# core/loaders/section.loader.ts

> 20 lines of code and 5 definitions.

Tree: Build tree
Language: typescript
Layer: infrastructure
Canonical: https://banes-lab.com/anatomy/build#file-build-core-loaders-section-loader-ts
Source text: https://banes-lab.com/assets/sources/source.1c46a0a478f7227ee429940d3556607bd08a05520bb9ba6b693da3005674763d.generated.txt

## Definitions

- `PAGE_IDS_MODULE` (lexical_declaration, line 5)
- `sitePages` (lexical_declaration, line 7, exported)
- `ids` (lexical_declaration, line 8, exported)
- `readSections` (lexical_declaration, line 14, exported)
- `found` (lexical_declaration, line 18, exported)

## Source

```typescript
import type { PageSection } from "#types/writing.types";
import { readPageContent } from "#core/loaders/payload.loader";
import { sectionsOf } from "#core/converters/section.converter";

const PAGE_IDS_MODULE = "@banes-lab/web/core/ids/page.ids.ts";

export const sitePages = async function sitePages(): Promise<readonly string[]> {
    const ids: unknown = await import(PAGE_IDS_MODULE);
    return typeof ids === "object" && ids !== null
        ? Object.values(ids).filter((id: unknown): id is string => typeof id === "string")
        : [];
};

export const readSections = function readSections(pages: readonly string[]): {
    readonly missing: readonly string[];
    readonly sections: readonly PageSection[];
} {
    const found = pages.map((page) => ({ content: readPageContent(page), page }));
    return {
        missing: found.filter((entry) => entry.content === null).map((entry) => entry.page),
        sections: found.flatMap((entry) => (entry.content === null ? [] : sectionsOf(entry.page, entry.content))),
    };
};
```
