starlight-cannoli-plugins 1.2.17 → 2.0.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/README.md +25 -39
- package/dist/chunk-3OL3VUEB.js +143 -0
- package/dist/{chunk-KQM5EAEK.js → chunk-47X5MKFJ.js} +52 -27
- package/dist/chunk-AZPHBHBE.js +71 -0
- package/dist/{chunk-HRUZQZ5L.js → chunk-FQLJMU2J.js} +15 -13
- package/dist/chunk-S4YMC25A.js +149 -0
- package/dist/cli/cannoli-latex-cleanup.js +1 -1
- package/dist/index.d.ts +17 -11
- package/dist/index.js +64 -67
- package/dist/plugins/astro-normalize-paths.d.ts +12 -0
- package/dist/plugins/astro-normalize-paths.js +9 -0
- package/dist/plugins/rehype-validate-links.js +1 -1
- package/dist/plugins/remark-latex-compile.d.ts +41 -4
- package/dist/plugins/remark-latex-compile.js +4 -6
- package/dist/plugins/starlight-sync-docs-to-public.d.ts +6 -9
- package/dist/plugins/starlight-sync-docs-to-public.js +5 -3
- package/dist/styles/_starlight.scss +3 -3
- package/package.json +1 -5
- package/dist/chunk-DEXMXUQL.js +0 -229
- package/dist/chunk-SBGY6FD3.js +0 -191
- package/dist/index-Ce1VCMrW.d.ts +0 -45
- package/dist/plugins/starlight-latex-compile.d.ts +0 -4
- package/dist/plugins/starlight-latex-compile.js +0 -10
package/dist/chunk-SBGY6FD3.js
DELETED
|
@@ -1,191 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseFrontmatter
|
|
3
|
-
} from "./chunk-3ATSZG6H.js";
|
|
4
|
-
|
|
5
|
-
// src/plugins/starlight-sync-docs-to-public.ts
|
|
6
|
-
import { cp, mkdir, readdir, readFile, writeFile, rm, stat } from "fs/promises";
|
|
7
|
-
import { resolve, relative } from "path";
|
|
8
|
-
import { minimatch } from "minimatch";
|
|
9
|
-
var DEFAULT_SRC_DIR = "src/content/docs";
|
|
10
|
-
var DEFAULT_PUBLIC_DIR = "public";
|
|
11
|
-
async function fullSync(srcDir, publicDir, preserveDirs, ignorePatterns) {
|
|
12
|
-
await mkdir(publicDir, { recursive: true });
|
|
13
|
-
const items = await readdir(publicDir);
|
|
14
|
-
for (const item of items) {
|
|
15
|
-
const itemPath = resolve(publicDir, item);
|
|
16
|
-
let itemStat;
|
|
17
|
-
try {
|
|
18
|
-
itemStat = await stat(itemPath);
|
|
19
|
-
} catch (err) {
|
|
20
|
-
if (err?.code === "ENOENT") {
|
|
21
|
-
continue;
|
|
22
|
-
}
|
|
23
|
-
throw err;
|
|
24
|
-
}
|
|
25
|
-
if (preserveDirs.includes(item) || !itemStat.isDirectory()) {
|
|
26
|
-
continue;
|
|
27
|
-
}
|
|
28
|
-
await rm(itemPath, { recursive: true, force: true });
|
|
29
|
-
}
|
|
30
|
-
await copyWithRetry(srcDir, publicDir, ignorePatterns);
|
|
31
|
-
console.log(
|
|
32
|
-
`[starlight-sync-docs-to-public] Synced ${DEFAULT_SRC_DIR}/ \u2192 ${DEFAULT_PUBLIC_DIR}/ (full sync)`
|
|
33
|
-
);
|
|
34
|
-
}
|
|
35
|
-
async function incrementalSync(changedFilePath, srcDir, publicDir, ignorePatterns) {
|
|
36
|
-
const rel = relative(srcDir, changedFilePath);
|
|
37
|
-
if (ignorePatterns.some((pattern) => minimatch(rel, pattern, { dot: true }))) {
|
|
38
|
-
return;
|
|
39
|
-
}
|
|
40
|
-
if (changedFilePath.endsWith(".md") || changedFilePath.endsWith(".mdx")) {
|
|
41
|
-
try {
|
|
42
|
-
const frontmatter = parseFrontmatter(changedFilePath);
|
|
43
|
-
if (frontmatter.draft === true) return;
|
|
44
|
-
} catch {
|
|
45
|
-
return;
|
|
46
|
-
}
|
|
47
|
-
}
|
|
48
|
-
const destPath = resolve(publicDir, rel);
|
|
49
|
-
let srcStat;
|
|
50
|
-
try {
|
|
51
|
-
srcStat = await stat(changedFilePath);
|
|
52
|
-
} catch (err) {
|
|
53
|
-
if (err?.code === "ENOENT") {
|
|
54
|
-
await rm(destPath, { recursive: true, force: true });
|
|
55
|
-
return;
|
|
56
|
-
}
|
|
57
|
-
throw err;
|
|
58
|
-
}
|
|
59
|
-
if (srcStat.isDirectory()) {
|
|
60
|
-
await mkdir(destPath, { recursive: true });
|
|
61
|
-
const files = await readdir(changedFilePath);
|
|
62
|
-
for (const file of files) {
|
|
63
|
-
await incrementalSync(
|
|
64
|
-
resolve(changedFilePath, file),
|
|
65
|
-
srcDir,
|
|
66
|
-
publicDir,
|
|
67
|
-
ignorePatterns
|
|
68
|
-
);
|
|
69
|
-
}
|
|
70
|
-
} else {
|
|
71
|
-
await mkdir(resolve(destPath, ".."), { recursive: true });
|
|
72
|
-
const content = await readFile(changedFilePath);
|
|
73
|
-
await writeFile(destPath, content);
|
|
74
|
-
}
|
|
75
|
-
console.log(
|
|
76
|
-
`[starlight-sync-docs-to-public] Synced ${rel}`
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
async function copyWithRetry(srcDir, publicDir, ignorePatterns) {
|
|
80
|
-
let lastError;
|
|
81
|
-
for (let attempt = 0; attempt < 3; attempt++) {
|
|
82
|
-
try {
|
|
83
|
-
await cp(srcDir, publicDir, {
|
|
84
|
-
recursive: true,
|
|
85
|
-
force: true,
|
|
86
|
-
filter: (src) => {
|
|
87
|
-
const rel = relative(srcDir, src);
|
|
88
|
-
if (rel === "") return true;
|
|
89
|
-
if (ignorePatterns.some((pattern) => minimatch(rel, pattern, { dot: true }))) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
if (src.endsWith(".md") || src.endsWith(".mdx")) {
|
|
93
|
-
try {
|
|
94
|
-
const frontmatter = parseFrontmatter(src);
|
|
95
|
-
if (frontmatter.draft === true) return false;
|
|
96
|
-
} catch {
|
|
97
|
-
return false;
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
return true;
|
|
101
|
-
}
|
|
102
|
-
});
|
|
103
|
-
return;
|
|
104
|
-
} catch (err) {
|
|
105
|
-
lastError = err;
|
|
106
|
-
const code = err?.code;
|
|
107
|
-
const isRaceCondition = code === "EEXIST" || code === "ENOENT";
|
|
108
|
-
if (!isRaceCondition) {
|
|
109
|
-
throw err;
|
|
110
|
-
}
|
|
111
|
-
if (attempt < 2) {
|
|
112
|
-
await new Promise((resolve2) => setTimeout(resolve2, 10 * (attempt + 1)));
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
if (lastError) {
|
|
117
|
-
const code = lastError?.code;
|
|
118
|
-
if (code === "EEXIST" || code === "ENOENT") {
|
|
119
|
-
return;
|
|
120
|
-
}
|
|
121
|
-
throw lastError;
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
function starlightSyncDocsToPublic(options) {
|
|
125
|
-
const srcDir = resolve(DEFAULT_SRC_DIR);
|
|
126
|
-
const publicDir = resolve(DEFAULT_PUBLIC_DIR);
|
|
127
|
-
const { preserveDirs, ignorePatterns = [] } = options;
|
|
128
|
-
return {
|
|
129
|
-
name: "starlight-sync-docs-to-public",
|
|
130
|
-
hooks: {
|
|
131
|
-
"config:setup": (hook) => {
|
|
132
|
-
hook.addIntegration({
|
|
133
|
-
name: "astro-sync-docs-to-public",
|
|
134
|
-
hooks: {
|
|
135
|
-
"astro:build:start": async () => {
|
|
136
|
-
await fullSync(srcDir, publicDir, preserveDirs, ignorePatterns);
|
|
137
|
-
},
|
|
138
|
-
"astro:server:setup": ({ server }) => {
|
|
139
|
-
let isSyncing = false;
|
|
140
|
-
let needsResync = false;
|
|
141
|
-
let lastChangedFile;
|
|
142
|
-
const performSync = async () => {
|
|
143
|
-
if (isSyncing) {
|
|
144
|
-
needsResync = true;
|
|
145
|
-
return;
|
|
146
|
-
}
|
|
147
|
-
isSyncing = true;
|
|
148
|
-
try {
|
|
149
|
-
if (lastChangedFile) {
|
|
150
|
-
await incrementalSync(
|
|
151
|
-
lastChangedFile,
|
|
152
|
-
srcDir,
|
|
153
|
-
publicDir,
|
|
154
|
-
ignorePatterns
|
|
155
|
-
);
|
|
156
|
-
}
|
|
157
|
-
if (needsResync) {
|
|
158
|
-
needsResync = false;
|
|
159
|
-
lastChangedFile = void 0;
|
|
160
|
-
await performSync();
|
|
161
|
-
}
|
|
162
|
-
} catch (err) {
|
|
163
|
-
console.error(err);
|
|
164
|
-
} finally {
|
|
165
|
-
isSyncing = false;
|
|
166
|
-
}
|
|
167
|
-
};
|
|
168
|
-
fullSync(srcDir, publicDir, preserveDirs, ignorePatterns).catch(
|
|
169
|
-
console.error
|
|
170
|
-
);
|
|
171
|
-
let debounceTimer = null;
|
|
172
|
-
server.watcher.add(srcDir);
|
|
173
|
-
server.watcher.on("all", (_event, filePath) => {
|
|
174
|
-
if (!filePath.startsWith(srcDir)) return;
|
|
175
|
-
lastChangedFile = filePath;
|
|
176
|
-
if (debounceTimer) clearTimeout(debounceTimer);
|
|
177
|
-
debounceTimer = setTimeout(() => {
|
|
178
|
-
performSync();
|
|
179
|
-
}, 100);
|
|
180
|
-
});
|
|
181
|
-
}
|
|
182
|
-
}
|
|
183
|
-
});
|
|
184
|
-
}
|
|
185
|
-
}
|
|
186
|
-
};
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
export {
|
|
190
|
-
starlightSyncDocsToPublic
|
|
191
|
-
};
|
package/dist/index-Ce1VCMrW.d.ts
DELETED
|
@@ -1,45 +0,0 @@
|
|
|
1
|
-
import { HookParameters } from '@astrojs/starlight/types';
|
|
2
|
-
import { Root } from 'hast';
|
|
3
|
-
import { VFile } from 'vfile';
|
|
4
|
-
|
|
5
|
-
interface CompilationResult {
|
|
6
|
-
hash: string;
|
|
7
|
-
svgPath: string;
|
|
8
|
-
wasCompiled: boolean;
|
|
9
|
-
}
|
|
10
|
-
/**
|
|
11
|
-
* Compile LaTeX code to SVG.
|
|
12
|
-
*
|
|
13
|
-
* @param latexCode - The LaTeX code to compile (e.g., TikZ, pgfplots, etc.)
|
|
14
|
-
* @param svgOutputDir - The directory where SVG files should be written
|
|
15
|
-
* @returns Result object with hash, svgPath, and whether compilation occurred
|
|
16
|
-
* @throws Error if compilation fails
|
|
17
|
-
*/
|
|
18
|
-
declare function compileLatexToSvg(latexCode: string, svgOutputDir: string): CompilationResult;
|
|
19
|
-
|
|
20
|
-
/**
|
|
21
|
-
* Starlight plugin wrapper for remark-latex-compile.
|
|
22
|
-
*
|
|
23
|
-
* This plugin hooks into Starlight's config:setup to inject the remark-latex-compile
|
|
24
|
-
* plugin and the build-time Astro integration for scanning markdown files.
|
|
25
|
-
*/
|
|
26
|
-
|
|
27
|
-
type StarlightLatexCompileOptions = RemarkLatexCompileOptions;
|
|
28
|
-
declare function starlightLatexCompile(options: StarlightLatexCompileOptions): {
|
|
29
|
-
name: string;
|
|
30
|
-
hooks: {
|
|
31
|
-
"config:setup": (hook: HookParameters<"config:setup">) => void;
|
|
32
|
-
};
|
|
33
|
-
};
|
|
34
|
-
|
|
35
|
-
declare function rehypeLatexCompile(): (tree: Root, _file: VFile) => void;
|
|
36
|
-
|
|
37
|
-
interface RemarkLatexCompileOptions {
|
|
38
|
-
/**
|
|
39
|
-
* Directory where SVG files should be written.
|
|
40
|
-
*/
|
|
41
|
-
svgOutputDir: string;
|
|
42
|
-
}
|
|
43
|
-
declare function remarkLatexCompile(options: RemarkLatexCompileOptions): (tree: Record<string, unknown>, file: unknown) => void;
|
|
44
|
-
|
|
45
|
-
export { type RemarkLatexCompileOptions as R, type StarlightLatexCompileOptions as S, remarkLatexCompile as a, compileLatexToSvg as c, rehypeLatexCompile as r, starlightLatexCompile as s };
|