@nifrajs/content 3.1.0 → 3.3.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/package.json +1 -1
- package/src/fs.ts +4 -4
- package/src/mdx.ts +18 -1
package/package.json
CHANGED
package/src/fs.ts
CHANGED
|
@@ -59,7 +59,7 @@ interface CachedEntry<Frontmatter> {
|
|
|
59
59
|
}
|
|
60
60
|
|
|
61
61
|
interface CollectionSnapshot<Frontmatter> {
|
|
62
|
-
readonly
|
|
62
|
+
readonly fingerprint: string
|
|
63
63
|
readonly entries: Array<Entry<Frontmatter>>
|
|
64
64
|
}
|
|
65
65
|
|
|
@@ -108,14 +108,14 @@ export function defineCollection<S extends StandardSchemaV1>(
|
|
|
108
108
|
return {
|
|
109
109
|
async all() {
|
|
110
110
|
const files = listFiles()
|
|
111
|
-
const
|
|
112
|
-
if (collectionCache?.
|
|
111
|
+
const fingerprint = files.map((file) => `${file.file}\0${file.stamp}`).join("\0")
|
|
112
|
+
if (collectionCache?.fingerprint === fingerprint) return [...collectionCache.entries]
|
|
113
113
|
|
|
114
114
|
const entries = await Promise.all(
|
|
115
115
|
files.map((file) => readEntry(file.path, slugOf(file.file), file.stamp)),
|
|
116
116
|
)
|
|
117
117
|
collectionCache = {
|
|
118
|
-
|
|
118
|
+
fingerprint,
|
|
119
119
|
entries,
|
|
120
120
|
}
|
|
121
121
|
return [...entries]
|
package/src/mdx.ts
CHANGED
|
@@ -15,8 +15,25 @@
|
|
|
15
15
|
* MDX is JSX-oriented, so this targets the JSX family (React/Preact/Solid) via `jsxImportSource`. Needs
|
|
16
16
|
* `@mdx-js/mdx` installed (an optional peer - lazy-loaded at build time only).
|
|
17
17
|
*/
|
|
18
|
+
|
|
19
|
+
import { fileURLToPath } from "node:url"
|
|
18
20
|
import type { BunPlugin } from "bun"
|
|
19
21
|
|
|
22
|
+
/** Convert Bun's file-URL pathname form (`/D:/…`) into a path the host filesystem can open. */
|
|
23
|
+
function normalizeFilePath(path: string): string {
|
|
24
|
+
let value = path.split("?", 1)[0] ?? path
|
|
25
|
+
if (value.startsWith("file://")) {
|
|
26
|
+
try {
|
|
27
|
+
value = fileURLToPath(value)
|
|
28
|
+
} catch {
|
|
29
|
+
// Let Bun report an invalid path at the actual read boundary.
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
if (process.platform !== "win32") return value
|
|
33
|
+
if (/^\/[A-Za-z]:[\\/]/.test(value)) value = value.slice(1)
|
|
34
|
+
return value.replaceAll("/", "\\")
|
|
35
|
+
}
|
|
36
|
+
|
|
20
37
|
export interface MdxPluginOptions {
|
|
21
38
|
/** JSX runtime source the compiled MDX imports from - `"react"` (default), `"preact"`, `"solid-js"`. */
|
|
22
39
|
readonly jsxImportSource?: string
|
|
@@ -59,7 +76,7 @@ export function mdxBunPlugin(options: MdxPluginOptions = {}): BunPlugin {
|
|
|
59
76
|
// Tolerate a `?query` suffix - `nifra dev` (Vite) appends an import-cache-busting query so edited
|
|
60
77
|
// `.mdx` re-SSR; strip it before reading off disk.
|
|
61
78
|
build.onLoad({ filter: /\.mdx(\?|$)/ }, async (args) => {
|
|
62
|
-
const path = args.path
|
|
79
|
+
const path = normalizeFilePath(args.path)
|
|
63
80
|
const source = await Bun.file(path).text()
|
|
64
81
|
const compiled = await compile(source, {
|
|
65
82
|
jsxImportSource,
|