# jg-site-checks

> Verify built static sites from an explicit page inventory, with exact canonical URLs, links, fragments, sitemaps, robots.txt, and llms.txt.

- **Version:** `1.0.0`
- **Runtimes:** Node.js
- **Install:** `npm install jg-site-checks`
- **On npm:** [jg-site-checks](https://www.npmjs.com/package/jg-site-checks)
- **Source:** [packages/jg-site-checks](https://github.com/jesusgraterol/jg-packages/tree/main/packages/jg-site-checks)
- **Recipes:** [jg-site-checks recipes](https://jg-packages.jesusgraterol.dev/packages/jg-site-checks/recipes/index.md)

## Usage

Pass `verifyStaticSite` the artifact directory, production origin and expected public page paths. Each page declares its exact canonical URL or `null`, and whether it should be indexed. The checker verifies those expectations, same-origin HTML links and fragments, and the supplied discovery files.

A sitemap can be a URL set or an index of local URL sets. Its URLs must match the indexable canonical inventory exactly. Parsed entries include the sitemap's `lastmod` text when present so a caller can check its own dates. Optional robots verification requires the configured sitemap reference. Optional `llms.txt` verification checks local Markdown link targets. Site-specific crawl policy, page content and search index checks belong in the caller.

A path with a trailing slash resolves to its `index.html`. Other paths resolve to an existing file, then a directory index or a matching `.html` file. HTML links with a different origin are ignored. Links, robots references and sitemap locations are never fetched. Build the artifact before verifying it and keep it unchanged until the check finishes. The default limits are 16,384 file and directory entries, 8 MiB per text file and 128 MiB of text per build.

## Errors

| Code                         | Message                                          |
| ---------------------------- | ------------------------------------------------ |
| `INVALID_SITE_BUILD_OPTIONS` | The site build verification options are invalid. |
| `SITE_BUILD_INVALID`         | The static site build failed verification.       |

## <a id="api-reference"></a>jg-site-checks API reference

Every export of `jg-site-checks@1.0.0`, 9 in all, with its signature, its errors, and an example. It's generated from the package's TSDoc.

- Functions: [`verifyStaticSite`](#api-verifyStaticSite)
- Constants: [`ERRORS`](#api-ERRORS)
- Types: [`ICheckedSitePage`](#api-ICheckedSitePage), [`ISiteSitemapEntry`](#api-ISiteSitemapEntry), [`IStaticSiteDiscovery`](#api-IStaticSiteDiscovery), [`IStaticSiteLimits`](#api-IStaticSiteLimits), [`IStaticSitePage`](#api-IStaticSitePage), [`IStaticSiteVerification`](#api-IStaticSiteVerification), [`IVerifyStaticSiteOptions`](#api-IVerifyStaticSiteOptions)

### <a id="api-functions"></a>Functions

#### <a id="api-verifyStaticSite"></a>`verifyStaticSite`

*Function*

Verifies a static build against an explicit site inventory. Reads only contained local artifact files, indexing each inspected HTML file once. Checks canonical metadata, robots indexability, links and fragments, and the discovery files the caller supplies.

```ts
verifyStaticSite(
  options: IVerifyStaticSiteOptions,
): Promise<IStaticSiteVerification>
```

**Parameters**

- `options` `IVerifyStaticSiteOptions`: The local artifact, production origin, page inventory and optional read limits.

**Returns** `Promise<IStaticSiteVerification>`: Verified pages and optional sitemap entries in document order.

**Throws**

- `INVALID_SITE_BUILD_OPTIONS`: The site build verification options are invalid.
- `SITE_BUILD_INVALID`: The static site build failed verification.

**Example**

```ts
import { verifyStaticSite } from 'jg-site-checks';

await verifyStaticSite({
  artifactRoot: 'dist',
  origin: 'https://example.com',
  pages: [{ path: '/', canonicalUrl: 'https://example.com/', indexable: true }],
  discovery: { sitemap: '/sitemap.xml', robots: '/robots.txt' },
});
```

### <a id="api-constants"></a>Constants

#### <a id="api-ERRORS"></a>`ERRORS`

*Constant*

stable public error codes

```ts
const ERRORS: { INVALID_SITE_BUILD_OPTIONS: "INVALID_SITE_BUILD_OPTIONS"; SITE_BUILD_INVALID: "SITE_BUILD_INVALID" }
```

### <a id="api-types"></a>Types

#### <a id="api-ICheckedSitePage"></a>`ICheckedSitePage`

*Type*

the verified inventory page and the relative build file that serves it

```ts
type ICheckedSitePage = IStaticSitePage & {
    file: string;
};
```

#### <a id="api-ISiteSitemapEntry"></a>`ISiteSitemapEntry`

*Type*

the exact sitemap location and optional published modification date

```ts
type ISiteSitemapEntry = {
    url: string;
    lastmod?: string;
};
```

**Members**

- `url: string` (property)
- `lastmod: string` (property)

#### <a id="api-IStaticSiteDiscovery"></a>`IStaticSiteDiscovery`

*Type*

discovery paths are same-origin site paths such as /sitemap-index.xml

```ts
type IStaticSiteDiscovery = {
    sitemap?: string;
    robots?: string;
    llms?: string;
};
```

**Members**

- `sitemap: string` (property)
- `robots: string` (property)
- `llms: string` (property)

#### <a id="api-IStaticSiteLimits"></a>`IStaticSiteLimits`

*Type*

traversal and cumulative UTF-8 file read limits for one artifact

```ts
type IStaticSiteLimits = {
    entries: number;
    textBytes: number;
    totalTextBytes: number;
};
```

**Members**

- `entries: number` (property)
- `textBytes: number` (property)
- `totalTextBytes: number` (property)

#### <a id="api-IStaticSitePage"></a>`IStaticSitePage`

*Type*

the canonical URL and indexing policy expected for a single served page

```ts
type IStaticSitePage = {
    path: string;
    canonicalUrl: string | null;
    indexable: boolean;
};
```

**Members**

- `path: string` (property)
- `canonicalUrl: string | null` (property)
- `indexable: boolean` (property)

#### <a id="api-IStaticSiteVerification"></a>`IStaticSiteVerification`

*Type*

verified pages in input order and, when enabled, sitemap entries in document order

```ts
type IStaticSiteVerification = {
    pages: ICheckedSitePage[];
    sitemapEntries?: ISiteSitemapEntry[];
};
```

**Members**

- `pages: ICheckedSitePage[]` (property)
- `sitemapEntries: ISiteSitemapEntry[]` (property)

#### <a id="api-IVerifyStaticSiteOptions"></a>`IVerifyStaticSiteOptions`

*Type*

caller-owned site expectations and the local artifact containing its built files

```ts
type IVerifyStaticSiteOptions = {
    artifactRoot: string;
    origin: string;
    pages: IStaticSitePage[];
    discovery?: IStaticSiteDiscovery;
    limits?: Partial<IStaticSiteLimits>;
};
```

**Members**

- `artifactRoot: string` (property)
- `origin: string` (property)
- `pages: IStaticSitePage[]` (property)
- `discovery: IStaticSiteDiscovery` (property)
- `limits: Partial<IStaticSiteLimits>` (property)
