Skip to content

[P5] Add typed transformer lifecycle hooks #46

@KayleeWilliams

Description

@KayleeWilliams

Problem

Leadtype has a strong internal pipeline, but users who need custom behavior currently have to work around it or fork pieces. We need extension points that preserve the pipeline's stability.

Proposal

Add typed transformer lifecycle hooks around parsing, markdown flattening, search indexing, and LLM artifact generation.

Example:

export default defineDocsConfig({
  transformers: [
    {
      name: "api-area-metadata",
      afterFrontmatter(page) {
        return {
          ...page,
          frontmatter: {
            ...page.frontmatter,
            apiArea: inferApiArea(page.filePath),
          },
        };
      },
      beforeSearchChunk(chunk) {
        return boostApiSymbols(chunk);
      },
    },
  ],
});

Potential hooks:

  • beforeParse
  • afterFrontmatter
  • afterMdxAst
  • afterFlattenMarkdown
  • beforeSearchIndex
  • beforeLlmsTxt
  • beforeAgentsMd

Core Behavior

  • Hooks operate on Leadtype pipeline objects, not framework request/response objects.
  • Hooks run in deterministic order.
  • Hook errors include transformer name and source path.
  • Existing remark plugin behavior remains compatible.

Framework Integration Notes

Docs should show framework-specific consumption patterns:

  • SvelteKit: derive route/layout metadata for load.
  • Nuxt: enrich pages for navigation/sidebar fields.
  • Astro: align generated metadata with Content Collections conventions.
  • Next/Fumadocs: derive sidebar/search metadata.

Acceptance Criteria

  • Hooks are typed and documented.
  • Hooks can customize frontmatter-derived metadata.
  • Hooks can customize search chunks without replacing the search generator.
  • Hooks can customize LLM artifacts without replacing the full generator.
  • Hook failures include transformer name and file path.
  • Pipeline output remains deterministic.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions