starlight-cannoli-plugins 2.1.8 → 2.1.9
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/{chunk-3ATSZG6H.js → chunk-IY4A67ZP.js} +7 -175
- package/dist/chunk-N2I2GJW3.js +238 -0
- package/dist/{chunk-KJ6KZOCD.js → chunk-WZNJ5VFU.js} +1 -1
- package/dist/{chunk-TTQY54Q6.js → chunk-XVMRLEQM.js} +113 -24
- package/dist/cpp-VZKLUKT7.js +1 -1
- package/dist/{erb-5EKNOWNJ.js → erb-WAGUANI2.js} +3 -3
- package/dist/index.d.ts +1 -1
- package/dist/index.js +4 -7
- package/dist/{just-DKAU2FPN.js → just-PYDV7ZQ7.js} +3 -3
- package/dist/plugins/astro-latex-compile.d.ts +3 -6
- package/dist/plugins/astro-latex-compile.js +3 -7
- package/dist/plugins/astro-sync-docs-to-public/page-script.js +9 -4
- package/dist/plugins/astro-sync-docs-to-public.js +2 -2
- package/dist/plugins/starlight-index-only-sidebar.js +2 -2
- package/dist/{rst-OXRHDCQE.js → rst-V6D7WWXH.js} +3 -3
- package/dist/{ruby-SUFBDHOR.js → ruby-QQFN2P53.js} +3 -3
- package/dist/styles/page-src-context-menu.scss +29 -0
- package/dist/{twig-BNCU37LV.js → twig-CHAFMQ5H.js} +3 -3
- package/package.json +1 -1
- package/dist/chunk-HDL4DZNT.js +0 -65
- package/dist/chunk-IX5UFISR.js +0 -149
- package/dist/cli/cannoli-latex-cleanup.d.ts +0 -1
- package/dist/cli/cannoli-latex-cleanup.js +0 -128
- package/dist/{blade-N26A55JB.js → blade-MNWQFAXA.js} +3 -3
- package/dist/{chunk-26NQJBXH.js → chunk-7DJE5LRN.js} +3 -3
- package/dist/{crystal-OIARPJAM.js → crystal-MYUTTSDY.js} +3 -3
- package/dist/{julia-T3UAQLFW.js → julia-VFJDJOWL.js} +3 -3
- package/dist/{ts-tags-DME2ZSNV.js → ts-tags-O77G7HGT.js} +1 -1
|
@@ -1718,10 +1718,6 @@ var require_components2 = __commonJS({
|
|
|
1718
1718
|
}
|
|
1719
1719
|
});
|
|
1720
1720
|
|
|
1721
|
-
// src/plugins/utils/sidebar-builder-utils.ts
|
|
1722
|
-
import * as fs from "fs";
|
|
1723
|
-
import * as path2 from "path";
|
|
1724
|
-
|
|
1725
1721
|
// node_modules/remark-smartypants/dist/plugin.js
|
|
1726
1722
|
import { visit } from "unist-util-visit";
|
|
1727
1723
|
|
|
@@ -5102,24 +5098,8 @@ function parseFrontmatter(code, options) {
|
|
|
5102
5098
|
// node_modules/@astrojs/markdown-remark/dist/index.js
|
|
5103
5099
|
var isPerformanceBenchmark = Boolean(process.env.ASTRO_PERFORMANCE_BENCHMARK);
|
|
5104
5100
|
|
|
5105
|
-
// src/plugins/utils/
|
|
5106
|
-
|
|
5107
|
-
try {
|
|
5108
|
-
return fs.statSync(filePath).isDirectory();
|
|
5109
|
-
} catch {
|
|
5110
|
-
return false;
|
|
5111
|
-
}
|
|
5112
|
-
}
|
|
5113
|
-
function findIndexMd(dirPath) {
|
|
5114
|
-
const indexMd = path2.join(dirPath, "index.md");
|
|
5115
|
-
const indexMdx = path2.join(dirPath, "index.mdx");
|
|
5116
|
-
try {
|
|
5117
|
-
if (fs.statSync(indexMd).isFile()) return indexMd;
|
|
5118
|
-
if (fs.statSync(indexMdx).isFile()) return indexMdx;
|
|
5119
|
-
} catch {
|
|
5120
|
-
}
|
|
5121
|
-
return null;
|
|
5122
|
-
}
|
|
5101
|
+
// src/plugins/utils/workspace-utils.ts
|
|
5102
|
+
import * as fs from "fs";
|
|
5123
5103
|
function parseFrontmatter2(filePath) {
|
|
5124
5104
|
let content;
|
|
5125
5105
|
try {
|
|
@@ -5131,164 +5111,16 @@ function parseFrontmatter2(filePath) {
|
|
|
5131
5111
|
const { frontmatter } = parseFrontmatter(content);
|
|
5132
5112
|
return frontmatter;
|
|
5133
5113
|
} catch (err) {
|
|
5134
|
-
console.warn(
|
|
5135
|
-
|
|
5136
|
-
|
|
5137
|
-
}
|
|
5138
|
-
function getSlug(dirPath, rootDir) {
|
|
5139
|
-
const normalized = path2.normalize(dirPath).replace(/\\/g, "/");
|
|
5140
|
-
const rootParent = path2.normalize(path2.dirname(rootDir)).replace(/\\/g, "/");
|
|
5141
|
-
const slug = normalized.startsWith(rootParent) ? normalized.slice(rootParent.length + 1) : normalized;
|
|
5142
|
-
return slug + "/index";
|
|
5143
|
-
}
|
|
5144
|
-
function hasIndexMdInSubtree(dirPath) {
|
|
5145
|
-
const indexFile = findIndexMd(dirPath);
|
|
5146
|
-
if (indexFile) {
|
|
5147
|
-
const fm = parseFrontmatter2(indexFile);
|
|
5148
|
-
if (fm.draft || fm.sidebar?.hidden) return false;
|
|
5149
|
-
return true;
|
|
5150
|
-
}
|
|
5151
|
-
try {
|
|
5152
|
-
const entries = fs.readdirSync(dirPath);
|
|
5153
|
-
for (const entry of entries) {
|
|
5154
|
-
if (entry === "assets") continue;
|
|
5155
|
-
const fullPath = path2.join(dirPath, entry);
|
|
5156
|
-
if (isDir(fullPath) && hasIndexMdInSubtree(fullPath)) {
|
|
5157
|
-
return true;
|
|
5158
|
-
}
|
|
5159
|
-
}
|
|
5160
|
-
} catch {
|
|
5161
|
-
return false;
|
|
5162
|
-
}
|
|
5163
|
-
return false;
|
|
5164
|
-
}
|
|
5165
|
-
function isGroupItem(item) {
|
|
5166
|
-
return "items" in item;
|
|
5167
|
-
}
|
|
5168
|
-
function pathSegmentToLabel(pathSegment) {
|
|
5169
|
-
let label = pathSegment.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
5170
|
-
const match = label.match(/^([a-z]+) [0-9]{2,}/i);
|
|
5171
|
-
if (match) {
|
|
5172
|
-
const firstGroup = match[1];
|
|
5173
|
-
const uppercasedFirstGroup = firstGroup.toUpperCase();
|
|
5174
|
-
label = uppercasedFirstGroup + label.substring(firstGroup.length);
|
|
5175
|
-
}
|
|
5176
|
-
return label;
|
|
5177
|
-
}
|
|
5178
|
-
function buildSidebarItems(dirPath, rootDir, currentDepth, maxDepth, dirnameDeterminesLabels, parentDirName = "") {
|
|
5179
|
-
const items = [];
|
|
5180
|
-
const indexFile = findIndexMd(dirPath);
|
|
5181
|
-
if (indexFile) {
|
|
5182
|
-
const fm = parseFrontmatter2(indexFile);
|
|
5183
|
-
if (!fm.draft && !fm.sidebar?.hidden) {
|
|
5184
|
-
let label;
|
|
5185
|
-
if (currentDepth >= maxDepth && parentDirName) {
|
|
5186
|
-
label = parentDirName;
|
|
5187
|
-
} else if (dirnameDeterminesLabels) {
|
|
5188
|
-
label = "Overview";
|
|
5189
|
-
} else {
|
|
5190
|
-
label = fm.title || "Overview";
|
|
5191
|
-
}
|
|
5192
|
-
items.push({
|
|
5193
|
-
label,
|
|
5194
|
-
slug: getSlug(dirPath, rootDir)
|
|
5195
|
-
});
|
|
5196
|
-
}
|
|
5197
|
-
}
|
|
5198
|
-
if (currentDepth >= maxDepth) {
|
|
5199
|
-
const flattenedItems = flattenIndexFilesAtDepth(
|
|
5200
|
-
dirPath,
|
|
5201
|
-
rootDir,
|
|
5202
|
-
dirnameDeterminesLabels
|
|
5114
|
+
console.warn(
|
|
5115
|
+
`[parseFrontmatter] Failed to parse frontmatter in ${filePath}:`,
|
|
5116
|
+
err
|
|
5203
5117
|
);
|
|
5204
|
-
|
|
5205
|
-
return items;
|
|
5206
|
-
}
|
|
5207
|
-
try {
|
|
5208
|
-
const entries = fs.readdirSync(dirPath).sort();
|
|
5209
|
-
for (const entry of entries) {
|
|
5210
|
-
if (entry === "assets") continue;
|
|
5211
|
-
const fullPath = path2.join(dirPath, entry);
|
|
5212
|
-
if (!isDir(fullPath)) continue;
|
|
5213
|
-
if (!hasIndexMdInSubtree(fullPath)) continue;
|
|
5214
|
-
const subItems = buildSidebarItems(
|
|
5215
|
-
fullPath,
|
|
5216
|
-
rootDir,
|
|
5217
|
-
currentDepth + 1,
|
|
5218
|
-
maxDepth,
|
|
5219
|
-
dirnameDeterminesLabels,
|
|
5220
|
-
entry
|
|
5221
|
-
);
|
|
5222
|
-
const hasIndex = findIndexMd(fullPath) !== null;
|
|
5223
|
-
if (!hasIndex) {
|
|
5224
|
-
const allGroups = subItems.length > 0 && subItems.every(isGroupItem);
|
|
5225
|
-
if (allGroups || subItems.length === 1 && isGroupItem(subItems[0])) {
|
|
5226
|
-
items.push(...subItems);
|
|
5227
|
-
} else {
|
|
5228
|
-
items.push({
|
|
5229
|
-
label: pathSegmentToLabel(entry),
|
|
5230
|
-
items: subItems
|
|
5231
|
-
});
|
|
5232
|
-
}
|
|
5233
|
-
} else {
|
|
5234
|
-
items.push({
|
|
5235
|
-
label: pathSegmentToLabel(entry),
|
|
5236
|
-
items: subItems
|
|
5237
|
-
});
|
|
5238
|
-
}
|
|
5239
|
-
}
|
|
5240
|
-
} catch {
|
|
5241
|
-
}
|
|
5242
|
-
return items;
|
|
5243
|
-
}
|
|
5244
|
-
function flattenIndexFilesAtDepth(dirPath, rootDir, dirnameDeterminesLabels) {
|
|
5245
|
-
const items = [];
|
|
5246
|
-
try {
|
|
5247
|
-
const entries = fs.readdirSync(dirPath);
|
|
5248
|
-
for (const entry of entries) {
|
|
5249
|
-
if (entry === "assets") continue;
|
|
5250
|
-
const fullPath = path2.join(dirPath, entry);
|
|
5251
|
-
if (!isDir(fullPath)) continue;
|
|
5252
|
-
const indexFile = findIndexMd(fullPath);
|
|
5253
|
-
if (indexFile) {
|
|
5254
|
-
const fm = parseFrontmatter2(indexFile);
|
|
5255
|
-
if (!fm.draft && !fm.sidebar?.hidden) {
|
|
5256
|
-
items.push({
|
|
5257
|
-
label: pathSegmentToLabel(entry),
|
|
5258
|
-
slug: getSlug(fullPath, rootDir)
|
|
5259
|
-
});
|
|
5260
|
-
}
|
|
5261
|
-
}
|
|
5262
|
-
items.push(
|
|
5263
|
-
...flattenIndexFilesAtDepth(fullPath, rootDir, dirnameDeterminesLabels)
|
|
5264
|
-
);
|
|
5265
|
-
}
|
|
5266
|
-
} catch {
|
|
5118
|
+
return {};
|
|
5267
5119
|
}
|
|
5268
|
-
return items;
|
|
5269
|
-
}
|
|
5270
|
-
function getIndexMdSidebarItems(directory, options = {}) {
|
|
5271
|
-
const maxDepth = options.maxDepthNesting ?? 100;
|
|
5272
|
-
const dirnameDeterminesLabels = options.dirnameDeterminesLabels ?? true;
|
|
5273
|
-
const rootDirName = pathSegmentToLabel(path2.basename(directory));
|
|
5274
|
-
const items = buildSidebarItems(
|
|
5275
|
-
directory,
|
|
5276
|
-
directory,
|
|
5277
|
-
0,
|
|
5278
|
-
maxDepth,
|
|
5279
|
-
dirnameDeterminesLabels
|
|
5280
|
-
);
|
|
5281
|
-
return [
|
|
5282
|
-
{
|
|
5283
|
-
label: rootDirName,
|
|
5284
|
-
items
|
|
5285
|
-
}
|
|
5286
|
-
];
|
|
5287
5120
|
}
|
|
5288
5121
|
|
|
5289
5122
|
export {
|
|
5290
|
-
parseFrontmatter2 as parseFrontmatter
|
|
5291
|
-
getIndexMdSidebarItems
|
|
5123
|
+
parseFrontmatter2 as parseFrontmatter
|
|
5292
5124
|
};
|
|
5293
5125
|
/*! Bundled license information:
|
|
5294
5126
|
|
|
@@ -0,0 +1,238 @@
|
|
|
1
|
+
import {
|
|
2
|
+
parseFrontmatter
|
|
3
|
+
} from "./chunk-IY4A67ZP.js";
|
|
4
|
+
|
|
5
|
+
// src/plugins/starlight-index-only-sidebar/index.ts
|
|
6
|
+
import { join as join2 } from "path";
|
|
7
|
+
|
|
8
|
+
// src/plugins/starlight-index-only-sidebar/utils.ts
|
|
9
|
+
import * as fs from "fs";
|
|
10
|
+
import * as path from "path";
|
|
11
|
+
function isDir(filePath) {
|
|
12
|
+
try {
|
|
13
|
+
return fs.statSync(filePath).isDirectory();
|
|
14
|
+
} catch {
|
|
15
|
+
return false;
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
function findIndexMd(dirPath) {
|
|
19
|
+
const indexMd = path.join(dirPath, "index.md");
|
|
20
|
+
const indexMdx = path.join(dirPath, "index.mdx");
|
|
21
|
+
try {
|
|
22
|
+
if (fs.statSync(indexMd).isFile()) return indexMd;
|
|
23
|
+
if (fs.statSync(indexMdx).isFile()) return indexMdx;
|
|
24
|
+
} catch {
|
|
25
|
+
}
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
function getSlug(dirPath, rootDir) {
|
|
29
|
+
const normalized = path.normalize(dirPath).replace(/\\/g, "/");
|
|
30
|
+
const rootParent = path.normalize(path.dirname(rootDir)).replace(/\\/g, "/");
|
|
31
|
+
const slug = normalized.startsWith(rootParent) ? normalized.slice(rootParent.length + 1) : normalized;
|
|
32
|
+
return slug + "/index";
|
|
33
|
+
}
|
|
34
|
+
function hasIndexMdInSubtree(dirPath) {
|
|
35
|
+
const indexFile = findIndexMd(dirPath);
|
|
36
|
+
if (indexFile) {
|
|
37
|
+
const fm = parseFrontmatter(indexFile);
|
|
38
|
+
if (fm.draft || fm.sidebar?.hidden) return false;
|
|
39
|
+
return true;
|
|
40
|
+
}
|
|
41
|
+
try {
|
|
42
|
+
const entries = fs.readdirSync(dirPath);
|
|
43
|
+
for (const entry of entries) {
|
|
44
|
+
if (entry === "assets") continue;
|
|
45
|
+
const fullPath = path.join(dirPath, entry);
|
|
46
|
+
if (isDir(fullPath) && hasIndexMdInSubtree(fullPath)) {
|
|
47
|
+
return true;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
} catch {
|
|
51
|
+
return false;
|
|
52
|
+
}
|
|
53
|
+
return false;
|
|
54
|
+
}
|
|
55
|
+
function isGroupItem(item) {
|
|
56
|
+
return "items" in item;
|
|
57
|
+
}
|
|
58
|
+
function pathSegmentToLabel(pathSegment) {
|
|
59
|
+
let label = pathSegment.split("-").map((word) => word.charAt(0).toUpperCase() + word.slice(1)).join(" ");
|
|
60
|
+
const match = label.match(/^([a-z]+) [0-9]{2,}/i);
|
|
61
|
+
if (match) {
|
|
62
|
+
const firstGroup = match[1];
|
|
63
|
+
const uppercasedFirstGroup = firstGroup.toUpperCase();
|
|
64
|
+
label = uppercasedFirstGroup + label.substring(firstGroup.length);
|
|
65
|
+
}
|
|
66
|
+
return label;
|
|
67
|
+
}
|
|
68
|
+
function buildSidebarItems(dirPath, rootDir, currentDepth, maxDepth, dirnameDeterminesLabels, parentDirName = "") {
|
|
69
|
+
const items = [];
|
|
70
|
+
const indexFile = findIndexMd(dirPath);
|
|
71
|
+
if (indexFile) {
|
|
72
|
+
const fm = parseFrontmatter(indexFile);
|
|
73
|
+
if (!fm.draft && !fm.sidebar?.hidden) {
|
|
74
|
+
let label;
|
|
75
|
+
if (currentDepth >= maxDepth && parentDirName) {
|
|
76
|
+
label = parentDirName;
|
|
77
|
+
} else if (dirnameDeterminesLabels) {
|
|
78
|
+
label = "Overview";
|
|
79
|
+
} else {
|
|
80
|
+
label = fm.title || "Overview";
|
|
81
|
+
}
|
|
82
|
+
items.push({
|
|
83
|
+
label,
|
|
84
|
+
slug: getSlug(dirPath, rootDir)
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
if (currentDepth >= maxDepth) {
|
|
89
|
+
const flattenedItems = flattenIndexFilesAtDepth(
|
|
90
|
+
dirPath,
|
|
91
|
+
rootDir,
|
|
92
|
+
dirnameDeterminesLabels
|
|
93
|
+
);
|
|
94
|
+
items.push(...flattenedItems);
|
|
95
|
+
return items;
|
|
96
|
+
}
|
|
97
|
+
try {
|
|
98
|
+
const entries = fs.readdirSync(dirPath).sort();
|
|
99
|
+
for (const entry of entries) {
|
|
100
|
+
if (entry === "assets") continue;
|
|
101
|
+
const fullPath = path.join(dirPath, entry);
|
|
102
|
+
if (!isDir(fullPath)) continue;
|
|
103
|
+
if (!hasIndexMdInSubtree(fullPath)) continue;
|
|
104
|
+
const subItems = buildSidebarItems(
|
|
105
|
+
fullPath,
|
|
106
|
+
rootDir,
|
|
107
|
+
currentDepth + 1,
|
|
108
|
+
maxDepth,
|
|
109
|
+
dirnameDeterminesLabels,
|
|
110
|
+
entry
|
|
111
|
+
);
|
|
112
|
+
const hasIndex = findIndexMd(fullPath) !== null;
|
|
113
|
+
if (!hasIndex) {
|
|
114
|
+
const allGroups = subItems.length > 0 && subItems.every(isGroupItem);
|
|
115
|
+
if (allGroups || subItems.length === 1 && isGroupItem(subItems[0])) {
|
|
116
|
+
items.push(...subItems);
|
|
117
|
+
} else {
|
|
118
|
+
items.push({
|
|
119
|
+
label: pathSegmentToLabel(entry),
|
|
120
|
+
items: subItems
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
} else {
|
|
124
|
+
items.push({
|
|
125
|
+
label: pathSegmentToLabel(entry),
|
|
126
|
+
items: subItems
|
|
127
|
+
});
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
} catch {
|
|
131
|
+
}
|
|
132
|
+
return items;
|
|
133
|
+
}
|
|
134
|
+
function flattenIndexFilesAtDepth(dirPath, rootDir, dirnameDeterminesLabels) {
|
|
135
|
+
const items = [];
|
|
136
|
+
try {
|
|
137
|
+
const entries = fs.readdirSync(dirPath);
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
if (entry === "assets") continue;
|
|
140
|
+
const fullPath = path.join(dirPath, entry);
|
|
141
|
+
if (!isDir(fullPath)) continue;
|
|
142
|
+
const indexFile = findIndexMd(fullPath);
|
|
143
|
+
if (indexFile) {
|
|
144
|
+
const fm = parseFrontmatter(indexFile);
|
|
145
|
+
if (!fm.draft && !fm.sidebar?.hidden) {
|
|
146
|
+
items.push({
|
|
147
|
+
label: pathSegmentToLabel(entry),
|
|
148
|
+
slug: getSlug(fullPath, rootDir)
|
|
149
|
+
});
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
items.push(
|
|
153
|
+
...flattenIndexFilesAtDepth(fullPath, rootDir, dirnameDeterminesLabels)
|
|
154
|
+
);
|
|
155
|
+
}
|
|
156
|
+
} catch {
|
|
157
|
+
}
|
|
158
|
+
return items;
|
|
159
|
+
}
|
|
160
|
+
function getIndexMdSidebarItems(directory, options = {}) {
|
|
161
|
+
const maxDepth = options.maxDepthNesting ?? 100;
|
|
162
|
+
const dirnameDeterminesLabels = options.dirnameDeterminesLabels ?? true;
|
|
163
|
+
const rootDirName = pathSegmentToLabel(path.basename(directory));
|
|
164
|
+
const items = buildSidebarItems(
|
|
165
|
+
directory,
|
|
166
|
+
directory,
|
|
167
|
+
0,
|
|
168
|
+
maxDepth,
|
|
169
|
+
dirnameDeterminesLabels
|
|
170
|
+
);
|
|
171
|
+
return [
|
|
172
|
+
{
|
|
173
|
+
label: rootDirName,
|
|
174
|
+
items
|
|
175
|
+
}
|
|
176
|
+
];
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// src/plugins/starlight-index-only-sidebar/index.ts
|
|
180
|
+
var SITE_DOCS_ROOT = "./src/content/docs";
|
|
181
|
+
function normalizeSlug(slug) {
|
|
182
|
+
return slug.endsWith("/index") ? slug.slice(0, -6) : slug;
|
|
183
|
+
}
|
|
184
|
+
function normalizeItems(items) {
|
|
185
|
+
return items.map((item) => {
|
|
186
|
+
if ("items" in item) {
|
|
187
|
+
return {
|
|
188
|
+
label: item.label,
|
|
189
|
+
items: normalizeItems(item.items)
|
|
190
|
+
};
|
|
191
|
+
}
|
|
192
|
+
if ("slug" in item) {
|
|
193
|
+
return {
|
|
194
|
+
label: item.label,
|
|
195
|
+
slug: normalizeSlug(item.slug)
|
|
196
|
+
};
|
|
197
|
+
}
|
|
198
|
+
return item;
|
|
199
|
+
});
|
|
200
|
+
}
|
|
201
|
+
function starlightIndexOnlySidebar(pluginOptions) {
|
|
202
|
+
return {
|
|
203
|
+
name: "index-only-sidebar",
|
|
204
|
+
hooks: {
|
|
205
|
+
"config:setup": (hookOptions) => {
|
|
206
|
+
const { updateConfig } = hookOptions;
|
|
207
|
+
const { directories, maxDepthNesting, dirnameDeterminesLabels } = pluginOptions;
|
|
208
|
+
const functionOptions = {
|
|
209
|
+
maxDepthNesting,
|
|
210
|
+
dirnameDeterminesLabels
|
|
211
|
+
};
|
|
212
|
+
const sidebarItems = directories.map((directory) => {
|
|
213
|
+
const dirPath = join2(SITE_DOCS_ROOT, directory);
|
|
214
|
+
const rawItems = getIndexMdSidebarItems(dirPath, functionOptions);
|
|
215
|
+
const rootGroup = rawItems[0];
|
|
216
|
+
if (!rootGroup || !("items" in rootGroup)) {
|
|
217
|
+
return void 0;
|
|
218
|
+
}
|
|
219
|
+
const items = rootGroup.items || [];
|
|
220
|
+
const normalizedItems = normalizeItems(items);
|
|
221
|
+
return {
|
|
222
|
+
label: rootGroup.label,
|
|
223
|
+
items: normalizedItems
|
|
224
|
+
};
|
|
225
|
+
}).filter(
|
|
226
|
+
(group) => group !== void 0 && group.items.length > 0
|
|
227
|
+
);
|
|
228
|
+
updateConfig({
|
|
229
|
+
sidebar: sidebarItems
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export {
|
|
237
|
+
starlightIndexOnlySidebar
|
|
238
|
+
};
|
|
@@ -1,6 +1,10 @@
|
|
|
1
|
+
// src/plugins/astro-latex-compile/index.ts
|
|
2
|
+
import { rm } from "fs/promises";
|
|
3
|
+
import { join as join2, resolve } from "path";
|
|
4
|
+
import { visit, SKIP } from "unist-util-visit";
|
|
5
|
+
|
|
1
6
|
// src/plugins/astro-latex-compile/utils.ts
|
|
2
7
|
import { createHash } from "crypto";
|
|
3
|
-
import { spawn } from "child_process";
|
|
4
8
|
import {
|
|
5
9
|
existsSync,
|
|
6
10
|
mkdirSync,
|
|
@@ -161,8 +165,29 @@ ${formattedSource}
|
|
|
161
165
|
`;
|
|
162
166
|
}
|
|
163
167
|
|
|
168
|
+
// src/plugins/utils/process-utils.ts
|
|
169
|
+
import { spawn } from "child_process";
|
|
170
|
+
function execProcess(command, args) {
|
|
171
|
+
return new Promise((resolve2, reject) => {
|
|
172
|
+
let stdout = "";
|
|
173
|
+
let stderr = "";
|
|
174
|
+
const proc = spawn(command, args);
|
|
175
|
+
proc.stdout.on("data", (data) => {
|
|
176
|
+
stdout += data.toString();
|
|
177
|
+
});
|
|
178
|
+
proc.stderr.on("data", (data) => {
|
|
179
|
+
stderr += data.toString();
|
|
180
|
+
});
|
|
181
|
+
proc.on("error", (err) => {
|
|
182
|
+
reject(err);
|
|
183
|
+
});
|
|
184
|
+
proc.on("close", (code) => {
|
|
185
|
+
resolve2({ status: code ?? 1, stdout, stderr });
|
|
186
|
+
});
|
|
187
|
+
});
|
|
188
|
+
}
|
|
189
|
+
|
|
164
190
|
// src/plugins/astro-latex-compile/utils.ts
|
|
165
|
-
var LATEX_BLOCK_REGEX = /```(?:tex|latex)\s+compile[^\r\n]*\r?\n([\s\S]*?)\r?\n```/g;
|
|
166
191
|
function hashLatexCode(code) {
|
|
167
192
|
const normalized = code.split("\n").map((line) => line.trim()).filter((line) => !line.startsWith("%")).filter(Boolean).join("\n").trim();
|
|
168
193
|
return createHash("md5").update(normalized).digest("hex").slice(0, 16);
|
|
@@ -188,25 +213,6 @@ function buildLatexSource(latexCode) {
|
|
|
188
213
|
"\\end{document}"
|
|
189
214
|
].join("\n");
|
|
190
215
|
}
|
|
191
|
-
function execProcess(command, args) {
|
|
192
|
-
return new Promise((resolve, reject) => {
|
|
193
|
-
let stdout = "";
|
|
194
|
-
let stderr = "";
|
|
195
|
-
const proc = spawn(command, args);
|
|
196
|
-
proc.stdout.on("data", (data) => {
|
|
197
|
-
stdout += data.toString();
|
|
198
|
-
});
|
|
199
|
-
proc.stderr.on("data", (data) => {
|
|
200
|
-
stderr += data.toString();
|
|
201
|
-
});
|
|
202
|
-
proc.on("error", (err) => {
|
|
203
|
-
reject(err);
|
|
204
|
-
});
|
|
205
|
-
proc.on("close", (code) => {
|
|
206
|
-
resolve({ status: code ?? 1, stdout, stderr });
|
|
207
|
-
});
|
|
208
|
-
});
|
|
209
|
-
}
|
|
210
216
|
async function compileLatexToSvg(latexCode, svgOutputDir) {
|
|
211
217
|
const hash = hashLatexCode(latexCode);
|
|
212
218
|
const svgPath = join(svgOutputDir, `${hash}.svg`);
|
|
@@ -275,8 +281,91 @@ Error: ${errorOutput}`
|
|
|
275
281
|
return { hash, svgPath, wasCompiled: true };
|
|
276
282
|
}
|
|
277
283
|
|
|
284
|
+
// src/plugins/astro-latex-compile/index.ts
|
|
285
|
+
function extractClassesFromMeta(meta) {
|
|
286
|
+
const classMatch = meta.match(/class="([^"]+)"/);
|
|
287
|
+
if (classMatch?.[1]) {
|
|
288
|
+
return classMatch[1].split(/\s+/).filter(Boolean);
|
|
289
|
+
}
|
|
290
|
+
return [];
|
|
291
|
+
}
|
|
292
|
+
function remarkLatexCompile(options) {
|
|
293
|
+
const svgOutputDir = resolve(options.svgOutputDir);
|
|
294
|
+
return async function transformer(tree, file) {
|
|
295
|
+
const nodes = [];
|
|
296
|
+
visit(tree, "code", (node, index, parent) => {
|
|
297
|
+
if ((node.lang === "tex" || node.lang === "latex") && node.meta?.includes("compile") && parent && index !== void 0) {
|
|
298
|
+
nodes.push({ node, index, parent });
|
|
299
|
+
}
|
|
300
|
+
return SKIP;
|
|
301
|
+
});
|
|
302
|
+
if (nodes.length === 0) return;
|
|
303
|
+
const filePath = file.path || "unknown";
|
|
304
|
+
const results = await Promise.all(
|
|
305
|
+
nodes.map(async ({ node, index, parent }) => {
|
|
306
|
+
const lineNumber = node.position?.start.line ?? "?";
|
|
307
|
+
try {
|
|
308
|
+
const result = await compileLatexToSvg(node.value, svgOutputDir);
|
|
309
|
+
if (result.wasCompiled) {
|
|
310
|
+
console.log(
|
|
311
|
+
`[remark-latex-compile] ${filePath}:${lineNumber}: compiled ${result.hash}.svg`
|
|
312
|
+
);
|
|
313
|
+
}
|
|
314
|
+
options._referencedHashes?.add(result.hash);
|
|
315
|
+
return { index, parent, result, error: null, hash: result.hash };
|
|
316
|
+
} catch (err) {
|
|
317
|
+
const errorMsg = err instanceof Error ? err.message : String(err);
|
|
318
|
+
const match = errorMsg.match(/\n\n([\s\S]+)/);
|
|
319
|
+
const details = match ? match[1] : errorMsg;
|
|
320
|
+
console.error(
|
|
321
|
+
`[remark-latex-compile] ${filePath}:${lineNumber}
|
|
322
|
+
${details}`
|
|
323
|
+
);
|
|
324
|
+
return { index, parent, result: null, error: err, hash: null };
|
|
325
|
+
}
|
|
326
|
+
})
|
|
327
|
+
);
|
|
328
|
+
if (options._fileHashMap) {
|
|
329
|
+
const newHashes = new Set(
|
|
330
|
+
results.map((r) => r.hash).filter(Boolean)
|
|
331
|
+
);
|
|
332
|
+
const oldHashes = options._fileHashMap.get(filePath) ?? /* @__PURE__ */ new Set();
|
|
333
|
+
const staleHashes = [...oldHashes].filter((h) => !newHashes.has(h));
|
|
334
|
+
for (const staleHash of staleHashes) {
|
|
335
|
+
console.warn(
|
|
336
|
+
`[remark-latex-compile] Removing orphaned svg: ${staleHash}.svg`
|
|
337
|
+
);
|
|
338
|
+
}
|
|
339
|
+
await Promise.all(
|
|
340
|
+
staleHashes.map(
|
|
341
|
+
(h) => rm(join2(svgOutputDir, `${h}.svg`), { force: true })
|
|
342
|
+
)
|
|
343
|
+
);
|
|
344
|
+
options._fileHashMap.set(filePath, newHashes);
|
|
345
|
+
}
|
|
346
|
+
for (let i = results.length - 1; i >= 0; i--) {
|
|
347
|
+
const { index, parent, result } = results[i];
|
|
348
|
+
const { node } = nodes[i];
|
|
349
|
+
if (!result) continue;
|
|
350
|
+
const customClasses = extractClassesFromMeta(node.meta ?? "");
|
|
351
|
+
const imageNode = {
|
|
352
|
+
type: "image",
|
|
353
|
+
url: `/static/tex-svgs/${result.hash}.svg`,
|
|
354
|
+
alt: "LaTeX diagram",
|
|
355
|
+
data: {
|
|
356
|
+
hProperties: { className: ["tex-compiled", ...customClasses] }
|
|
357
|
+
}
|
|
358
|
+
};
|
|
359
|
+
const paragraph = {
|
|
360
|
+
type: "paragraph",
|
|
361
|
+
children: [imageNode]
|
|
362
|
+
};
|
|
363
|
+
parent.children.splice(index, 1, paragraph);
|
|
364
|
+
}
|
|
365
|
+
};
|
|
366
|
+
}
|
|
367
|
+
|
|
278
368
|
export {
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
compileLatexToSvg
|
|
369
|
+
compileLatexToSvg,
|
|
370
|
+
remarkLatexCompile
|
|
282
371
|
};
|
package/dist/cpp-VZKLUKT7.js
CHANGED
|
@@ -3,8 +3,8 @@ import {
|
|
|
3
3
|
} from "./chunk-ICUS267J.js";
|
|
4
4
|
import "./chunk-MT4FGOLU.js";
|
|
5
5
|
import "./chunk-YJV35WLF.js";
|
|
6
|
-
import "./chunk-IWM27JZF.js";
|
|
7
6
|
import "./chunk-XOMTOLBK.js";
|
|
7
|
+
import "./chunk-IWM27JZF.js";
|
|
8
8
|
import "./chunk-QGM4M3NI.js";
|
|
9
9
|
export {
|
|
10
10
|
cpp_default as default
|
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ruby_default
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-7DJE5LRN.js";
|
|
4
4
|
import "./chunk-ZSX4GOHC.js";
|
|
5
|
-
import "./chunk-NE25QJUZ.js";
|
|
6
5
|
import "./chunk-OII47WE4.js";
|
|
7
6
|
import "./chunk-76C5RMV7.js";
|
|
8
7
|
import "./chunk-S3SFQXYS.js";
|
|
8
|
+
import "./chunk-NE25QJUZ.js";
|
|
9
9
|
import "./chunk-ICUS267J.js";
|
|
10
10
|
import "./chunk-MT4FGOLU.js";
|
|
11
11
|
import "./chunk-YJV35WLF.js";
|
|
12
12
|
import "./chunk-5TDK5Y5S.js";
|
|
13
|
-
import "./chunk-IWM27JZF.js";
|
|
14
13
|
import "./chunk-XOMTOLBK.js";
|
|
14
|
+
import "./chunk-IWM27JZF.js";
|
|
15
15
|
import "./chunk-VB3O6QM4.js";
|
|
16
16
|
import "./chunk-QFOAKHDY.js";
|
|
17
17
|
import "./chunk-AZIN3OHL.js";
|
package/dist/index.d.ts
CHANGED
|
@@ -3,7 +3,7 @@ export { SyncDocsToPublicOptions, syncDocsToPublic } from './plugins/astro-sync-
|
|
|
3
3
|
export { default as rehypeValidateLinks } from './plugins/rehype-validate-links.js';
|
|
4
4
|
export { astroNormalizePaths } from './plugins/astro-normalize-paths.js';
|
|
5
5
|
import { RemarkLatexCompileOptions } from './plugins/astro-latex-compile.js';
|
|
6
|
-
export {
|
|
6
|
+
export { default as remarkLatexCompile } from './plugins/astro-latex-compile.js';
|
|
7
7
|
import { AstroIntegration } from 'astro';
|
|
8
8
|
import '@astrojs/starlight/types';
|
|
9
9
|
import 'hast';
|
package/dist/index.js
CHANGED
|
@@ -1,21 +1,19 @@
|
|
|
1
1
|
import {
|
|
2
2
|
starlightIndexOnlySidebar
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-N2I2GJW3.js";
|
|
4
4
|
import {
|
|
5
5
|
rehypeValidateLinks
|
|
6
6
|
} from "./chunk-FQLJMU2J.js";
|
|
7
7
|
import {
|
|
8
|
-
rehypeLatexCompile,
|
|
9
8
|
remarkLatexCompile
|
|
10
|
-
} from "./chunk-
|
|
9
|
+
} from "./chunk-XVMRLEQM.js";
|
|
11
10
|
import {
|
|
12
11
|
astroNormalizePaths
|
|
13
12
|
} from "./chunk-AZPHBHBE.js";
|
|
14
13
|
import {
|
|
15
14
|
syncDocsToPublic
|
|
16
|
-
} from "./chunk-
|
|
17
|
-
import "./chunk-
|
|
18
|
-
import "./chunk-TTQY54Q6.js";
|
|
15
|
+
} from "./chunk-WZNJ5VFU.js";
|
|
16
|
+
import "./chunk-IY4A67ZP.js";
|
|
19
17
|
import "./chunk-QGM4M3NI.js";
|
|
20
18
|
|
|
21
19
|
// src/plugins/astro-latex-compile/astro-integration.ts
|
|
@@ -82,7 +80,6 @@ function astroLatexCompile(options) {
|
|
|
82
80
|
export {
|
|
83
81
|
astroLatexCompile,
|
|
84
82
|
astroNormalizePaths,
|
|
85
|
-
rehypeLatexCompile,
|
|
86
83
|
rehypeValidateLinks,
|
|
87
84
|
remarkLatexCompile,
|
|
88
85
|
starlightIndexOnlySidebar,
|