{"version":3,"file":"index.mjs","names":[],"sources":["../src/config.ts","../src/collections.ts","../src/toc.ts"],"sourcesContent":["/**\n * Configuration helpers.\n *\n * defineConfig() and defineCollection() are type-safe identity functions\n * that provide TypeScript inference for collection schemas.\n */\n\nimport type { z } from \"zod\";\nimport type { CollectionComputed, CollectionDef, CollectionMap } from \"./schemas/collection\";\nimport type { Loader, LoaderType } from \"./loaders/types\";\nimport type { ContentLayerConfig } from \"./schemas/content-config\";\n\n/** Define a content layer configuration with type inference. */\nexport function defineConfig(config: ContentLayerConfig): ContentLayerConfig {\n  return config;\n}\n\n/** Define a collection with Zod schema type inference. */\nexport function defineCollection<\n  const S extends z.ZodType,\n  const TComputed extends CollectionComputed = {},\n  const TLoader extends LoaderType | Loader = LoaderType | Loader,\n>(\n  def: Omit<CollectionDef<S, TComputed, TLoader>, \"computed\"> & {\n    computed?: TComputed & CollectionComputed;\n  },\n): CollectionDef<S, TComputed, TLoader> {\n  return def;\n}\n\n/** Define a named collection map with strong literal inference. */\nexport function defineCollections<const TCollections extends CollectionMap>(\n  collections: TCollections,\n): TCollections {\n  return collections;\n}\n","/**\n * Convenience collection factories.\n *\n * These wrap `defineCollection` with sensible defaults for common content\n * patterns. Use them for projects that follow the default conventions; drop\n * down to `defineCollection` directly when you need full control.\n */\n\nimport type { z } from \"zod\";\n\nimport { defineCollection } from \"./config\";\nimport {\n  BaseFrontmatterSchema,\n  BlogFrontmatterSchema,\n  ProjectFrontmatterSchema,\n} from \"./schemas/frontmatter\";\nimport type { CollectionComputed, CollectionDef } from \"./schemas/collection\";\n\ntype FactoryOptions<S extends z.ZodType, TComputed extends CollectionComputed = {}> = {\n  /** Override the default content directory. */\n  directory?: string;\n  /**\n   * Override the default frontmatter schema. Use `BlogFrontmatterSchema.extend({...})`\n   * (or the relevant base) when adding project-specific fields.\n   */\n  schema?: S;\n  /** Extra include globs beyond the default `**\\/*.md`. */\n  include?: string[];\n  /** Extra exclude globs. */\n  exclude?: string[];\n  /** Computed fields derived from each entry. */\n  computed?: TComputed & CollectionComputed;\n};\n\ntype FactoryResult<S extends z.ZodType, TComputed extends CollectionComputed> = CollectionDef<\n  S,\n  TComputed,\n  \"markdown\"\n>;\n\n/** A markdown collection that uses `BlogFrontmatterSchema` by default. */\nexport function blogCollection<\n  S extends z.ZodType = typeof BlogFrontmatterSchema,\n  TComputed extends CollectionComputed = {},\n>(options: FactoryOptions<S, TComputed> = {}): FactoryResult<S, TComputed> {\n  const { directory = \"content/posts\", schema, include, exclude, computed } = options;\n  return defineCollection({\n    loader: \"markdown\",\n    directory,\n    schema: (schema ?? BlogFrontmatterSchema) as S,\n    ...(include ? { include } : {}),\n    ...(exclude ? { exclude } : {}),\n    ...(computed ? { computed } : {}),\n  }) as FactoryResult<S, TComputed>;\n}\n\n/** A markdown collection that uses `ProjectFrontmatterSchema` by default. */\nexport function projectsCollection<\n  S extends z.ZodType = typeof ProjectFrontmatterSchema,\n  TComputed extends CollectionComputed = {},\n>(options: FactoryOptions<S, TComputed> = {}): FactoryResult<S, TComputed> {\n  const { directory = \"content/projects\", schema, include, exclude, computed } = options;\n  return defineCollection({\n    loader: \"markdown\",\n    directory,\n    schema: (schema ?? ProjectFrontmatterSchema) as S,\n    ...(include ? { include } : {}),\n    ...(exclude ? { exclude } : {}),\n    ...(computed ? { computed } : {}),\n  }) as FactoryResult<S, TComputed>;\n}\n\n/**\n * A markdown collection that uses `BaseFrontmatterSchema` — suitable for\n * docs-style content where every entry has at least title/description.\n */\nexport function docsCollection<\n  S extends z.ZodType = typeof BaseFrontmatterSchema,\n  TComputed extends CollectionComputed = {},\n>(options: FactoryOptions<S, TComputed> = {}): FactoryResult<S, TComputed> {\n  const { directory = \"content/docs\", schema, include, exclude, computed } = options;\n  return defineCollection({\n    loader: \"markdown\",\n    directory,\n    schema: (schema ?? BaseFrontmatterSchema) as S,\n    ...(include ? { include } : {}),\n    ...(exclude ? { exclude } : {}),\n    ...(computed ? { computed } : {}),\n  }) as FactoryResult<S, TComputed>;\n}\n","import type { Heading } from \"./schemas/heading\";\n\n/**\n * Extract table of contents headings from an HTML string.\n *\n * Regex-based: finds <h[1-6] id=\"...\">text</h[1-6]>, strips inner HTML tags.\n * No dependency on unified — works on any HTML string.\n */\nexport function extractToc(html: string): Heading[] {\n  const headings: Heading[] = [];\n  const re = /<h([1-6])\\s+id=\"([^\"]*)\"[^>]*>([\\s\\S]*?)<\\/h\\1>/gi;\n  let match: RegExpExecArray | null;\n\n  while ((match = re.exec(html)) !== null) {\n    const depth = parseInt(match[1], 10);\n    const slug = match[2];\n    // Strip inner HTML tags to get plain text\n    const text = match[3].replace(/<[^>]+>/g, \"\").trim();\n    headings.push({ depth, text, slug });\n  }\n\n  return headings;\n}\n"],"mappings":";;;;;;;;;;AAaA,SAAgB,aAAa,QAAgD;CAC3E,OAAO;AACT;;AAGA,SAAgB,iBAKd,KAGsC;CACtC,OAAO;AACT;;AAGA,SAAgB,kBACd,aACc;CACd,OAAO;AACT;;;;ACMA,SAAgB,eAGd,UAAwC,CAAC,GAAgC;CACzE,MAAM,EAAE,YAAY,iBAAiB,QAAQ,SAAS,SAAS,aAAa;CAC5E,OAAO,iBAAiB;EACtB,QAAQ;EACR;EACA,QAAS,UAAU;EACnB,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAC7B,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAC7B,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;CACjC,CAAC;AACH;;AAGA,SAAgB,mBAGd,UAAwC,CAAC,GAAgC;CACzE,MAAM,EAAE,YAAY,oBAAoB,QAAQ,SAAS,SAAS,aAAa;CAC/E,OAAO,iBAAiB;EACtB,QAAQ;EACR;EACA,QAAS,UAAU;EACnB,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAC7B,GAAI,UAAU,EAAE,QAAQ,IAAI,CAAC;EAC7B,GAAI,WAAW,EAAE,SAAS,IAAI,CAAC;CACjC,CAAC;AACH;;;;;AAMA,SAAgB,eAGd,UA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