@ox-content/vite-plugin 2.10.0 → 2.11.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/github.cjs +381 -10
- package/dist/github.cjs.map +1 -1
- package/dist/github.mjs +352 -11
- package/dist/github.mjs.map +1 -1
- package/dist/index.cjs +164 -76
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +251 -167
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +251 -167
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +156 -78
- package/dist/index.mjs.map +1 -1
- package/package.json +2 -2
package/dist/github.mjs
CHANGED
|
@@ -2,30 +2,130 @@ import { c as __exportAll } from "./mermaid.mjs";
|
|
|
2
2
|
import { unified } from "unified";
|
|
3
3
|
import rehypeParse from "rehype-parse";
|
|
4
4
|
import rehypeStringify from "rehype-stringify";
|
|
5
|
+
import { Buffer } from "node:buffer";
|
|
5
6
|
//#region src/plugins/github.ts
|
|
6
7
|
/**
|
|
7
|
-
* GitHub Plugin - Repository
|
|
8
|
+
* GitHub Plugin - Repository and source code embedding
|
|
8
9
|
*
|
|
9
|
-
* Transforms <GitHub> components into static repository cards
|
|
10
|
+
* Transforms <GitHub> components into static repository and source code cards
|
|
10
11
|
* by fetching data from GitHub API at build time.
|
|
11
12
|
*/
|
|
12
13
|
var github_exports = /* @__PURE__ */ __exportAll({
|
|
13
14
|
collectGitHubRepos: () => collectGitHubRepos,
|
|
15
|
+
collectGitHubSources: () => collectGitHubSources,
|
|
16
|
+
createGitHubPermalink: () => createGitHubPermalink,
|
|
17
|
+
fetchGitHubSource: () => fetchGitHubSource,
|
|
14
18
|
fetchRepoData: () => fetchRepoData,
|
|
15
19
|
isSafeGitHubRepo: () => isSafeGitHubRepo,
|
|
20
|
+
parseGitHubLineRange: () => parseGitHubLineRange,
|
|
21
|
+
parseGitHubPermalink: () => parseGitHubPermalink,
|
|
16
22
|
prefetchGitHubRepos: () => prefetchGitHubRepos,
|
|
23
|
+
prefetchGitHubSources: () => prefetchGitHubSources,
|
|
17
24
|
transformGitHub: () => transformGitHub
|
|
18
25
|
});
|
|
19
26
|
const defaultOptions = {
|
|
20
27
|
token: "",
|
|
21
28
|
cache: true,
|
|
22
|
-
cacheTTL: 36e5
|
|
29
|
+
cacheTTL: 36e5,
|
|
30
|
+
maxSourceBytes: 2e5,
|
|
31
|
+
maxSourceLines: 120
|
|
23
32
|
};
|
|
24
33
|
const repoCache = /* @__PURE__ */ new Map();
|
|
34
|
+
const sourceCache = /* @__PURE__ */ new Map();
|
|
25
35
|
const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
36
|
+
const GITHUB_COMPONENT_RE = /<github\b([^>]*)>/gi;
|
|
37
|
+
const ATTRIBUTE_RE = /([:\w-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;
|
|
38
|
+
const CONTROL_CHAR_RE = /[\u0000-\u001f\u007f]/;
|
|
39
|
+
const EXTENSION_LANGUAGE_MAP = new Map([
|
|
40
|
+
["cjs", "javascript"],
|
|
41
|
+
["css", "css"],
|
|
42
|
+
["go", "go"],
|
|
43
|
+
["html", "html"],
|
|
44
|
+
["js", "javascript"],
|
|
45
|
+
["json", "json"],
|
|
46
|
+
["jsx", "jsx"],
|
|
47
|
+
["md", "markdown"],
|
|
48
|
+
["mdx", "mdx"],
|
|
49
|
+
["mjs", "javascript"],
|
|
50
|
+
["py", "python"],
|
|
51
|
+
["rb", "ruby"],
|
|
52
|
+
["rs", "rust"],
|
|
53
|
+
["sh", "shell"],
|
|
54
|
+
["svelte", "svelte"],
|
|
55
|
+
["toml", "toml"],
|
|
56
|
+
["ts", "typescript"],
|
|
57
|
+
["tsx", "tsx"],
|
|
58
|
+
["vue", "vue"],
|
|
59
|
+
["yaml", "yaml"],
|
|
60
|
+
["yml", "yaml"]
|
|
61
|
+
]);
|
|
26
62
|
function isSafeGitHubRepo(repo) {
|
|
27
63
|
return GITHUB_REPO_RE.test(repo) && !repo.split("/").some((part) => part === "." || part === "..");
|
|
28
64
|
}
|
|
65
|
+
function isSafeGitHubRef(ref) {
|
|
66
|
+
return Boolean(ref) && !CONTROL_CHAR_RE.test(ref) && !hasUnsafePathSegment(ref);
|
|
67
|
+
}
|
|
68
|
+
function isSafeGitHubPath(path) {
|
|
69
|
+
return Boolean(path) && !CONTROL_CHAR_RE.test(path) && !hasUnsafePathSegment(path);
|
|
70
|
+
}
|
|
71
|
+
function hasUnsafePathSegment(value) {
|
|
72
|
+
return value.split("/").some((part) => !part || part === "." || part === ".." || part.includes("\\"));
|
|
73
|
+
}
|
|
74
|
+
function encodePath(path) {
|
|
75
|
+
return path.split("/").map(encodeURIComponent).join("/");
|
|
76
|
+
}
|
|
77
|
+
function sourceKey(source) {
|
|
78
|
+
return `${source.repo}@${source.ref}:${source.path}`;
|
|
79
|
+
}
|
|
80
|
+
function formatLineRange(lines) {
|
|
81
|
+
return lines.start === lines.end ? `L${lines.start}` : `L${lines.start}-L${lines.end}`;
|
|
82
|
+
}
|
|
83
|
+
function parseGitHubLineRange(value) {
|
|
84
|
+
if (!value) return void 0;
|
|
85
|
+
const match = value.trim().match(/^#?L?(\d+)(?:-L?(\d+))?$/i);
|
|
86
|
+
if (!match) return void 0;
|
|
87
|
+
const start = Number.parseInt(match[1], 10);
|
|
88
|
+
const end = match[2] ? Number.parseInt(match[2], 10) : start;
|
|
89
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 1 || end < start) return;
|
|
90
|
+
return {
|
|
91
|
+
start,
|
|
92
|
+
end
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
function createGitHubPermalink(source) {
|
|
96
|
+
const fragment = source.lines ? `#${formatLineRange(source.lines)}` : "";
|
|
97
|
+
return `https://github.com/${source.repo}/blob/${encodeURIComponent(source.ref)}/${encodePath(source.path)}${fragment}`;
|
|
98
|
+
}
|
|
99
|
+
function parseGitHubPermalink(value) {
|
|
100
|
+
let url;
|
|
101
|
+
try {
|
|
102
|
+
url = new URL(value);
|
|
103
|
+
} catch {
|
|
104
|
+
return null;
|
|
105
|
+
}
|
|
106
|
+
if (url.protocol !== "https:" || url.hostname !== "github.com") return null;
|
|
107
|
+
let parts;
|
|
108
|
+
try {
|
|
109
|
+
parts = url.pathname.split("/").filter(Boolean).map((part) => decodeURIComponent(part));
|
|
110
|
+
} catch {
|
|
111
|
+
return null;
|
|
112
|
+
}
|
|
113
|
+
if (parts.length < 5 || parts[2] !== "blob") return null;
|
|
114
|
+
const repo = `${parts[0]}/${parts[1]}`;
|
|
115
|
+
const ref = parts[3];
|
|
116
|
+
const path = parts.slice(4).join("/");
|
|
117
|
+
if (!isSafeGitHubRepo(repo) || !isSafeGitHubRef(ref) || !isSafeGitHubPath(path)) return null;
|
|
118
|
+
const source = {
|
|
119
|
+
repo,
|
|
120
|
+
ref,
|
|
121
|
+
path,
|
|
122
|
+
lines: parseGitHubLineRange(url.hash)
|
|
123
|
+
};
|
|
124
|
+
return {
|
|
125
|
+
...source,
|
|
126
|
+
permalink: createGitHubPermalink(source)
|
|
127
|
+
};
|
|
128
|
+
}
|
|
29
129
|
/**
|
|
30
130
|
* Get element attribute value.
|
|
31
131
|
*/
|
|
@@ -74,6 +174,52 @@ async function fetchRepoData(repo, options) {
|
|
|
74
174
|
}
|
|
75
175
|
}
|
|
76
176
|
/**
|
|
177
|
+
* Fetch source file data from GitHub API.
|
|
178
|
+
*/
|
|
179
|
+
async function fetchGitHubSource(source, options) {
|
|
180
|
+
if (!isSafeGitHubRepo(source.repo) || !isSafeGitHubRef(source.ref) || !isSafeGitHubPath(source.path)) return null;
|
|
181
|
+
const key = sourceKey(source);
|
|
182
|
+
if (options.cache) {
|
|
183
|
+
const cached = sourceCache.get(key);
|
|
184
|
+
if (cached && Date.now() - cached.timestamp < options.cacheTTL) return cached.data;
|
|
185
|
+
}
|
|
186
|
+
try {
|
|
187
|
+
const headers = {
|
|
188
|
+
Accept: "application/vnd.github.v3+json",
|
|
189
|
+
"User-Agent": "ox-content-github-plugin"
|
|
190
|
+
};
|
|
191
|
+
if (options.token) headers.Authorization = `Bearer ${options.token}`;
|
|
192
|
+
const apiUrl = `https://api.github.com/repos/${source.repo}/contents/${encodePath(source.path)}?ref=${encodeURIComponent(source.ref)}`;
|
|
193
|
+
const response = await fetch(apiUrl, { headers });
|
|
194
|
+
if (!response.ok) {
|
|
195
|
+
console.warn(`Failed to fetch GitHub source ${source.permalink}: ${response.status}`);
|
|
196
|
+
return null;
|
|
197
|
+
}
|
|
198
|
+
const data = await response.json();
|
|
199
|
+
if (data.type !== "file" || data.encoding !== "base64" || !data.content || (data.size ?? 0) > options.maxSourceBytes) return null;
|
|
200
|
+
const content = Buffer.from(data.content.replace(/\s/g, ""), "base64").toString("utf8");
|
|
201
|
+
if (Buffer.byteLength(content) > options.maxSourceBytes) return null;
|
|
202
|
+
const sourceData = {
|
|
203
|
+
repo: source.repo,
|
|
204
|
+
ref: source.ref,
|
|
205
|
+
path: source.path,
|
|
206
|
+
permalink: source.permalink,
|
|
207
|
+
content,
|
|
208
|
+
size: data.size ?? Buffer.byteLength(content),
|
|
209
|
+
html_url: data.html_url ?? source.permalink,
|
|
210
|
+
language: inferLanguage(source.path)
|
|
211
|
+
};
|
|
212
|
+
if (options.cache) sourceCache.set(key, {
|
|
213
|
+
data: sourceData,
|
|
214
|
+
timestamp: Date.now()
|
|
215
|
+
});
|
|
216
|
+
return sourceData;
|
|
217
|
+
} catch (error) {
|
|
218
|
+
console.warn(`Error fetching GitHub source ${source.permalink}:`, error);
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
/**
|
|
77
223
|
* Create GitHub card element from repo data.
|
|
78
224
|
*/
|
|
79
225
|
function createGitHubCard(repoData) {
|
|
@@ -238,17 +384,184 @@ function createFallbackCard(repo) {
|
|
|
238
384
|
}]
|
|
239
385
|
};
|
|
240
386
|
}
|
|
387
|
+
function inferLanguage(path) {
|
|
388
|
+
const fileName = path.split("/").at(-1)?.toLowerCase() ?? "";
|
|
389
|
+
if (fileName === "dockerfile") return "dockerfile";
|
|
390
|
+
if (fileName === "makefile") return "makefile";
|
|
391
|
+
const extension = fileName.includes(".") ? fileName.split(".").at(-1) : void 0;
|
|
392
|
+
return extension ? EXTENSION_LANGUAGE_MAP.get(extension) ?? extension : null;
|
|
393
|
+
}
|
|
394
|
+
function normalizeSourceLines(content) {
|
|
395
|
+
const lines = content.replace(/\r\n?/g, "\n").split("\n");
|
|
396
|
+
if (lines.length > 1 && lines.at(-1) === "") lines.pop();
|
|
397
|
+
return lines.length > 0 ? lines : [""];
|
|
398
|
+
}
|
|
399
|
+
function createGitHubSourceCard(source, lines, options) {
|
|
400
|
+
const allLines = normalizeSourceLines(source.content);
|
|
401
|
+
const start = Math.min(lines?.start ?? 1, allLines.length);
|
|
402
|
+
const end = lines ? Math.min(lines.end, allLines.length) : Math.min(allLines.length, options.maxSourceLines);
|
|
403
|
+
const selectedLines = allLines.slice(start - 1, end);
|
|
404
|
+
const lineRange = {
|
|
405
|
+
start,
|
|
406
|
+
end
|
|
407
|
+
};
|
|
408
|
+
const loc = selectedLines.length;
|
|
409
|
+
const rangeLabel = formatLineRange(lineRange);
|
|
410
|
+
const locLabel = !lines && end < allLines.length ? `${rangeLabel} of ${allLines.length} LOC` : `${rangeLabel} - ${loc} LOC`;
|
|
411
|
+
const languageClass = source.language ? [`language-${source.language}`] : [];
|
|
412
|
+
return {
|
|
413
|
+
type: "element",
|
|
414
|
+
tagName: "figure",
|
|
415
|
+
properties: {
|
|
416
|
+
className: ["ox-github-code"],
|
|
417
|
+
"data-loc": String(loc),
|
|
418
|
+
"data-source": source.permalink
|
|
419
|
+
},
|
|
420
|
+
children: [{
|
|
421
|
+
type: "element",
|
|
422
|
+
tagName: "figcaption",
|
|
423
|
+
properties: { className: ["ox-github-code-header"] },
|
|
424
|
+
children: [{
|
|
425
|
+
type: "element",
|
|
426
|
+
tagName: "a",
|
|
427
|
+
properties: {
|
|
428
|
+
className: ["ox-github-code-title"],
|
|
429
|
+
href: source.permalink,
|
|
430
|
+
target: "_blank",
|
|
431
|
+
rel: "noopener noreferrer"
|
|
432
|
+
},
|
|
433
|
+
children: [{
|
|
434
|
+
type: "text",
|
|
435
|
+
value: `${source.repo}/${source.path}`
|
|
436
|
+
}]
|
|
437
|
+
}, {
|
|
438
|
+
type: "element",
|
|
439
|
+
tagName: "span",
|
|
440
|
+
properties: { className: ["ox-github-code-loc"] },
|
|
441
|
+
children: [{
|
|
442
|
+
type: "text",
|
|
443
|
+
value: locLabel
|
|
444
|
+
}]
|
|
445
|
+
}]
|
|
446
|
+
}, {
|
|
447
|
+
type: "element",
|
|
448
|
+
tagName: "pre",
|
|
449
|
+
properties: {
|
|
450
|
+
className: ["ox-github-code-block", ...languageClass],
|
|
451
|
+
...source.language ? { "data-language": source.language } : {}
|
|
452
|
+
},
|
|
453
|
+
children: [{
|
|
454
|
+
type: "element",
|
|
455
|
+
tagName: "code",
|
|
456
|
+
properties: { className: languageClass },
|
|
457
|
+
children: selectedLines.map((line, index) => {
|
|
458
|
+
const lineNumber = start + index;
|
|
459
|
+
return {
|
|
460
|
+
type: "element",
|
|
461
|
+
tagName: "span",
|
|
462
|
+
properties: {
|
|
463
|
+
className: ["line", "ox-github-code-line"],
|
|
464
|
+
"data-line": String(lineNumber)
|
|
465
|
+
},
|
|
466
|
+
children: [{
|
|
467
|
+
type: "element",
|
|
468
|
+
tagName: "span",
|
|
469
|
+
properties: { className: ["ox-github-code-line-number"] },
|
|
470
|
+
children: [{
|
|
471
|
+
type: "text",
|
|
472
|
+
value: String(lineNumber)
|
|
473
|
+
}]
|
|
474
|
+
}, {
|
|
475
|
+
type: "element",
|
|
476
|
+
tagName: "span",
|
|
477
|
+
properties: { className: ["ox-github-code-line-content"] },
|
|
478
|
+
children: [{
|
|
479
|
+
type: "text",
|
|
480
|
+
value: line || " "
|
|
481
|
+
}]
|
|
482
|
+
}]
|
|
483
|
+
};
|
|
484
|
+
})
|
|
485
|
+
}]
|
|
486
|
+
}]
|
|
487
|
+
};
|
|
488
|
+
}
|
|
241
489
|
/**
|
|
242
490
|
* Collect all GitHub repos from HTML for pre-fetching.
|
|
243
491
|
*/
|
|
244
492
|
async function collectGitHubRepos(html) {
|
|
245
493
|
const repos = [];
|
|
246
|
-
|
|
494
|
+
GITHUB_COMPONENT_RE.lastIndex = 0;
|
|
247
495
|
let match;
|
|
248
|
-
while ((match =
|
|
496
|
+
while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {
|
|
497
|
+
const attrs = parseAttributes(match[1]);
|
|
498
|
+
if (attrs.path || attrs.file || attrs.permalink || attrs.url || attrs.href) continue;
|
|
499
|
+
const repo = attrs.repo;
|
|
500
|
+
if (repo && isSafeGitHubRepo(repo)) repos.push(repo);
|
|
501
|
+
}
|
|
249
502
|
return repos;
|
|
250
503
|
}
|
|
251
504
|
/**
|
|
505
|
+
* Collect all GitHub source references from HTML for pre-fetching.
|
|
506
|
+
*/
|
|
507
|
+
async function collectGitHubSources(html) {
|
|
508
|
+
const sources = [];
|
|
509
|
+
GITHUB_COMPONENT_RE.lastIndex = 0;
|
|
510
|
+
let match;
|
|
511
|
+
while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {
|
|
512
|
+
const source = sourceRefFromAttributes(parseAttributes(match[1]));
|
|
513
|
+
if (source) sources.push(source);
|
|
514
|
+
}
|
|
515
|
+
return sources;
|
|
516
|
+
}
|
|
517
|
+
function parseAttributes(raw) {
|
|
518
|
+
const attrs = {};
|
|
519
|
+
ATTRIBUTE_RE.lastIndex = 0;
|
|
520
|
+
let match;
|
|
521
|
+
while ((match = ATTRIBUTE_RE.exec(raw)) !== null) attrs[match[1].toLowerCase()] = match[2] ?? match[3] ?? match[4] ?? "";
|
|
522
|
+
return attrs;
|
|
523
|
+
}
|
|
524
|
+
function attributesFromElement(el) {
|
|
525
|
+
const attrs = {};
|
|
526
|
+
for (const name of [
|
|
527
|
+
"permalink",
|
|
528
|
+
"url",
|
|
529
|
+
"href",
|
|
530
|
+
"repo",
|
|
531
|
+
"path",
|
|
532
|
+
"file",
|
|
533
|
+
"ref",
|
|
534
|
+
"sha",
|
|
535
|
+
"branch",
|
|
536
|
+
"loc",
|
|
537
|
+
"lines",
|
|
538
|
+
"line"
|
|
539
|
+
]) {
|
|
540
|
+
const value = getAttribute(el, name);
|
|
541
|
+
if (value !== void 0) attrs[name] = value;
|
|
542
|
+
}
|
|
543
|
+
return attrs;
|
|
544
|
+
}
|
|
545
|
+
function sourceRefFromAttributes(attrs) {
|
|
546
|
+
const permalink = attrs.permalink ?? attrs.url ?? attrs.href;
|
|
547
|
+
if (permalink) return parseGitHubPermalink(permalink);
|
|
548
|
+
const repo = attrs.repo;
|
|
549
|
+
const path = attrs.path ?? attrs.file;
|
|
550
|
+
if (!repo || !path || !isSafeGitHubRepo(repo) || !isSafeGitHubPath(path)) return null;
|
|
551
|
+
const ref = attrs.ref ?? attrs.sha ?? attrs.branch ?? "main";
|
|
552
|
+
if (!isSafeGitHubRef(ref)) return null;
|
|
553
|
+
const source = {
|
|
554
|
+
repo,
|
|
555
|
+
ref,
|
|
556
|
+
path,
|
|
557
|
+
lines: parseGitHubLineRange(attrs.loc ?? attrs.lines ?? attrs.line)
|
|
558
|
+
};
|
|
559
|
+
return {
|
|
560
|
+
...source,
|
|
561
|
+
permalink: createGitHubPermalink(source)
|
|
562
|
+
};
|
|
563
|
+
}
|
|
564
|
+
/**
|
|
252
565
|
* Pre-fetch all GitHub repos data.
|
|
253
566
|
*/
|
|
254
567
|
async function prefetchGitHubRepos(repos, options) {
|
|
@@ -257,22 +570,45 @@ async function prefetchGitHubRepos(repos, options) {
|
|
|
257
570
|
...options
|
|
258
571
|
};
|
|
259
572
|
const results = /* @__PURE__ */ new Map();
|
|
260
|
-
await Promise.all(repos.map(async (repo) => {
|
|
573
|
+
await Promise.all(Array.from(new Set(repos)).map(async (repo) => {
|
|
261
574
|
const data = await fetchRepoData(repo, mergedOptions);
|
|
262
575
|
results.set(repo, data);
|
|
263
576
|
}));
|
|
264
577
|
return results;
|
|
265
578
|
}
|
|
266
579
|
/**
|
|
580
|
+
* Pre-fetch all GitHub source files.
|
|
581
|
+
*/
|
|
582
|
+
async function prefetchGitHubSources(sources, options) {
|
|
583
|
+
const mergedOptions = {
|
|
584
|
+
...defaultOptions,
|
|
585
|
+
...options
|
|
586
|
+
};
|
|
587
|
+
const results = /* @__PURE__ */ new Map();
|
|
588
|
+
const uniqueSources = Array.from(new Map(sources.map((source) => [sourceKey(source), source])).values());
|
|
589
|
+
await Promise.all(uniqueSources.map(async (source) => {
|
|
590
|
+
const data = await fetchGitHubSource(source, mergedOptions);
|
|
591
|
+
results.set(sourceKey(source), data);
|
|
592
|
+
}));
|
|
593
|
+
return results;
|
|
594
|
+
}
|
|
595
|
+
/**
|
|
267
596
|
* Rehype plugin to transform GitHub components.
|
|
268
597
|
*/
|
|
269
|
-
function rehypeGitHub(repoDataMap) {
|
|
598
|
+
function rehypeGitHub(repoDataMap, sourceDataMap, options) {
|
|
270
599
|
return (tree) => {
|
|
271
600
|
const visit = (node) => {
|
|
272
601
|
if ("children" in node) for (let i = 0; i < node.children.length; i++) {
|
|
273
602
|
const child = node.children[i];
|
|
274
603
|
if (child.type === "element") if (child.tagName.toLowerCase() === "github") {
|
|
275
|
-
const
|
|
604
|
+
const attrs = attributesFromElement(child);
|
|
605
|
+
const source = sourceRefFromAttributes(attrs);
|
|
606
|
+
if (source) {
|
|
607
|
+
const sourceData = sourceDataMap.get(sourceKey(source));
|
|
608
|
+
node.children[i] = sourceData ? createGitHubSourceCard(sourceData, source.lines, options) : createFallbackCard(source.permalink);
|
|
609
|
+
continue;
|
|
610
|
+
}
|
|
611
|
+
const repo = attrs.repo;
|
|
276
612
|
if (repo) {
|
|
277
613
|
const repoData = repoDataMap.get(repo);
|
|
278
614
|
const cardElement = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);
|
|
@@ -288,12 +624,17 @@ function rehypeGitHub(repoDataMap) {
|
|
|
288
624
|
* Transform GitHub components in HTML.
|
|
289
625
|
*/
|
|
290
626
|
async function transformGitHub(html, repoDataMap, options) {
|
|
627
|
+
const mergedOptions = {
|
|
628
|
+
...defaultOptions,
|
|
629
|
+
...options
|
|
630
|
+
};
|
|
291
631
|
let dataMap = repoDataMap;
|
|
292
|
-
if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html),
|
|
293
|
-
const
|
|
632
|
+
if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html), mergedOptions);
|
|
633
|
+
const sourceDataMap = await prefetchGitHubSources(await collectGitHubSources(html), mergedOptions);
|
|
634
|
+
const result = await unified().use(rehypeParse, { fragment: true }).use(rehypeGitHub, dataMap, sourceDataMap, mergedOptions).use(rehypeStringify).process(html);
|
|
294
635
|
return String(result);
|
|
295
636
|
}
|
|
296
637
|
//#endregion
|
|
297
|
-
export {
|
|
638
|
+
export { github_exports as a, prefetchGitHubRepos as c, fetchRepoData as i, prefetchGitHubSources as l, collectGitHubSources as n, parseGitHubLineRange as o, fetchGitHubSource as r, parseGitHubPermalink as s, collectGitHubRepos as t, transformGitHub as u };
|
|
298
639
|
|
|
299
640
|
//# sourceMappingURL=github.mjs.map
|
package/dist/github.mjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.mjs","names":[],"sources":["../src/plugins/github.ts"],"sourcesContent":["/**\n * GitHub Plugin - Repository card embedding\n *\n * Transforms <GitHub> components into static repository cards\n * by fetching data from GitHub API at build time.\n */\n\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element } from \"hast\";\n\nexport interface GitHubRepoData {\n name: string;\n full_name: string;\n description: string | null;\n html_url: string;\n stargazers_count: number;\n forks_count: number;\n language: string | null;\n owner: {\n login: string;\n avatar_url: string;\n };\n}\n\nexport interface GitHubOptions {\n /** GitHub API token for higher rate limits. */\n token?: string;\n /** Cache fetched data. Default: true */\n cache?: boolean;\n /** Cache TTL in milliseconds. Default: 3600000 (1 hour) */\n cacheTTL?: number;\n}\n\nconst defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n};\n\n// Simple in-memory cache\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\nconst GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;\n\nexport function isSafeGitHubRepo(repo: string): boolean {\n return (\n GITHUB_REPO_RE.test(repo) && !repo.split(\"/\").some((part) => part === \".\" || part === \"..\")\n );\n}\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\n/**\n * Format number with K/M suffix.\n */\nfunction formatNumber(num: number): string {\n if (num >= 1000000) {\n return `${(num / 1000000).toFixed(1)}M`;\n }\n if (num >= 1000) {\n return `${(num / 1000).toFixed(1)}k`;\n }\n return String(num);\n}\n\n/**\n * Fetch repository data from GitHub API.\n */\nexport async function fetchRepoData(\n repo: string,\n options: Required<GitHubOptions>,\n): Promise<GitHubRepoData | null> {\n if (!isSafeGitHubRepo(repo)) {\n return null;\n }\n\n // Check cache\n if (options.cache) {\n const cached = repoCache.get(repo);\n if (cached && Date.now() - cached.timestamp < options.cacheTTL) {\n return cached.data;\n }\n }\n\n try {\n const headers: Record<string, string> = {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"ox-content-github-plugin\",\n };\n\n if (options.token) {\n headers.Authorization = `Bearer ${options.token}`;\n }\n\n const response = await fetch(`https://api.github.com/repos/${repo}`, { headers });\n\n if (!response.ok) {\n console.warn(`Failed to fetch GitHub repo ${repo}: ${response.status}`);\n return null;\n }\n\n const data = (await response.json()) as GitHubRepoData;\n\n // Cache the result\n if (options.cache) {\n repoCache.set(repo, { data, timestamp: Date.now() });\n }\n\n return data;\n } catch (error) {\n console.warn(`Error fetching GitHub repo ${repo}:`, error);\n return null;\n }\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nfunction createGitHubCard(repoData: GitHubRepoData): Element {\n const statsChildren: Element[\"children\"] = [];\n\n // Language\n if (repoData.language) {\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-language\"] },\n children: [\n {\n type: \"element\",\n tagName: \"span\",\n properties: {\n className: [\"ox-github-language-color\"],\n \"data-lang\": repoData.language.toLowerCase(),\n },\n children: [],\n },\n { type: \"text\", value: repoData.language },\n ],\n });\n }\n\n // Stars\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Z\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n // Forks\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\"],\n href: repoData.html_url,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n // Header\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repoData.full_name }],\n },\n ],\n },\n // Description\n ...(repoData.description\n ? [\n {\n type: \"element\" as const,\n tagName: \"p\",\n properties: { className: [\"ox-github-description\"] },\n children: [{ type: \"text\" as const, value: repoData.description }],\n },\n ]\n : []),\n // Stats\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: statsChildren,\n },\n ],\n };\n}\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nfunction createFallbackCard(repo: string): Element {\n const href = isSafeGitHubRepo(repo) ? `https://github.com/${repo}` : \"#\";\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\", \"error\"],\n href,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repo }],\n },\n ],\n },\n ],\n };\n}\n\n/**\n * Collect all GitHub repos from HTML for pre-fetching.\n */\nexport async function collectGitHubRepos(html: string): Promise<string[]> {\n const repos: string[] = [];\n const repoPattern = /<github[^>]*\\s+repo=[\"']([^\"']+)[\"']/gi;\n\n let match;\n while ((match = repoPattern.exec(html)) !== null) {\n if (isSafeGitHubRepo(match[1])) {\n repos.push(match[1]);\n }\n }\n\n return repos;\n}\n\n/**\n * Pre-fetch all GitHub repos data.\n */\nexport async function prefetchGitHubRepos(\n repos: string[],\n options?: GitHubOptions,\n): Promise<Map<string, GitHubRepoData | null>> {\n const mergedOptions = { ...defaultOptions, ...options };\n const results = new Map<string, GitHubRepoData | null>();\n\n await Promise.all(\n repos.map(async (repo) => {\n const data = await fetchRepoData(repo, mergedOptions);\n results.set(repo, data);\n }),\n );\n\n return results;\n}\n\n/**\n * Rehype plugin to transform GitHub components.\n */\nfunction rehypeGitHub(repoDataMap: Map<string, GitHubRepoData | null>) {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <GitHub> component\n if (child.tagName.toLowerCase() === \"github\") {\n const repo = getAttribute(child, \"repo\");\n\n if (repo) {\n const repoData = repoDataMap.get(repo);\n const cardElement = repoData\n ? createGitHubCard(repoData)\n : createFallbackCard(repo);\n node.children[i] = cardElement;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform GitHub components in HTML.\n */\nexport async function transformGitHub(\n html: string,\n repoDataMap?: Map<string, GitHubRepoData | null>,\n options?: GitHubOptions,\n): Promise<string> {\n // If no pre-fetched data, collect and fetch\n let dataMap = repoDataMap;\n if (!dataMap) {\n const repos = await collectGitHubRepos(html);\n dataMap = await prefetchGitHubRepos(repos, options);\n }\n\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeGitHub, dataMap)\n .use(rehypeStringify)\n .process(html);\n\n return String(result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IAAI,aAAa,EAAE,UAAU,MAAM,CAAC,CACpC,IAAI,cAAc,QAAQ,CAC1B,IAAI,gBAAgB,CACpB,QAAQ,KAAK;AAEhB,QAAO,OAAO,OAAO"}
|
|
1
|
+
{"version":3,"file":"github.mjs","names":[],"sources":["../src/plugins/github.ts"],"sourcesContent":["/**\n * GitHub Plugin - Repository and source code embedding\n *\n * Transforms <GitHub> components into static repository and source code cards\n * by fetching data from GitHub API at build time.\n */\n\nimport { Buffer } from \"node:buffer\";\nimport { unified } from \"unified\";\nimport rehypeParse from \"rehype-parse\";\nimport rehypeStringify from \"rehype-stringify\";\nimport type { Root, Element } from \"hast\";\n\nexport interface GitHubRepoData {\n name: string;\n full_name: string;\n description: string | null;\n html_url: string;\n stargazers_count: number;\n forks_count: number;\n language: string | null;\n owner: {\n login: string;\n avatar_url: string;\n };\n}\n\nexport interface GitHubLineRange {\n start: number;\n end: number;\n}\n\nexport interface GitHubSourceRef {\n repo: string;\n ref: string;\n path: string;\n permalink: string;\n lines?: GitHubLineRange;\n}\n\nexport interface GitHubSourceData {\n repo: string;\n ref: string;\n path: string;\n permalink: string;\n content: string;\n size: number;\n html_url: string;\n language: string | null;\n}\n\nexport interface GitHubOptions {\n /** GitHub API token for higher rate limits. */\n token?: string;\n /** Cache fetched data. Default: true */\n cache?: boolean;\n /** Cache TTL in milliseconds. Default: 3600000 (1 hour) */\n cacheTTL?: number;\n /** Maximum source file size to inline in bytes. Default: 200000 */\n maxSourceBytes?: number;\n /** Maximum source lines to inline when no line range is specified. Default: 120 */\n maxSourceLines?: number;\n}\n\nconst defaultOptions: Required<GitHubOptions> = {\n token: \"\",\n cache: true,\n cacheTTL: 3600000,\n maxSourceBytes: 200000,\n maxSourceLines: 120,\n};\n\n// Simple in-memory cache\nconst repoCache = new Map<string, { data: GitHubRepoData; timestamp: number }>();\nconst sourceCache = new Map<string, { data: GitHubSourceData; timestamp: number }>();\nconst GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\\/[A-Za-z0-9_.-]+$/;\nconst GITHUB_COMPONENT_RE = /<github\\b([^>]*)>/gi;\nconst ATTRIBUTE_RE = /([:\\w-]+)(?:\\s*=\\s*(?:\"([^\"]*)\"|'([^']*)'|([^\\s\"'>/]+)))?/g;\nconst CONTROL_CHAR_RE = /[\\u0000-\\u001f\\u007f]/;\nconst EXTENSION_LANGUAGE_MAP = new Map<string, string>([\n [\"cjs\", \"javascript\"],\n [\"css\", \"css\"],\n [\"go\", \"go\"],\n [\"html\", \"html\"],\n [\"js\", \"javascript\"],\n [\"json\", \"json\"],\n [\"jsx\", \"jsx\"],\n [\"md\", \"markdown\"],\n [\"mdx\", \"mdx\"],\n [\"mjs\", \"javascript\"],\n [\"py\", \"python\"],\n [\"rb\", \"ruby\"],\n [\"rs\", \"rust\"],\n [\"sh\", \"shell\"],\n [\"svelte\", \"svelte\"],\n [\"toml\", \"toml\"],\n [\"ts\", \"typescript\"],\n [\"tsx\", \"tsx\"],\n [\"vue\", \"vue\"],\n [\"yaml\", \"yaml\"],\n [\"yml\", \"yaml\"],\n]);\n\nexport function isSafeGitHubRepo(repo: string): boolean {\n return (\n GITHUB_REPO_RE.test(repo) && !repo.split(\"/\").some((part) => part === \".\" || part === \"..\")\n );\n}\n\nfunction isSafeGitHubRef(ref: string): boolean {\n return Boolean(ref) && !CONTROL_CHAR_RE.test(ref) && !hasUnsafePathSegment(ref);\n}\n\nfunction isSafeGitHubPath(path: string): boolean {\n return Boolean(path) && !CONTROL_CHAR_RE.test(path) && !hasUnsafePathSegment(path);\n}\n\nfunction hasUnsafePathSegment(value: string): boolean {\n return value\n .split(\"/\")\n .some((part) => !part || part === \".\" || part === \"..\" || part.includes(\"\\\\\"));\n}\n\nfunction encodePath(path: string): string {\n return path.split(\"/\").map(encodeURIComponent).join(\"/\");\n}\n\nfunction sourceKey(source: GitHubSourceRef): string {\n return `${source.repo}@${source.ref}:${source.path}`;\n}\n\nfunction formatLineRange(lines: GitHubLineRange): string {\n return lines.start === lines.end ? `L${lines.start}` : `L${lines.start}-L${lines.end}`;\n}\n\nexport function parseGitHubLineRange(value: string | undefined): GitHubLineRange | undefined {\n if (!value) return undefined;\n const match = value.trim().match(/^#?L?(\\d+)(?:-L?(\\d+))?$/i);\n if (!match) return undefined;\n\n const start = Number.parseInt(match[1], 10);\n const end = match[2] ? Number.parseInt(match[2], 10) : start;\n if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 1 || end < start) {\n return undefined;\n }\n\n return { start, end };\n}\n\nexport function createGitHubPermalink(source: Omit<GitHubSourceRef, \"permalink\">): string {\n const fragment = source.lines ? `#${formatLineRange(source.lines)}` : \"\";\n return `https://github.com/${source.repo}/blob/${encodeURIComponent(source.ref)}/${encodePath(\n source.path,\n )}${fragment}`;\n}\n\nexport function parseGitHubPermalink(value: string): GitHubSourceRef | null {\n let url: URL;\n try {\n url = new URL(value);\n } catch {\n return null;\n }\n\n if (url.protocol !== \"https:\" || url.hostname !== \"github.com\") {\n return null;\n }\n\n let parts: string[];\n try {\n parts = url.pathname\n .split(\"/\")\n .filter(Boolean)\n .map((part) => decodeURIComponent(part));\n } catch {\n return null;\n }\n\n if (parts.length < 5 || parts[2] !== \"blob\") {\n return null;\n }\n\n const repo = `${parts[0]}/${parts[1]}`;\n const ref = parts[3];\n const path = parts.slice(4).join(\"/\");\n if (!isSafeGitHubRepo(repo) || !isSafeGitHubRef(ref) || !isSafeGitHubPath(path)) {\n return null;\n }\n\n const lines = parseGitHubLineRange(url.hash);\n const source = { repo, ref, path, lines };\n return {\n ...source,\n permalink: createGitHubPermalink(source),\n };\n}\n\n/**\n * Get element attribute value.\n */\nfunction getAttribute(el: Element, name: string): string | undefined {\n const value = el.properties?.[name];\n if (typeof value === \"string\") return value;\n if (Array.isArray(value)) return value.join(\" \");\n return undefined;\n}\n\n/**\n * Format number with K/M suffix.\n */\nfunction formatNumber(num: number): string {\n if (num >= 1000000) {\n return `${(num / 1000000).toFixed(1)}M`;\n }\n if (num >= 1000) {\n return `${(num / 1000).toFixed(1)}k`;\n }\n return String(num);\n}\n\n/**\n * Fetch repository data from GitHub API.\n */\nexport async function fetchRepoData(\n repo: string,\n options: Required<GitHubOptions>,\n): Promise<GitHubRepoData | null> {\n if (!isSafeGitHubRepo(repo)) {\n return null;\n }\n\n // Check cache\n if (options.cache) {\n const cached = repoCache.get(repo);\n if (cached && Date.now() - cached.timestamp < options.cacheTTL) {\n return cached.data;\n }\n }\n\n try {\n const headers: Record<string, string> = {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"ox-content-github-plugin\",\n };\n\n if (options.token) {\n headers.Authorization = `Bearer ${options.token}`;\n }\n\n const response = await fetch(`https://api.github.com/repos/${repo}`, { headers });\n\n if (!response.ok) {\n console.warn(`Failed to fetch GitHub repo ${repo}: ${response.status}`);\n return null;\n }\n\n const data = (await response.json()) as GitHubRepoData;\n\n // Cache the result\n if (options.cache) {\n repoCache.set(repo, { data, timestamp: Date.now() });\n }\n\n return data;\n } catch (error) {\n console.warn(`Error fetching GitHub repo ${repo}:`, error);\n return null;\n }\n}\n\ninterface GitHubContentApiFile {\n type: string;\n encoding?: string;\n content?: string;\n size?: number;\n html_url?: string;\n}\n\n/**\n * Fetch source file data from GitHub API.\n */\nexport async function fetchGitHubSource(\n source: GitHubSourceRef,\n options: Required<GitHubOptions>,\n): Promise<GitHubSourceData | null> {\n if (\n !isSafeGitHubRepo(source.repo) ||\n !isSafeGitHubRef(source.ref) ||\n !isSafeGitHubPath(source.path)\n ) {\n return null;\n }\n\n const key = sourceKey(source);\n if (options.cache) {\n const cached = sourceCache.get(key);\n if (cached && Date.now() - cached.timestamp < options.cacheTTL) {\n return cached.data;\n }\n }\n\n try {\n const headers: Record<string, string> = {\n Accept: \"application/vnd.github.v3+json\",\n \"User-Agent\": \"ox-content-github-plugin\",\n };\n\n if (options.token) {\n headers.Authorization = `Bearer ${options.token}`;\n }\n\n const apiUrl = `https://api.github.com/repos/${source.repo}/contents/${encodePath(\n source.path,\n )}?ref=${encodeURIComponent(source.ref)}`;\n const response = await fetch(apiUrl, { headers });\n\n if (!response.ok) {\n console.warn(`Failed to fetch GitHub source ${source.permalink}: ${response.status}`);\n return null;\n }\n\n const data = (await response.json()) as GitHubContentApiFile;\n if (\n data.type !== \"file\" ||\n data.encoding !== \"base64\" ||\n !data.content ||\n (data.size ?? 0) > options.maxSourceBytes\n ) {\n return null;\n }\n\n const content = Buffer.from(data.content.replace(/\\s/g, \"\"), \"base64\").toString(\"utf8\");\n if (Buffer.byteLength(content) > options.maxSourceBytes) {\n return null;\n }\n\n const sourceData: GitHubSourceData = {\n repo: source.repo,\n ref: source.ref,\n path: source.path,\n permalink: source.permalink,\n content,\n size: data.size ?? Buffer.byteLength(content),\n html_url: data.html_url ?? source.permalink,\n language: inferLanguage(source.path),\n };\n\n if (options.cache) {\n sourceCache.set(key, { data: sourceData, timestamp: Date.now() });\n }\n\n return sourceData;\n } catch (error) {\n console.warn(`Error fetching GitHub source ${source.permalink}:`, error);\n return null;\n }\n}\n\n/**\n * Create GitHub card element from repo data.\n */\nfunction createGitHubCard(repoData: GitHubRepoData): Element {\n const statsChildren: Element[\"children\"] = [];\n\n // Language\n if (repoData.language) {\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-language\"] },\n children: [\n {\n type: \"element\",\n tagName: \"span\",\n properties: {\n className: [\"ox-github-language-color\"],\n \"data-lang\": repoData.language.toLowerCase(),\n },\n children: [],\n },\n { type: \"text\", value: repoData.language },\n ],\n });\n }\n\n // Stars\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M8 .25a.75.75 0 0 1 .673.418l1.882 3.815 4.21.612a.75.75 0 0 1 .416 1.279l-3.046 2.97.719 4.192a.751.751 0 0 1-1.088.791L8 12.347l-3.766 1.98a.75.75 0 0 1-1.088-.79l.72-4.194L.818 6.374a.75.75 0 0 1 .416-1.28l4.21-.611L7.327.668A.75.75 0 0 1 8 .25Z\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.stargazers_count) },\n ],\n });\n\n // Forks\n statsChildren.push({\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-stat\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M5 5.372v.878c0 .414.336.75.75.75h4.5a.75.75 0 0 0 .75-.75v-.878a2.25 2.25 0 1 1 1.5 0v.878a2.25 2.25 0 0 1-2.25 2.25h-1.5v2.128a2.251 2.251 0 1 1-1.5 0V8.5h-1.5A2.25 2.25 0 0 1 3.5 6.25v-.878a2.25 2.25 0 1 1 1.5 0ZM5 3.25a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Zm6.75.75a.75.75 0 1 0 0-1.5.75.75 0 0 0 0 1.5Zm-3 8.75a.75.75 0 1 0-1.5 0 .75.75 0 0 0 1.5 0Z\",\n },\n children: [],\n },\n ],\n },\n { type: \"text\", value: formatNumber(repoData.forks_count) },\n ],\n });\n\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\"],\n href: repoData.html_url,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n // Header\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M2 2.5A2.5 2.5 0 0 1 4.5 0h8.75a.75.75 0 0 1 .75.75v12.5a.75.75 0 0 1-.75.75h-2.5a.75.75 0 0 1 0-1.5h1.75v-2h-8a1 1 0 0 0-.714 1.7.75.75 0 1 1-1.072 1.05A2.495 2.495 0 0 1 2 11.5Zm10.5-1h-8a1 1 0 0 0-1 1v6.708A2.486 2.486 0 0 1 4.5 9h8ZM5 12.25a.25.25 0 0 1 .25-.25h3.5a.25.25 0 0 1 .25.25v3.25a.25.25 0 0 1-.4.2l-1.45-1.087a.249.249 0 0 0-.3 0L5.4 15.7a.25.25 0 0 1-.4-.2Z\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repoData.full_name }],\n },\n ],\n },\n // Description\n ...(repoData.description\n ? [\n {\n type: \"element\" as const,\n tagName: \"p\",\n properties: { className: [\"ox-github-description\"] },\n children: [{ type: \"text\" as const, value: repoData.description }],\n },\n ]\n : []),\n // Stats\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-stats\"] },\n children: statsChildren,\n },\n ],\n };\n}\n\n/**\n * Create fallback element when repo data is unavailable.\n */\nfunction createFallbackCard(repo: string): Element {\n const href = isSafeGitHubRepo(repo) ? `https://github.com/${repo}` : \"#\";\n return {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-card\", \"error\"],\n href,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"div\",\n properties: { className: [\"ox-github-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"svg\",\n properties: {\n className: [\"ox-github-icon\"],\n viewBox: \"0 0 16 16\",\n fill: \"currentColor\",\n },\n children: [\n {\n type: \"element\",\n tagName: \"path\",\n properties: {\n d: \"M8 0c4.42 0 8 3.58 8 8a8.013 8.013 0 0 1-5.45 7.59c-.4.08-.55-.17-.55-.38 0-.27.01-1.13.01-2.2 0-.75-.25-1.23-.54-1.48 1.78-.2 3.65-.88 3.65-3.95 0-.88-.31-1.59-.82-2.15.08-.2.36-1.02-.08-2.12 0 0-.67-.22-2.2.82-.64-.18-1.32-.27-2-.27-.68 0-1.36.09-2 .27-1.53-1.03-2.2-.82-2.2-.82-.44 1.1-.16 1.92-.08 2.12-.51.56-.82 1.28-.82 2.15 0 3.06 1.86 3.75 3.64 3.95-.23.2-.44.55-.51 1.07-.46.21-1.61.55-2.33-.66-.15-.24-.6-.83-1.23-.82-.67.01-.27.38.01.53.34.19.73.9.82 1.13.16.45.68 1.31 2.69.94 0 .67.01 1.3.01 1.49 0 .21-.15.45-.55.38A7.995 7.995 0 0 1 0 8c0-4.42 3.58-8 8-8Z\",\n },\n children: [],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-repo\"] },\n children: [{ type: \"text\", value: repo }],\n },\n ],\n },\n ],\n };\n}\n\nfunction inferLanguage(path: string): string | null {\n const fileName = path.split(\"/\").at(-1)?.toLowerCase() ?? \"\";\n if (fileName === \"dockerfile\") return \"dockerfile\";\n if (fileName === \"makefile\") return \"makefile\";\n\n const extension = fileName.includes(\".\") ? fileName.split(\".\").at(-1) : undefined;\n return extension ? (EXTENSION_LANGUAGE_MAP.get(extension) ?? extension) : null;\n}\n\nfunction normalizeSourceLines(content: string): string[] {\n const lines = content.replace(/\\r\\n?/g, \"\\n\").split(\"\\n\");\n if (lines.length > 1 && lines.at(-1) === \"\") {\n lines.pop();\n }\n return lines.length > 0 ? lines : [\"\"];\n}\n\nfunction createGitHubSourceCard(\n source: GitHubSourceData,\n lines: GitHubLineRange | undefined,\n options: Required<GitHubOptions>,\n): Element {\n const allLines = normalizeSourceLines(source.content);\n const start = Math.min(lines?.start ?? 1, allLines.length);\n const end = lines\n ? Math.min(lines.end, allLines.length)\n : Math.min(allLines.length, options.maxSourceLines);\n const selectedLines = allLines.slice(start - 1, end);\n const lineRange = { start, end };\n const loc = selectedLines.length;\n const rangeLabel = formatLineRange(lineRange);\n const locLabel =\n !lines && end < allLines.length\n ? `${rangeLabel} of ${allLines.length} LOC`\n : `${rangeLabel} - ${loc} LOC`;\n const languageClass = source.language ? [`language-${source.language}`] : [];\n\n return {\n type: \"element\",\n tagName: \"figure\",\n properties: {\n className: [\"ox-github-code\"],\n \"data-loc\": String(loc),\n \"data-source\": source.permalink,\n },\n children: [\n {\n type: \"element\",\n tagName: \"figcaption\",\n properties: { className: [\"ox-github-code-header\"] },\n children: [\n {\n type: \"element\",\n tagName: \"a\",\n properties: {\n className: [\"ox-github-code-title\"],\n href: source.permalink,\n target: \"_blank\",\n rel: \"noopener noreferrer\",\n },\n children: [{ type: \"text\", value: `${source.repo}/${source.path}` }],\n },\n {\n type: \"element\",\n tagName: \"span\",\n properties: { className: [\"ox-github-code-loc\"] },\n children: [{ type: \"text\", value: locLabel }],\n },\n ],\n },\n {\n type: \"element\",\n tagName: \"pre\",\n properties: {\n className: [\"ox-github-code-block\", ...languageClass],\n ...(source.language ? { \"data-language\": source.language } : {}),\n },\n children: [\n {\n type: \"element\",\n tagName: \"code\",\n properties: {\n className: languageClass,\n },\n children: selectedLines.map((line, index) => {\n const lineNumber = start + index;\n return {\n type: \"element\" as const,\n tagName: \"span\",\n properties: {\n className: [\"line\", \"ox-github-code-line\"],\n \"data-line\": String(lineNumber),\n },\n children: [\n {\n type: \"element\" as const,\n tagName: \"span\",\n properties: { className: [\"ox-github-code-line-number\"] },\n children: [{ type: \"text\" as const, value: String(lineNumber) }],\n },\n {\n type: \"element\" as const,\n tagName: \"span\",\n properties: { className: [\"ox-github-code-line-content\"] },\n children: [{ type: \"text\" as const, value: line || \" \" }],\n },\n ],\n };\n }),\n },\n ],\n },\n ],\n };\n}\n\n/**\n * Collect all GitHub repos from HTML for pre-fetching.\n */\nexport async function collectGitHubRepos(html: string): Promise<string[]> {\n const repos: string[] = [];\n\n GITHUB_COMPONENT_RE.lastIndex = 0;\n let match;\n while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {\n const attrs = parseAttributes(match[1]);\n if (attrs.path || attrs.file || attrs.permalink || attrs.url || attrs.href) {\n continue;\n }\n\n const repo = attrs.repo;\n if (repo && isSafeGitHubRepo(repo)) {\n repos.push(repo);\n }\n }\n\n return repos;\n}\n\n/**\n * Collect all GitHub source references from HTML for pre-fetching.\n */\nexport async function collectGitHubSources(html: string): Promise<GitHubSourceRef[]> {\n const sources: GitHubSourceRef[] = [];\n\n GITHUB_COMPONENT_RE.lastIndex = 0;\n let match;\n while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {\n const source = sourceRefFromAttributes(parseAttributes(match[1]));\n if (source) {\n sources.push(source);\n }\n }\n\n return sources;\n}\n\nfunction parseAttributes(raw: string): Record<string, string> {\n const attrs: Record<string, string> = {};\n ATTRIBUTE_RE.lastIndex = 0;\n let match;\n\n while ((match = ATTRIBUTE_RE.exec(raw)) !== null) {\n attrs[match[1].toLowerCase()] = match[2] ?? match[3] ?? match[4] ?? \"\";\n }\n\n return attrs;\n}\n\nfunction attributesFromElement(el: Element): Record<string, string> {\n const attrs: Record<string, string> = {};\n for (const name of [\n \"permalink\",\n \"url\",\n \"href\",\n \"repo\",\n \"path\",\n \"file\",\n \"ref\",\n \"sha\",\n \"branch\",\n \"loc\",\n \"lines\",\n \"line\",\n ]) {\n const value = getAttribute(el, name);\n if (value !== undefined) {\n attrs[name] = value;\n }\n }\n return attrs;\n}\n\nfunction sourceRefFromAttributes(attrs: Record<string, string>): GitHubSourceRef | null {\n const permalink = attrs.permalink ?? attrs.url ?? attrs.href;\n if (permalink) {\n return parseGitHubPermalink(permalink);\n }\n\n const repo = attrs.repo;\n const path = attrs.path ?? attrs.file;\n if (!repo || !path || !isSafeGitHubRepo(repo) || !isSafeGitHubPath(path)) {\n return null;\n }\n\n const ref = attrs.ref ?? attrs.sha ?? attrs.branch ?? \"main\";\n if (!isSafeGitHubRef(ref)) {\n return null;\n }\n\n const lines = parseGitHubLineRange(attrs.loc ?? attrs.lines ?? attrs.line);\n const source = { repo, ref, path, lines };\n return {\n ...source,\n permalink: createGitHubPermalink(source),\n };\n}\n\n/**\n * Pre-fetch all GitHub repos data.\n */\nexport async function prefetchGitHubRepos(\n repos: string[],\n options?: GitHubOptions,\n): Promise<Map<string, GitHubRepoData | null>> {\n const mergedOptions = { ...defaultOptions, ...options };\n const results = new Map<string, GitHubRepoData | null>();\n\n await Promise.all(\n Array.from(new Set(repos)).map(async (repo) => {\n const data = await fetchRepoData(repo, mergedOptions);\n results.set(repo, data);\n }),\n );\n\n return results;\n}\n\n/**\n * Pre-fetch all GitHub source files.\n */\nexport async function prefetchGitHubSources(\n sources: GitHubSourceRef[],\n options?: GitHubOptions,\n): Promise<Map<string, GitHubSourceData | null>> {\n const mergedOptions = { ...defaultOptions, ...options };\n const results = new Map<string, GitHubSourceData | null>();\n const uniqueSources = Array.from(\n new Map(sources.map((source) => [sourceKey(source), source])).values(),\n );\n\n await Promise.all(\n uniqueSources.map(async (source) => {\n const data = await fetchGitHubSource(source, mergedOptions);\n results.set(sourceKey(source), data);\n }),\n );\n\n return results;\n}\n\n/**\n * Rehype plugin to transform GitHub components.\n */\nfunction rehypeGitHub(\n repoDataMap: Map<string, GitHubRepoData | null>,\n sourceDataMap: Map<string, GitHubSourceData | null>,\n options: Required<GitHubOptions>,\n) {\n return (tree: Root) => {\n const visit = (node: Root | Element) => {\n if (\"children\" in node) {\n for (let i = 0; i < node.children.length; i++) {\n const child = node.children[i];\n\n if (child.type === \"element\") {\n // Check for <GitHub> component\n if (child.tagName.toLowerCase() === \"github\") {\n const attrs = attributesFromElement(child);\n const source = sourceRefFromAttributes(attrs);\n\n if (source) {\n const sourceData = sourceDataMap.get(sourceKey(source));\n node.children[i] = sourceData\n ? createGitHubSourceCard(sourceData, source.lines, options)\n : createFallbackCard(source.permalink);\n continue;\n }\n\n const repo = attrs.repo;\n if (repo) {\n const repoData = repoDataMap.get(repo);\n const cardElement = repoData\n ? createGitHubCard(repoData)\n : createFallbackCard(repo);\n node.children[i] = cardElement;\n }\n } else {\n visit(child);\n }\n }\n }\n }\n };\n\n visit(tree);\n };\n}\n\n/**\n * Transform GitHub components in HTML.\n */\nexport async function transformGitHub(\n html: string,\n repoDataMap?: Map<string, GitHubRepoData | null>,\n options?: GitHubOptions,\n): Promise<string> {\n const mergedOptions = { ...defaultOptions, ...options };\n // If no pre-fetched data, collect and fetch\n let dataMap = repoDataMap;\n if (!dataMap) {\n const repos = await collectGitHubRepos(html);\n dataMap = await prefetchGitHubRepos(repos, mergedOptions);\n }\n const sources = await collectGitHubSources(html);\n const sourceDataMap = await prefetchGitHubSources(sources, mergedOptions);\n\n const result = await unified()\n .use(rehypeParse, { fragment: true })\n .use(rehypeGitHub, dataMap, sourceDataMap, mergedOptions)\n .use(rehypeStringify)\n .process(html);\n\n return String(result);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;AAgEA,MAAM,iBAA0C;CAC9C,OAAO;CACP,OAAO;CACP,UAAU;CACV,gBAAgB;CAChB,gBAAgB;CACjB;AAGD,MAAM,4BAAY,IAAI,KAA0D;AAChF,MAAM,8BAAc,IAAI,KAA4D;AACpF,MAAM,iBAAiB;AACvB,MAAM,sBAAsB;AAC5B,MAAM,eAAe;AACrB,MAAM,kBAAkB;AACxB,MAAM,yBAAyB,IAAI,IAAoB;CACrD,CAAC,OAAO,aAAa;CACrB,CAAC,OAAO,MAAM;CACd,CAAC,MAAM,KAAK;CACZ,CAAC,QAAQ,OAAO;CAChB,CAAC,MAAM,aAAa;CACpB,CAAC,QAAQ,OAAO;CAChB,CAAC,OAAO,MAAM;CACd,CAAC,MAAM,WAAW;CAClB,CAAC,OAAO,MAAM;CACd,CAAC,OAAO,aAAa;CACrB,CAAC,MAAM,SAAS;CAChB,CAAC,MAAM,OAAO;CACd,CAAC,MAAM,OAAO;CACd,CAAC,MAAM,QAAQ;CACf,CAAC,UAAU,SAAS;CACpB,CAAC,QAAQ,OAAO;CAChB,CAAC,MAAM,aAAa;CACpB,CAAC,OAAO,MAAM;CACd,CAAC,OAAO,MAAM;CACd,CAAC,QAAQ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