styledsea

Manifest

Generate manifest for production builds

Usage

Enable it from global config.

import { defineConfig } from 'styledsea-docs-mdx/config';
 
export default defineConfig({
  generateManifest: true,
});

During a production build (next build), Adalt MDX will output a manifest file in .source/manifest.json. You can use it to set up search indexes, like configuring Algolia Search.

What is It?

The manifest file contains the compiled info of collection entries. This includes their frontmatter, structuredData and toc (Table of Contents).

You can check the type definitions to see all available properties.

import type { Manifest } from 'styledsea-docs-mdx';

Read Manifest

You can read the file after the build is finished.

import type { Manifest } from 'styledsea-docs-mdx';
import { readFileSync } from 'node:fs';
 
const manifest = JSON.parse(
  readFileSync('.source/manifest.json').toString(),
) as Manifest;

Example

To integrate with Algolia Search:

update-indexes.ts
import algosearch from 'algoliasearch';
import { sync } from 'styledsea-docs-core/search-algolia/server';
import type { Manifest } from 'styledsea-docs-mdx';
import {
  createGetUrl,
  getSlugs,
  parseFilePath,
} from 'styledsea-docs-core/source';
import path from 'node:path';
 
const getUrl = createGetUrl('/docs'); // we need to estimate the URL of pages
 
export async function updateSearchIndexes(manifest: Manifest): Promise<void> {
  const client = algosearch(
    process.env.NEXT_PUBLIC_ALGOLIA_APP_ID,
    process.env.ALGOLIA_API_KEY,
  );
 
  await sync(client, {
    document: process.env.NEXT_PUBLIC_ALGOLIA_INDEX ?? 'document',
    documents: manifest.files
      .filter((file) => file.collection === 'docs') // the collection name
      .map((docs) => {
        const url = getUrl(
          getSlugs(parseFilePath(path.relative('content/docs', docs.path))),
        );
 
        if (!docs.data.structuredData)
          throw new Error('`structuredData` is required');
 
        return {
          _id: docs.path,
          title: docs.data.frontmatter.title as string,
          description: docs.data.frontmatter.description as string,
          url,
          structured: docs.data.structuredData,
        };
      }),
  });
}

frontmatter is untyped. With type check enabled, you need to cast them to the correct type.

Last updated on

On this page

Edit on GitHub