@pitlane/content 0.1.1 → 0.2.1

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/CHANGELOG.md CHANGED
@@ -1,7 +1,34 @@
1
1
  # @pitlane/content
2
2
 
3
+ ## 0.2.1
4
+
5
+ ### Patch Changes
6
+
7
+ - f2fa73e: Read a heading's `text`, and the `id` made from it, from what the heading shows on the page. Three kinds of heading change, and an anchor written by hand against one of them needs checking once:
8
+
9
+ - Inline HTML now contributes its words and not its tags. `## <span>Visible</span> text` was `<span>Visible</span> text` with the `id` `spanvisiblespan-text`, and is now `Visible text` with `visible-text`.
10
+ - An image no longer contributes its alt text, which matches GitHub and Astro. `## [A](url) ![Cat photo](cat.png)` was `a-cat-photo` and is now `a-`, keeping the space before the image as GitHub does.
11
+ - In MDX, an expression that is a single string literal now contributes its value. `## Hello {"world"}` was `hello-` and is now `hello-world`, and `## The {"{"} key` reads `The { key`. Any other expression, such as `{name}`, still contributes nothing.
12
+
13
+ Headings without inline HTML, images, or expressions keep their `text` and `id`.
14
+
15
+ ## 0.2.0
16
+
17
+ ### Minor Changes
18
+
19
+ - 87ec1f6: Give headings the ids GitHub gives them. `headings()` now lowercases a heading, removes every character outside letters, marks, digits, and connector punctuation, and turns each space into a hyphen without collapsing or trimming any of them — the algorithm GitHub uses, and the one Astro's `rehype-heading-ids` uses through the same `github-slugger` package. `## Databases & Data Loading` was `databases-data-loading` and is now `databases--data-loading`; `## Jenni’s Quesadillas` was `jenni-s-quesadillas` and is now `jennis-quesadillas`.
20
+
21
+ A heading containing punctuation or symbols can therefore get a different `id` than it did before — `## Hello World!` keeps `hello-world`, but `## Databases & Data Loading` does not — so an anchor written by hand against the old ids needs checking once. In exchange, a table of contents carried over from GitHub or Astro keeps landing without being rewritten. A heading that slugs to nothing at all, such as `## 🎉`, still falls back to `heading` rather than to the empty `id` GitHub produces, and a later `## Heading` in the same document then takes `heading-1`.
22
+
23
+ ### Patch Changes
24
+
25
+ - f8b0db5: Keep content prebuilds from deleting the running app's optimized browser dependencies. This fixes `504 (Outdated Optimize Dep)` errors that could leave MDX updates and client-side navigation broken until the dev server restarted.
26
+ - 98e8a77: Vite no longer warns that it cannot analyze a dynamic import in `@pitlane/content` when an app using `contentLayer()` starts its dev server. The runtime import of a document's resolved dependencies is now marked `/* @vite-ignore */`, since its target is only known at request time.
27
+
3
28
  ## 0.1.1
4
29
 
