@ng-native/analog 0.6.0 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/content.js CHANGED
@@ -88,7 +88,8 @@ function listed(found) {
88
88
  /**
89
89
  * Where `injectContent` finds each file, as Analog finds it: by its slug, in its own folder, so a
90
90
  * front matter `slug` renames the file. A slug with a `/` in it is from the folder under
91
- * `src/content` it is in, or from `src/content` itself.
91
+ * `src/content` it is in, or from `src/content` itself. A slug is there both as written and
92
+ * encoded, as the list gives it: Analog finds `caf%C3%A9` and the route parameter can be either.
92
93
  */
93
94
  function filesBySlug(files) {
94
95
  const bySlug = new Map();
@@ -97,7 +98,9 @@ function filesBySlug(files) {
97
98
  const folder = parts.slice(0, -1).join('/');
98
99
  const slug = rawSlugOf(found) || 'index';
99
100
  const root = parts.length > 4 ? parts.slice(0, 4).join('/') : '/src/content';
100
- bySlug.set(`${slug.includes('/') ? root : folder}/${slug}.md`.replace(/\/{2,}/g, '/'), found);
101
+ for (const name of new Set([slug, encodeURI(slug)])) {
102
+ bySlug.set(`${slug.includes('/') ? root : folder}/${name}.md`.replace(/\/{2,}/g, '/'), found);
103
+ }
101
104
  }
102
105
  return bySlug;
103
106
  }
@@ -1 +1 @@
1
- {"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,cAAc,EACd,QAAQ,EACR,MAAM,EACN,QAAQ,GAIT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAmB,MAAM,MAAM,CAAC;AA4EvD,MAAM,aAAa,GAAG,IAAI,cAAc,CAAoB,iC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AAC,QAAQ,CAAC,CAAC;IAC3C,OAAO,QAAQ,CAAC,EAAE,MAAM,EAAE,KAAK,IAAI,EAAE,CAAC,KAAK,EAAE,CAAC,CAAC;AACjD,CAAC;AAED;;;GAGG;AACH,MAAM,UAAU,mBAAmB,CACjC,MAAoD,EACpD,QAAQ,GAAG,gBAAgB;IAE3B,MAAM,KAAK,GAAG,WAAW,CAAC,uBAAuB,CAAC,CAAC;IACnD,MAAM,KAAK,GACT,MAAM;QACN,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE;YACtF,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;IACL,OAAO,QAAQ,CAAC;QACd,MAAM,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5C,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;YAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,OAAO,WAAW,CAAa,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;YAC9E,CAAC;YACD,OAAO,KAAK,CAAC,CAAC,CAAC,WAAW,CAAa,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC3F,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * `@analogjs/content`'s API on native, over the `.md` files in `src/content`: `injectContent`,\n * `injectContentFiles`, `contentFilesResource` and `contentFileResource`, with the names, the\n * arguments and the `ContentFile` shape Analog has, so a blog's pages read the same on both.\n *\n * Analog finds the files with Vite as it builds. On native the app finds them with a\n * `require.context` and hands it to `provideContentFiles`, and Metro has made each file\n * `{ attributes, content, tokens }` already: see `@ng-native/metro`'s `markdown-module.cjs`. So\n * there is no renderer to provide and no parser on the device: a page draws `tokens` with\n * `<markdown>` from `@ng-native/components/markdown`.\n */\nimport {\n InjectionToken,\n computed,\n inject,\n resource,\n type ResourceRef,\n type Signal,\n type Provider,\n} from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { ActivatedRoute } from '@angular/router';\nimport { markdownPageFile } from '@ng-native/router';\nimport { defer, map, of, type Observable } from 'rxjs';\n\n/**\n * A token `marked.lexer` made, as `<markdown [tokens]>` takes it. Typed here rather than imported\n * from `marked`, so an app's types never need it.\n */\nexport interface ContentToken {\n type: string;\n raw: string;\n [key: string]: any;\n}\n\n/** A heading of a content file, as Analog lists them. */\nexport interface TableOfContentItem {\n /** The heading's text made a slug, as Analog makes it: `Getting started` is `getting-started`. */\n id: string;\n /** 1 for `#`, up to 6. */\n level: number;\n /** The heading as written, without its `#`s. */\n text: string;\n}\n\n/** A content file, as `@analogjs/content` gives it, with the tokens it was lexed into. */\nexport interface ContentFile<Attributes extends Record<string, any> = Record<string, any>> {\n /** Its path from the project, `/src/content/post.md`; without `.md` from `injectContent`. */\n filename: string;\n /** Its front matter `slug`, or its file name without `.md`; `index.md` is `''`. */\n slug: string;\n /** The Markdown after the front matter; the fallback text for a file that is not there. */\n content?: string;\n /** The front matter. A date in it is its ISO string. */\n attributes: Attributes;\n /** `content` lexed by `marked`, for `<markdown [tokens]>`. Not set on the fallback. */\n tokens?: ContentToken[];\n /** The headings, from `injectContent` and `contentFileResource`. */\n toc?: TableOfContentItem[];\n}\n\n/** What a `.md` file is as a module, made by `@ng-native/metro` as the app is bundled. */\nexport interface MarkdownModule {\n readonly attributes: Readonly<Record<string, unknown>>;\n readonly content: string;\n readonly tokens: ContentToken[];\n}\n\n/**\n * What Metro's `require.context('../content', true, /\\.md$/)` returns: the files it found, each\n * keyed by its path from that directory (`./blog/post.md`), and a call that loads one.\n */\nexport interface ContentContext {\n keys(): string[];\n (key: string): unknown;\n}\n\n/**\n * The files of an eager `import.meta.glob`, such as\n * `import.meta.glob('/src/content/**\\/*.md', { eager: true })`, for a Vitest test.\n */\nexport type ContentModules = Readonly<Record<string, unknown>>;\n\nexport type InjectContentFilesFilterFunction<T extends Record<string, any>> = (\n value: ContentFile<T>,\n index: number,\n array: ContentFile<T>[],\n) => boolean;\n\n/** The parameter `injectContent` and `contentFileResource` find a file by. */\nexport type ContentParam =\n string | { param: string; subdirectory: string } | { customFilename: string };\n\n/** One file found, by its path from the project and the module Metro made of it. */\ninterface FoundFile {\n readonly filename: string;\n readonly module: MarkdownModule;\n}\n\nconst CONTENT_FILES = new InjectionToken<() => FoundFile[]>('@ng-native/analog content files');\n\n/** The content files, or an error saying how to provide them. */\nfunction injectFiles(caller: string): () => FoundFile[] {\n const files = inject(CONTENT_FILES, { optional: true });\n if (!files) {\n throw new Error(\n `${caller} reads the files provideContentFiles was given, and the app has none. Add ` +\n \"provideContentFiles(require.context('../content', true, /\\\\.md$/)) to its providers.\",\n );\n }\n return files;\n}\n\nconst DEFAULT_FALLBACK = 'No Content Found';\n\n/**\n * The content files `injectContent` and `injectContentFiles` read, from a `require.context` of\n * `src/content` in an app:\n *\n * ```ts\n * provideContentFiles(require.context('../content', true, /\\.md$/))\n * ```\n *\n * or from an eager `import.meta.glob` of the same files in a Vitest test. The context is read each\n * time a file or the list is asked for, so a file Metro adds or removes is in the next one.\n */\nexport function provideContentFiles(content: ContentContext | ContentModules): Provider[] {\n return [{ provide: CONTENT_FILES, useValue: () => foundFiles(content) }];\n}\n\nfunction foundFiles(content: ContentContext | ContentModules): FoundFile[] {\n const entries: [string, () => unknown][] =\n typeof content === 'function'\n ? content\n .keys()\n .map((key) => [`/src/content/${key.replace(/^\\.\\//, '')}`, () => content(key)])\n : Object.keys(content).map((key) => [contentPath(key), () => content[key]]);\n return entries\n .filter(([filename]) => filename.endsWith('.md'))\n .map(([filename, load]) => ({ filename, module: markdownModuleOf(load(), filename) }));\n}\n\n/** A glob's key as Analog names a content file, from `/src/content`. */\nfunction contentPath(key: string): string {\n const named = key.replace(/^(?:.*?)\\/content(?=\\/)/, '/src/content');\n return (\n named.startsWith('/src/content/') ? named : `/src/content/${key.replace(/^\\.?\\//, '')}`\n ).replace(/\\/{2,}/g, '/');\n}\n\n/**\n * The `{ attributes, content, tokens }` a loaded `.md` module holds, from its namespace or as it\n * is, checked as `fileRoutes` checks a Markdown page.\n */\nfunction markdownModuleOf(loaded: unknown, filename: string): MarkdownModule {\n if (loaded instanceof Promise || typeof (loaded as { then?: unknown })?.then === 'function') {\n throw new Error(\n `${filename} loaded as a promise. provideContentFiles reads every file as the list is ` +\n \"asked for: make its require.context without 'lazy', and an import.meta.glob with \" +\n '{ eager: true }.',\n );\n }\n const { attributes, content, tokens } = markdownPageFile(filename, loaded);\n return { attributes, content, tokens };\n}\n\n/** A file's slug from its name, as Analog takes it: `post.md` is `post`, `index.md` is `''`. */\nfunction slugOf(filename: string): string {\n const base = (filename.split(/[/\\\\]/).pop() ?? '').trim().replace(/\\.[^./\\\\]+$/, '');\n return base === 'index' ? '' : base;\n}\n\n/** A file's front matter `slug`, or its name's, as written. */\nfunction rawSlugOf(found: FoundFile): string {\n const slug = (found.module.attributes as Record<string, unknown>)['slug'];\n return typeof slug === 'string' && slug ? slug : slugOf(found.filename);\n}\n\n/** A file in the list: its slug encoded for a URL, as Analog lists it. */\nfunction listed<Attributes extends Record<string, any>>(found: FoundFile): ContentFile<Attributes> {\n return {\n filename: found.filename,\n attributes: found.module.attributes as Attributes,\n slug: encodeURI(rawSlugOf(found)),\n };\n}\n\n/**\n * Where `injectContent` finds each file, as Analog finds it: by its slug, in its own folder, so a\n * front matter `slug` renames the file. A slug with a `/` in it is from the folder under\n * `src/content` it is in, or from `src/content` itself.\n */\nfunction filesBySlug(files: readonly FoundFile[]): Map<string, FoundFile> {\n const bySlug = new Map<string, FoundFile>();\n for (const found of files) {\n const parts = found.filename.split('/');\n const folder = parts.slice(0, -1).join('/');\n const slug = rawSlugOf(found) || 'index';\n const root = parts.length > 4 ? parts.slice(0, 4).join('/') : '/src/content';\n bySlug.set(`${slug.includes('/') ? root : folder}/${slug}.md`.replace(/\\/{2,}/g, '/'), found);\n }\n return bySlug;\n}\n\n/** The headings of `tokens`, with ids made as Analog makes them. */\nfunction tableOfContents(tokens: readonly ContentToken[]): TableOfContentItem[] {\n const counts = new Map<string, number>();\n const toc: TableOfContentItem[] = [];\n for (const token of tokens) {\n if (token.type !== 'heading') continue;\n const text = String(token['text'] ?? '').trim();\n if (!text) continue;\n const base = text\n .toLowerCase()\n .replace(/[^\\w\\s-]/g, '')\n .trim()\n .replace(/\\s+/g, '-');\n const count = counts.get(base) ?? 0;\n counts.set(base, count + 1);\n toc.push({ id: count === 0 ? base : `${base}-${count}`, level: Number(token['depth']), text });\n }\n return toc;\n}\n\n/**\n * The file at `/src/content/<prefix><slug>.md`, or `<slug>/index.md` under it, as `injectContent`\n * gives it; the fallback when there is none, as Analog gives it.\n */\nfunction contentFile<Attributes extends Record<string, any>>(\n files: readonly FoundFile[],\n prefix: string,\n slug: string,\n fallback: string,\n): ContentFile<Attributes | Record<string, never>> {\n const bySlug = filesBySlug(files);\n const base = `/src/content/${prefix}${slug}`.replace(/\\/{2,}/g, '/');\n const key = [`${base}.md`, `${base}/index.md`].find((candidate) => bySlug.has(candidate));\n const found = key === undefined ? undefined : bySlug.get(key);\n if (!key || !found) {\n return { filename: base, attributes: {}, slug: '', content: fallback, toc: [] };\n }\n const { attributes, content, tokens } = found.module;\n return {\n filename: key.replace(/\\.md$/, ''),\n slug,\n attributes: attributes as Attributes,\n content,\n tokens,\n toc: tableOfContents(tokens),\n };\n}\n\nconst NO_SLUG = (fallback: string): ContentFile<Record<string, never>> => ({\n filename: '',\n slug: '',\n attributes: {},\n content: fallback,\n toc: [],\n});\n\n/**\n * One content file, by the route parameter that names it, as in Analog:\n *\n * - `injectContent()` reads the `slug` parameter: `/blog/:slug` finds `src/content/<slug>.md`.\n * - `injectContent('id')` reads the `id` parameter instead.\n * - `injectContent({ param: 'slug', subdirectory: 'blog' })` finds `src/content/blog/<slug>.md`.\n * - `injectContent({ customFilename: 'about' })` finds `src/content/about.md`, with no parameter.\n *\n * A file that is not there, or a parameter that is not set, gives `{ attributes: {}, content:\n * fallback }`, which a page can tell by its empty `slug`.\n */\nexport function injectContent<Attributes extends Record<string, any> = Record<string, any>>(\n param: ContentParam = 'slug',\n fallback = DEFAULT_FALLBACK,\n): Observable<ContentFile<Attributes | Record<string, never>>> {\n const files = injectFiles('injectContent()');\n if (typeof param !== 'string' && 'customFilename' in param) {\n return defer(() => of(contentFile<Attributes>(files(), '', param.customFilename, fallback)));\n }\n const prefix = typeof param === 'string' ? '' : `${param.subdirectory}/`;\n const key = typeof param === 'string' ? param : param.param;\n return inject(ActivatedRoute).paramMap.pipe(\n map((params) => params.get(key)),\n map((slug) =>\n slug ? contentFile<Attributes>(files(), prefix, slug, fallback) : NO_SLUG(fallback),\n ),\n );\n}\n\n/**\n * Every content file, without its content, as in Analog: `filename`, `slug` and `attributes`, in\n * the order the context lists them. `filterFn` keeps the ones it returns true for.\n */\nexport function injectContentFiles<Attributes extends Record<string, any>>(\n filterFn?: InjectContentFilesFilterFunction<Attributes>,\n): ContentFile<Attributes>[] {\n const files = injectFiles('injectContentFiles()')().map((found) => listed<Attributes>(found));\n return filterFn ? files.filter(filterFn) : files;\n}\n\n/** `injectContentFiles`, as a resource, as `@analogjs/content/resources` has it. */\nexport function contentFilesResource<Attributes extends Record<string, any>>(\n filterFn?: InjectContentFilesFilterFunction<Attributes>,\n): ResourceRef<ContentFile<Attributes>[] | undefined> {\n const files = injectContentFiles(filterFn);\n return resource({ loader: async () => files });\n}\n\n/**\n * One content file, as a resource, as `@analogjs/content/resources` has it: by `params`, a slug or\n * `{ customFilename }`, or by the route's `slug` parameter when there is none.\n */\nexport function contentFileResource<Attributes extends Record<string, any> = Record<string, any>>(\n params?: Signal<string | { customFilename: string }>,\n fallback = DEFAULT_FALLBACK,\n): ResourceRef<ContentFile<Attributes | Record<string, never>> | undefined> {\n const files = injectFiles('contentFileResource()');\n const input =\n params ??\n toSignal(inject(ActivatedRoute).paramMap.pipe(map((route) => route.get('slug') ?? '')), {\n requireSync: true,\n });\n return resource({\n params: computed(() => ({ input: input() })),\n loader: async ({ params: { input: param } }) => {\n if (typeof param !== 'string') {\n return contentFile<Attributes>(files(), '', param.customFilename, fallback);\n }\n return param ? contentFile<Attributes>(files(), '', param, fallback) : NO_SLUG(fallback);\n },\n });\n}\n"]}
1
+ {"version":3,"file":"content.js","sourceRoot":"","sources":["../src/content.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;GAUG;AACH,OAAO,EACL,cAAc,EACd,QAAQ,EACR,MAAM,EACN,QAAQ,GAIT,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,QAAQ,EAAE,MAAM,4BAA4B,CAAC;AACtD,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACjD,OAAO,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AACrD,OAAO,EAAE,KAAK,EAAE,GAAG,EAAE,EAAE,EAAmB,MAAM,MAAM,CAAC;AA4EvD,MAAM,aAAa,GAAG,IAAI,cAAc,CAAoB,iCAAiC,CAAC,CAAC;AAE/F,iEAAiE;AACjE,SAAS,WAAW,CAAC,MAAc;IACjC,MAAM,KAAK,GAAG,MAAM,CAAC,aAAa,EAAE,EAAE,QAAQ,EAAE,IAAI,EAAE,CAAC,CAAC;IACxD,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,KAAK,CACb,GAAG,MAAM,4EAA4E;YACnF,sFAAsF,CACzF,CAAC;IACJ,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,MAAM,gBAAgB,GAAG,kBAAkB,CAAC;AAE5C;;;;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AW,CAAC,uBAAuB,CAAC,CAAC;IACnD,MAAM,KAAK,GACT,MAAM;QACN,QAAQ,CAAC,MAAM,CAAC,cAAc,CAAC,CAAC,QAAQ,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,EAAE,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC,CAAC,EAAE;YACtF,WAAW,EAAE,IAAI;SAClB,CAAC,CAAC;IACL,OAAO,QAAQ,CAAC;QACd,MAAM,EAAE,QAAQ,CAAC,GAAG,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,CAAC,CAAC;QAC5C,MAAM,EAAE,KAAK,EAAE,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,EAAE,EAAE;YAC7C,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;gBAC9B,OAAO,WAAW,CAAa,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,CAAC,cAAc,EAAE,QAAQ,CAAC,CAAC;YAC9E,CAAC;YACD,OAAO,KAAK,CAAC,CAAC,CAAC,WAAW,CAAa,KAAK,EAAE,EAAE,EAAE,EAAE,KAAK,EAAE,QAAQ,CAAC,CAAC,CAAC,CAAC,OAAO,CAAC,QAAQ,CAAC,CAAC;QAC3F,CAAC;KACF,CAAC,CAAC;AACL,CAAC","sourcesContent":["/**\n * `@analogjs/content`'s API on native, over the `.md` files in `src/content`: `injectContent`,\n * `injectContentFiles`, `contentFilesResource` and `contentFileResource`, with the names, the\n * arguments and the `ContentFile` shape Analog has, so a blog's pages read the same on both.\n *\n * Analog finds the files with Vite as it builds. On native the app finds them with a\n * `require.context` and hands it to `provideContentFiles`, and Metro has made each file\n * `{ attributes, content, tokens }` already: see `@ng-native/metro`'s `markdown-module.cjs`. So\n * there is no renderer to provide and no parser on the device: a page draws `tokens` with\n * `<markdown>` from `@ng-native/components/markdown`.\n */\nimport {\n InjectionToken,\n computed,\n inject,\n resource,\n type ResourceRef,\n type Signal,\n type Provider,\n} from '@angular/core';\nimport { toSignal } from '@angular/core/rxjs-interop';\nimport { ActivatedRoute } from '@angular/router';\nimport { markdownPageFile } from '@ng-native/router';\nimport { defer, map, of, type Observable } from 'rxjs';\n\n/**\n * A token `marked.lexer` made, as `<markdown [tokens]>` takes it. Typed here rather than imported\n * from `marked`, so an app's types never need it.\n */\nexport interface ContentToken {\n type: string;\n raw: string;\n [key: string]: any;\n}\n\n/** A heading of a content file, as Analog lists them. */\nexport interface TableOfContentItem {\n /** The heading's text made a slug, as Analog makes it: `Getting started` is `getting-started`. */\n id: string;\n /** 1 for `#`, up to 6. */\n level: number;\n /** The heading as written, without its `#`s. */\n text: string;\n}\n\n/** A content file, as `@analogjs/content` gives it, with the tokens it was lexed into. */\nexport interface ContentFile<Attributes extends Record<string, any> = Record<string, any>> {\n /** Its path from the project, `/src/content/post.md`; without `.md` from `injectContent`. */\n filename: string;\n /** Its front matter `slug`, or its file name without `.md`; `index.md` is `''`. */\n slug: string;\n /** The Markdown after the front matter; the fallback text for a file that is not there. */\n content?: string;\n /** The front matter. A date in it is its ISO string. */\n attributes: Attributes;\n /** `content` lexed by `marked`, for `<markdown [tokens]>`. Not set on the fallback. */\n tokens?: ContentToken[];\n /** The headings, from `injectContent` and `contentFileResource`. */\n toc?: TableOfContentItem[];\n}\n\n/** What a `.md` file is as a module, made by `@ng-native/metro` as the app is bundled. */\nexport interface MarkdownModule {\n readonly attributes: Readonly<Record<string, unknown>>;\n readonly content: string;\n readonly tokens: ContentToken[];\n}\n\n/**\n * What Metro's `require.context('../content', true, /\\.md$/)` returns: the files it found, each\n * keyed by its path from that directory (`./blog/post.md`), and a call that loads one.\n */\nexport interface ContentContext {\n keys(): string[];\n (key: string): unknown;\n}\n\n/**\n * The files of an eager `import.meta.glob`, such as\n * `import.meta.glob('/src/content/**\\/*.md', { eager: true })`, for a Vitest test.\n */\nexport type ContentModules = Readonly<Record<string, unknown>>;\n\nexport type InjectContentFilesFilterFunction<T extends Record<string, any>> = (\n value: ContentFile<T>,\n index: number,\n array: ContentFile<T>[],\n) => boolean;\n\n/** The parameter `injectContent` and `contentFileResource` find a file by. */\nexport type ContentParam =\n string | { param: string; subdirectory: string } | { customFilename: string };\n\n/** One file found, by its path from the project and the module Metro made of it. */\ninterface FoundFile {\n readonly filename: string;\n readonly module: MarkdownModule;\n}\n\nconst CONTENT_FILES = new InjectionToken<() => FoundFile[]>('@ng-native/analog content files');\n\n/** The content files, or an error saying how to provide them. */\nfunction injectFiles(caller: string): () => FoundFile[] {\n const files = inject(CONTENT_FILES, { optional: true });\n if (!files) {\n throw new Error(\n `${caller} reads the files provideContentFiles was given, and the app has none. Add ` +\n \"provideContentFiles(require.context('../content', true, /\\\\.md$/)) to its providers.\",\n );\n }\n return files;\n}\n\nconst DEFAULT_FALLBACK = 'No Content Found';\n\n/**\n * The content files `injectContent` and `injectContentFiles` read, from a `require.context` of\n * `src/content` in an app:\n *\n * ```ts\n * provideContentFiles(require.context('../content', true, /\\.md$/))\n * ```\n *\n * or from an eager `import.meta.glob` of the same files in a Vitest test. The context is read each\n * time a file or the list is asked for, so a file Metro adds or removes is in the next one.\n */\nexport function provideContentFiles(content: ContentContext | ContentModules): Provider[] {\n return [{ provide: CONTENT_FILES, useValue: () => foundFiles(content) }];\n}\n\nfunction foundFiles(content: ContentContext | ContentModules): FoundFile[] {\n const entries: [string, () => unknown][] =\n typeof content === 'function'\n ? content\n .keys()\n .map((key) => [`/src/content/${key.replace(/^\\.\\//, '')}`, () => content(key)])\n : Object.keys(content).map((key) => [contentPath(key), () => content[key]]);\n return entries\n .filter(([filename]) => filename.endsWith('.md'))\n .map(([filename, load]) => ({ filename, module: markdownModuleOf(load(), filename) }));\n}\n\n/** A glob's key as Analog names a content file, from `/src/content`. */\nfunction contentPath(key: string): string {\n const named = key.replace(/^(?:.*?)\\/content(?=\\/)/, '/src/content');\n return (\n named.startsWith('/src/content/') ? named : `/src/content/${key.replace(/^\\.?\\//, '')}`\n ).replace(/\\/{2,}/g, '/');\n}\n\n/**\n * The `{ attributes, content, tokens }` a loaded `.md` module holds, from its namespace or as it\n * is, checked as `fileRoutes` checks a Markdown page.\n */\nfunction markdownModuleOf(loaded: unknown, filename: string): MarkdownModule {\n if (loaded instanceof Promise || typeof (loaded as { then?: unknown })?.then === 'function') {\n throw new Error(\n `${filename} loaded as a promise. provideContentFiles reads every file as the list is ` +\n \"asked for: make its require.context without 'lazy', and an import.meta.glob with \" +\n '{ eager: true }.',\n );\n }\n const { attributes, content, tokens } = markdownPageFile(filename, loaded);\n return { attributes, content, tokens };\n}\n\n/** A file's slug from its name, as Analog takes it: `post.md` is `post`, `index.md` is `''`. */\nfunction slugOf(filename: string): string {\n const base = (filename.split(/[/\\\\]/).pop() ?? '').trim().replace(/\\.[^./\\\\]+$/, '');\n return base === 'index' ? '' : base;\n}\n\n/** A file's front matter `slug`, or its name's, as written. */\nfunction rawSlugOf(found: FoundFile): string {\n const slug = (found.module.attributes as Record<string, unknown>)['slug'];\n return typeof slug === 'string' && slug ? slug : slugOf(found.filename);\n}\n\n/** A file in the list: its slug encoded for a URL, as Analog lists it. */\nfunction listed<Attributes extends Record<string, any>>(found: FoundFile): ContentFile<Attributes> {\n return {\n filename: found.filename,\n attributes: found.module.attributes as Attributes,\n slug: encodeURI(rawSlugOf(found)),\n };\n}\n\n/**\n * Where `injectContent` finds each file, as Analog finds it: by its slug, in its own folder, so a\n * front matter `slug` renames the file. A slug with a `/` in it is from the folder under\n * `src/content` it is in, or from `src/content` itself. A slug is there both as written and\n * encoded, as the list gives it: Analog finds `caf%C3%A9` and the route parameter can be either.\n */\nfunction filesBySlug(files: readonly FoundFile[]): Map<string, FoundFile> {\n const bySlug = new Map<string, FoundFile>();\n for (const found of files) {\n const parts = found.filename.split('/');\n const folder = parts.slice(0, -1).join('/');\n const slug = rawSlugOf(found) || 'index';\n const root = parts.length > 4 ? parts.slice(0, 4).join('/') : '/src/content';\n for (const name of new Set([slug, encodeURI(slug)])) {\n bySlug.set(`${slug.includes('/') ? root : folder}/${name}.md`.replace(/\\/{2,}/g, '/'), found);\n }\n }\n return bySlug;\n}\n\n/** The headings of `tokens`, with ids made as Analog makes them. */\nfunction tableOfContents(tokens: readonly ContentToken[]): TableOfContentItem[] {\n const counts = new Map<string, number>();\n const toc: TableOfContentItem[] = [];\n for (const token of tokens) {\n if (token.type !== 'heading') continue;\n const text = String(token['text'] ?? '').trim();\n if (!text) continue;\n const base = text\n .toLowerCase()\n .replace(/[^\\w\\s-]/g, '')\n .trim()\n .replace(/\\s+/g, '-');\n const count = counts.get(base) ?? 0;\n counts.set(base, count + 1);\n toc.push({ id: count === 0 ? base : `${base}-${count}`, level: Number(token['depth']), text });\n }\n return toc;\n}\n\n/**\n * The file at `/src/content/<prefix><slug>.md`, or `<slug>/index.md` under it, as `injectContent`\n * gives it; the fallback when there is none, as Analog gives it.\n */\nfunction contentFile<Attributes extends Record<string, any>>(\n files: readonly FoundFile[],\n prefix: string,\n slug: string,\n fallback: string,\n): ContentFile<Attributes | Record<string, never>> {\n const bySlug = filesBySlug(files);\n const base = `/src/content/${prefix}${slug}`.replace(/\\/{2,}/g, '/');\n const key = [`${base}.md`, `${base}/index.md`].find((candidate) => bySlug.has(candidate));\n const found = key === undefined ? undefined : bySlug.get(key);\n if (!key || !found) {\n return { filename: base, attributes: {}, slug: '', content: fallback, toc: [] };\n }\n const { attributes, content, tokens } = found.module;\n return {\n filename: key.replace(/\\.md$/, ''),\n slug,\n attributes: attributes as Attributes,\n content,\n tokens,\n toc: tableOfContents(tokens),\n };\n}\n\nconst NO_SLUG = (fallback: string): ContentFile<Record<string, never>> => ({\n filename: '',\n slug: '',\n attributes: {},\n content: fallback,\n toc: [],\n});\n\n/**\n * One content file, by the route parameter that names it, as in Analog:\n *\n * - `injectContent()` reads the `slug` parameter: `/blog/:slug` finds `src/content/<slug>.md`.\n * - `injectContent('id')` reads the `id` parameter instead.\n * - `injectContent({ param: 'slug', subdirectory: 'blog' })` finds `src/content/blog/<slug>.md`.\n * - `injectContent({ customFilename: 'about' })` finds `src/content/about.md`, with no parameter.\n *\n * A file that is not there, or a parameter that is not set, gives `{ attributes: {}, content:\n * fallback }`, which a page can tell by its empty `slug`.\n */\nexport function injectContent<Attributes extends Record<string, any> = Record<string, any>>(\n param: ContentParam = 'slug',\n fallback = DEFAULT_FALLBACK,\n): Observable<ContentFile<Attributes | Record<string, never>>> {\n const files = injectFiles('injectContent()');\n if (typeof param !== 'string' && 'customFilename' in param) {\n return defer(() => of(contentFile<Attributes>(files(), '', param.customFilename, fallback)));\n }\n const prefix = typeof param === 'string' ? '' : `${param.subdirectory}/`;\n const key = typeof param === 'string' ? param : param.param;\n return inject(ActivatedRoute).paramMap.pipe(\n map((params) => params.get(key)),\n map((slug) =>\n slug ? contentFile<Attributes>(files(), prefix, slug, fallback) : NO_SLUG(fallback),\n ),\n );\n}\n\n/**\n * Every content file, without its content, as in Analog: `filename`, `slug` and `attributes`, in\n * the order the context lists them. `filterFn` keeps the ones it returns true for.\n */\nexport function injectContentFiles<Attributes extends Record<string, any>>(\n filterFn?: InjectContentFilesFilterFunction<Attributes>,\n): ContentFile<Attributes>[] {\n const files = injectFiles('injectContentFiles()')().map((found) => listed<Attributes>(found));\n return filterFn ? files.filter(filterFn) : files;\n}\n\n/** `injectContentFiles`, as a resource, as `@analogjs/content/resources` has it. */\nexport function contentFilesResource<Attributes extends Record<string, any>>(\n filterFn?: InjectContentFilesFilterFunction<Attributes>,\n): ResourceRef<ContentFile<Attributes>[] | undefined> {\n const files = injectContentFiles(filterFn);\n return resource({ loader: async () => files });\n}\n\n/**\n * One content file, as a resource, as `@analogjs/content/resources` has it: by `params`, a slug or\n * `{ customFilename }`, or by the route's `slug` parameter when there is none.\n */\nexport function contentFileResource<Attributes extends Record<string, any> = Record<string, any>>(\n params?: Signal<string | { customFilename: string }>,\n fallback = DEFAULT_FALLBACK,\n): ResourceRef<ContentFile<Attributes | Record<string, never>> | undefined> {\n const files = injectFiles('contentFileResource()');\n const input =\n params ??\n toSignal(inject(ActivatedRoute).paramMap.pipe(map((route) => route.get('slug') ?? '')), {\n requireSync: true,\n });\n return resource({\n params: computed(() => ({ input: input() })),\n loader: async ({ params: { input: param } }) => {\n if (typeof param !== 'string') {\n return contentFile<Attributes>(files(), '', param.customFilename, fallback);\n }\n return param ? contentFile<Attributes>(files(), '', param, fallback) : NO_SLUG(fallback);\n },\n });\n}\n"]}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ng-native/analog",
3
- "version": "0.6.0",
3
+ "version": "0.7.0",
4
4
  "description": "Analog's file-based pages and content files for Angular Native: src/app/pages, routed by @analogjs/router on a native stack, and src/content read as @analogjs/content reads it.",
5
5
  "keywords": [
6
6
  "angular",
@@ -34,7 +34,7 @@
34
34
  "@analogjs/router": "^2.8.0",
35
35
  "@angular/core": "^22.0.0",
36
36
  "@angular/router": "^22.0.0",
37
- "@ng-native/router": "0.6.0",
37
+ "@ng-native/router": "0.7.0",
38
38
  "rxjs": "^7.4.0"
39
39
  },
40
40
  "devDependencies": {
@@ -43,7 +43,7 @@
43
43
  "@angular/core": "22.2.0",
44
44
  "@angular/platform-browser": "22.2.0",
45
45
  "@angular/router": "22.2.0",
46
- "@ng-native/router": "0.6.0",
46
+ "@ng-native/router": "0.7.0",
47
47
  "rxjs": "^7.8.2"
48
48
  },
49
49
  "nx": {