30
+ Published 2026-09-21. [npm](https://www.npmjs.com/package/@pitlane/content/v/0.1.1) · [GitHub release](https://github.com/pitlane-tools/pitlane/releases/tag/%40pitlane/content%400.1.1) · [Source](https://github.com/pitlane-tools/pitlane/commit/b725843491ad0c36c61c83d44466134f76dbd615).
31
+
5
32
  Documentation only. No code changed.
6
33
 
7
34
  - The npm description is one line now: "Schema-validated content collections for Remix." The old one led with `createContent()` and ran well past what a registry listing shows.
@@ -11,11 +38,18 @@ Documentation only. No code changed.
11
38
 
12
39
  ## 0.1.0
13
40
 
41
+ Published 2026-09-21. [npm](https://www.npmjs.com/package/@pitlane/content/v/0.1.0) · [GitHub release](https://github.com/pitlane-tools/pitlane/releases/tag/%40pitlane/content%400.1.0) · [Source](https://github.com/pitlane-tools/pitlane/commit/31aae9c3c941238fbb94769e578e320179dc8284).
42
+
14
43
  Initial release.
15
44
 
16
45
  - `createContent` returns typed collection handles synchronously without loading entries. Reads and rendering remain asynchronous; declaration errors throw synchronously.
46
+ - An entry's data is validated against its collection's schema as it loads, before any query returns it. Any Standard Schema validator does that work, `remix/data-schema` and Zod included, and the entry type is inferred from the schema rather than generated: `CollectionEntry<typeof content.blog>` names one. A failure reports the entry, the collection, the file it came from, and every issue.
17
47
  - `getCollection`, `getCollection(filter)`, and `getEntry` over entries sorted by id; `c.reference(collection)` for typed pointers between collections.
18
48
  - `render()` resolves an entry's Markdown or MDX to a Remix component and its heading list, parsing nothing until it is called.
19
- - Two loader interfaces: `ContentLoader` resolves a whole collection in one execution and can be prebuilt, `LiveLoader` answers one query at a time and runs on every read. `loaders.glob` and `loaders.file` implement the first.
49
+ - Without a bundler, `render()` also resolves an MDX document's own imports relative to the document. A namespace import and `import.meta` are refused by name, since neither survives the function body an MDX document compiles to here.
50
+ - Two loader interfaces: `ContentLoader` resolves a whole collection in one execution and can be prebuilt, `LiveLoader` answers one query at a time and runs on every read. `loaders.glob` and `loaders.file` implement the first. `glob` reads Markdown, MDX, JSON, and YAML, one entry per file; `file` reads a single JSON or YAML file holding many entries, and takes a `parser` for any other format.
20
51
  - `contentLayer()` from `@pitlane/content/vite` loads `ContentLoader` collections after evaluating their declarations and inlines them into the bundle. It waits for loading and validation before emitting, and watches the loaders' sources in dev.
21
- - `headings()` from `@pitlane/content/satteri` produces the heading list on both rendering paths.
52
+ - `headings()` from `@pitlane/content/satteri` produces the heading list on both rendering paths. `rawStyles()` sits beside it and hands a `<style>` element's CSS to Remix as markup, which is what keeps an Expressive Code theme from reaching the page escaped into rules that match nothing. `render()` applies both; a Vite build passes them to `vite-plugin-satteri`.
53
+ - `hotContent()` from `@pitlane/content/hot` reloads the browser when a file behind a collection changes, for an application that runs from source with no build. It does nothing unless `remix/node-hmr` is supervising the process, so it can stay in production code. A file created after startup still needs a restart.
54
+ - Every peer dependency is optional, `remix` included. Reading and validating data imports neither it nor `satteri`; `render()` loads Remix only when something asks for a component, and names the entry that needed it if Remix is not installed. Node `^20.19.0 || >=22.12.0`.
55
+ - The prebuild channel, the manifest emitter, and the MDX import reader ship as `@pitlane/content/internal/prebuild`, `/internal/codegen`, and `/internal/mdx`, so a plugin for a bundler other than Vite can reuse them.
package/dist/index.mjs CHANGED
@@ -280,7 +280,7 @@ function view(collection, entry) {
280
280
  data: entry.data,
281
281
  ...entry.filePath === void 0 ? {} : { filePath: entry.filePath },
282
282
  render: async () => {
283
- return await (await import("./render-U9dXN6f0.mjs").catch((cause) => {
283
+ return await (await import("./render-Bg0i1C_C.mjs").catch((cause) => {
284
284
  throw missingRenderer(`${collection}/${entry.id}`, cause) ?? cause;
285
285
  })).renderedEntry(collection, entry);
286
286
  }
@@ -222,7 +222,14 @@ async function nodeResolution() {
222
222
  async function importFrom(specifier, from, where, node, attributes) {
223
223
  let resolved = specifier.startsWith(".") ? new URL(specifier, from).href : resolveBare(specifier, from, where, node);
224
224
  try {
225
- return await (attributes ? import(resolved, { with: attributes }) : import(resolved));
225
+ return await (attributes ? import(
226
+ /* @vite-ignore */
227
+ resolved,
228
+ { with: attributes }
229
+ ) : import(
230
+ /* @vite-ignore */
231
+ resolved
232
+ ));
226
233
  } catch (error) {
227
234
  let cause = error instanceof Error ? error.message : String(error);
228
235
  throw new Error(`"${where}" imports "${specifier}", which could not be loaded: ${cause}`, { cause: error });
@@ -3,7 +3,8 @@ import { HastPluginEntry, MdastPluginEntry } from "satteri";
3
3
  /**
4
4
  * Collects every heading of a document as `{ depth, slug, text }`, publishes the
5
5
  * list as `data.headings`, and gives each heading an `id` matching its slug so an
6
- * anchor link lands on it. On MDX the list is also appended to the tree as
6
+ * anchor link lands on it. A heading's text is the text it shows on the page,
7
+ * as `visibleText` reads it. On MDX the list is also appended to the tree as
7
8
  * `export const headings`, so the compiled module carries its own table of
8
9
  * contents.
9
10
  *
package/dist/satteri.mjs CHANGED
@@ -1,19 +1,40 @@
1
1
  //#region src/satteri.ts
2
2
  /**
3
- * The base slug for a heading with no letters or digits at all (`## ---`). An
4
- * empty `id` is invalid HTML and makes the anchor a bare `#`, which lands
5
- * nowhere; a fixed word plus the usual collision suffix keeps such headings
6
- * addressable and distinct.
3
+ * The base slug for a heading that slugs to nothing at all, such as `## ***` or
4
+ * `## 🎉`. GitHub answers the empty string there; an empty `id` is invalid HTML
5
+ * and makes the anchor a bare `#`, which lands nowhere, so a fixed word plus
6
+ * the usual collision suffix keeps such headings addressable and distinct. This
7
+ * is the one case where these slugs are deliberately not GitHub's.
7
8
  */
8
9
  const FALLBACK_SLUG = "heading";
9
10
  /**
10
- * The slug for `text`, kept distinct from every slug `taken` already holds by
11
+ * Every character GitHub's slugger removes: anything that is not alphabetic, a
12
+ * combining mark, a decimal digit, connector punctuation, a space, or a hyphen.
13
+ * Marks are kept because dropping them would shatter Devanagari, Hebrew, and
14
+ * Arabic words into bare consonants; letters of every script are kept so a
15
+ * Japanese or Cyrillic heading slugs to its own text rather than to nothing.
16
+ *
17
+ * `github-slugger` ships this set as a table generated from Unicode 13, while a
18
+ * regular expression matches against whatever Unicode version the engine
19
+ * carries. A character assigned after Unicode 13 therefore survives here and
20
+ * would be stripped there; nothing assigned in Unicode 13 or earlier differs.
21
+ */
22
+ const STRIPPED = /[^\p{Alphabetic}\p{M}\p{Nd}\p{Pc} -]/gu;
23
+ /**
24
+ * The slug for `text`, built the way GitHub builds a heading's `id`: lowercase
25
+ * it, remove every stripped character, then turn each remaining space into a
26
+ * hyphen. Nothing is collapsed and nothing is trimmed, so `Databases & Data
27
+ * Loading` slugs to `databases--data-loading` and `## ---` to `---`. Astro slugs
28
+ * with the same algorithm, so a table of contents written by hand against
29
+ * either of them keeps landing after a move to Pitlane.
30
+ *
31
+ * The result is then kept distinct from every slug `taken` already holds by
11
32
  * suffixing `-1`, `-2`, … The map remembers the last suffix tried for a base so
12
33
  * a document of a hundred identical headings stays linear, and the loop covers
13
34
  * the case where the suffixed candidate is itself a real heading's slug.
14
35
  */
15
36
  function uniqueSlug(text, taken) {
16
- let base = text.toLowerCase().replace(/[^\p{L}\p{N}\p{M}]+/gu, "-").replace(/^-+|-+$/g, "");
37
+ let base = text.toLowerCase().replace(STRIPPED, "").replaceAll(" ", "-");
17
38
  if (!base) base = FALLBACK_SLUG;
18
39
  let suffix = taken.get(base) ?? 0;
19
40
  let slug = base;
@@ -26,9 +47,73 @@ function uniqueSlug(text, taken) {
26
47
  return slug;
27
48
  }
28
49
  /**
50
+ * The text a heading shows on the page, which is what GitHub and Astro slug.
51
+ * Sätteri's `textContent` differs in three places: it keeps raw HTML tags as
52
+ * text, includes image alt text, and reads every MDX expression as nothing.
53
+ * Its options drop the first two, but an expression only carries its source,
54
+ * so the walk is done here.
55
+ *
56
+ * Raw HTML nodes hold only the tags; the text between them is already its own
57
+ * sibling node, so dropping `html` leaves the visible words. Images render no
58
+ * text.
59
+ */
60
+ function visibleText(node) {
61
+ switch (node.type) {
62
+ case "html":
63
+ case "image":
64
+ case "imageReference": return "";
65
+ case "mdxTextExpression": return stringLiteralValue(node.value ?? "") ?? "";
66
+ }
67
+ if (node.children) return node.children.map(visibleText).join("");
68
+ return node.value ?? "";
69
+ }
70
+ /** A lone JavaScript string or template literal, surrounded by nothing but whitespace. */
71
+ const STRING_LITERAL = /^\s*(?:"((?:[^"\\\n\r]|\\[^])*)"|'((?:[^'\\\n\r]|\\[^])*)'|`((?:[^`\\$]|\\[^]|\$(?!\{))*)`)\s*$/;
72
+ /**
73
+ * One escape sequence: a code point in either `\u` form, a `\x` byte, `\0` not
74
+ * followed by a digit, a line continuation, or any other escaped character.
75
+ */
76
+ const ESCAPE = /\\(?:u\{([\da-fA-F]+)\}|u([\da-fA-F]{4})|x([\da-fA-F]{2})|(0)(?!\d)|(\r\n|[\n\r\u2028\u2029])|([^]))/g;
77
+ const SINGLE_CHARACTER_ESCAPES = {
78
+ b: "\b",
79
+ f: "\f",
80
+ n: "\n",
81
+ r: "\r",
82
+ t: " ",
83
+ v: "\v"
84
+ };
85
+ /**
86
+ * The value of an MDX expression whose source is a lone string literal, such
87
+ * as `{"{"}`, the usual way to write a brace in MDX text. `undefined` for any
88
+ * other expression, whose value is only known once the module runs.
89
+ *
90
+ * Escapes decode as in a module, which is strict code: a legacy octal escape
91
+ * such as `\1`, a `\8`, or a malformed `\x` or `\u` makes the literal invalid.
92
+ */
93
+ function stringLiteralValue(source) {
94
+ let match = STRING_LITERAL.exec(source);
95
+ if (!match) return void 0;
96
+ let [, double, single, template] = match;
97
+ let body = double ?? single ?? template.replace(/\r\n?/g, "\n");
98
+ let valid = true;
99
+ let value = body.replace(ESCAPE, (_, braced, unit, byte, nul, lineBreak, other) => {
100
+ if (braced !== void 0) {
101
+ let codePoint = Number.parseInt(braced, 16);
102
+ if (codePoint <= 1114111) return String.fromCodePoint(codePoint);
103
+ } else if (unit !== void 0 || byte !== void 0) return String.fromCharCode(Number.parseInt(unit ?? byte, 16));
104
+ else if (nul !== void 0) return "\0";
105
+ else if (lineBreak !== void 0) return "";
106
+ else if (!/[ux\d]/.test(other)) return SINGLE_CHARACTER_ESCAPES[other] ?? other;
107
+ valid = false;
108
+ return "";
109
+ });
110
+ return valid ? value : void 0;
111
+ }
112
+ /**
29
113
  * Collects every heading of a document as `{ depth, slug, text }`, publishes the
30
114
  * list as `data.headings`, and gives each heading an `id` matching its slug so an
31
- * anchor link lands on it. On MDX the list is also appended to the tree as
115
+ * anchor link lands on it. A heading's text is the text it shows on the page,
116
+ * as `visibleText` reads it. On MDX the list is also appended to the tree as
32
117
  * `export const headings`, so the compiled module carries its own table of
33
118
  * contents.
34
119
  *
@@ -51,7 +136,7 @@ function headings() {
51
136
  return {
52
137
  name: "pitlane-headings",
53
138
  heading(node, context) {
54
- let text = context.textContent(node);
139
+ let text = visibleText(node);
55
140
  let slug = uniqueSlug(text, taken);
56
141
  collected.push({
57
142
  depth: node.depth,
package/dist/vite.mjs CHANGED
@@ -225,6 +225,7 @@ async function inPrebuildServer(root, entry, resolution, onWatched) {
225
225
  root,
226
226
  configFile: false,
227
227
  logLevel: "silent",
228
+ optimizeDeps: { noDiscovery: true },
228
229
  resolve: resolution,
229
230
  server: {
230
231
  middlewareMode: true,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@pitlane/content",
3
- "version": "0.1.1",
3
+ "version": "0.2.1",
4
4
  "description": "Schema-validated content collections for Remix.",
5
5
  "keywords": [
6
6
  "content",