@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.cjs
CHANGED
|
@@ -4,30 +4,130 @@ let rehype_parse = require("rehype-parse");
|
|
|
4
4
|
rehype_parse = require_chunk.__toESM(rehype_parse);
|
|
5
5
|
let rehype_stringify = require("rehype-stringify");
|
|
6
6
|
rehype_stringify = require_chunk.__toESM(rehype_stringify);
|
|
7
|
+
let node_buffer = require("node:buffer");
|
|
7
8
|
//#region src/plugins/github.ts
|
|
8
9
|
/**
|
|
9
|
-
* GitHub Plugin - Repository
|
|
10
|
+
* GitHub Plugin - Repository and source code embedding
|
|
10
11
|
*
|
|
11
|
-
* Transforms <GitHub> components into static repository cards
|
|
12
|
+
* Transforms <GitHub> components into static repository and source code cards
|
|
12
13
|
* by fetching data from GitHub API at build time.
|
|
13
14
|
*/
|
|
14
15
|
var github_exports = /* @__PURE__ */ require_chunk.__exportAll({
|
|
15
16
|
collectGitHubRepos: () => collectGitHubRepos,
|
|
17
|
+
collectGitHubSources: () => collectGitHubSources,
|
|
18
|
+
createGitHubPermalink: () => createGitHubPermalink,
|
|
19
|
+
fetchGitHubSource: () => fetchGitHubSource,
|
|
16
20
|
fetchRepoData: () => fetchRepoData,
|
|
17
21
|
isSafeGitHubRepo: () => isSafeGitHubRepo,
|
|
22
|
+
parseGitHubLineRange: () => parseGitHubLineRange,
|
|
23
|
+
parseGitHubPermalink: () => parseGitHubPermalink,
|
|
18
24
|
prefetchGitHubRepos: () => prefetchGitHubRepos,
|
|
25
|
+
prefetchGitHubSources: () => prefetchGitHubSources,
|
|
19
26
|
transformGitHub: () => transformGitHub
|
|
20
27
|
});
|
|
21
28
|
const defaultOptions = {
|
|
22
29
|
token: "",
|
|
23
30
|
cache: true,
|
|
24
|
-
cacheTTL: 36e5
|
|
31
|
+
cacheTTL: 36e5,
|
|
32
|
+
maxSourceBytes: 2e5,
|
|
33
|
+
maxSourceLines: 120
|
|
25
34
|
};
|
|
26
35
|
const repoCache = /* @__PURE__ */ new Map();
|
|
36
|
+
const sourceCache = /* @__PURE__ */ new Map();
|
|
27
37
|
const GITHUB_REPO_RE = /^[A-Za-z0-9_.-]+\/[A-Za-z0-9_.-]+$/;
|
|
38
|
+
const GITHUB_COMPONENT_RE = /<github\b([^>]*)>/gi;
|
|
39
|
+
const ATTRIBUTE_RE = /([:\w-]+)(?:\s*=\s*(?:"([^"]*)"|'([^']*)'|([^\s"'>/]+)))?/g;
|
|
40
|
+
const CONTROL_CHAR_RE = /[\u0000-\u001f\u007f]/;
|
|
41
|
+
const EXTENSION_LANGUAGE_MAP = new Map([
|
|
42
|
+
["cjs", "javascript"],
|
|
43
|
+
["css", "css"],
|
|
44
|
+
["go", "go"],
|
|
45
|
+
["html", "html"],
|
|
46
|
+
["js", "javascript"],
|
|
47
|
+
["json", "json"],
|
|
48
|
+
["jsx", "jsx"],
|
|
49
|
+
["md", "markdown"],
|
|
50
|
+
["mdx", "mdx"],
|
|
51
|
+
["mjs", "javascript"],
|
|
52
|
+
["py", "python"],
|
|
53
|
+
["rb", "ruby"],
|
|
54
|
+
["rs", "rust"],
|
|
55
|
+
["sh", "shell"],
|
|
56
|
+
["svelte", "svelte"],
|
|
57
|
+
["toml", "toml"],
|
|
58
|
+
["ts", "typescript"],
|
|
59
|
+
["tsx", "tsx"],
|
|
60
|
+
["vue", "vue"],
|
|
61
|
+
["yaml", "yaml"],
|
|
62
|
+
["yml", "yaml"]
|
|
63
|
+
]);
|
|
28
64
|
function isSafeGitHubRepo(repo) {
|
|
29
65
|
return GITHUB_REPO_RE.test(repo) && !repo.split("/").some((part) => part === "." || part === "..");
|
|
30
66
|
}
|
|
67
|
+
function isSafeGitHubRef(ref) {
|
|
68
|
+
return Boolean(ref) && !CONTROL_CHAR_RE.test(ref) && !hasUnsafePathSegment(ref);
|
|
69
|
+
}
|
|
70
|
+
function isSafeGitHubPath(path) {
|
|
71
|
+
return Boolean(path) && !CONTROL_CHAR_RE.test(path) && !hasUnsafePathSegment(path);
|
|
72
|
+
}
|
|
73
|
+
function hasUnsafePathSegment(value) {
|
|
74
|
+
return value.split("/").some((part) => !part || part === "." || part === ".." || part.includes("\\"));
|
|
75
|
+
}
|
|
76
|
+
function encodePath(path) {
|
|
77
|
+
return path.split("/").map(encodeURIComponent).join("/");
|
|
78
|
+
}
|
|
79
|
+
function sourceKey(source) {
|
|
80
|
+
return `${source.repo}@${source.ref}:${source.path}`;
|
|
81
|
+
}
|
|
82
|
+
function formatLineRange(lines) {
|
|
83
|
+
return lines.start === lines.end ? `L${lines.start}` : `L${lines.start}-L${lines.end}`;
|
|
84
|
+
}
|
|
85
|
+
function parseGitHubLineRange(value) {
|
|
86
|
+
if (!value) return void 0;
|
|
87
|
+
const match = value.trim().match(/^#?L?(\d+)(?:-L?(\d+))?$/i);
|
|
88
|
+
if (!match) return void 0;
|
|
89
|
+
const start = Number.parseInt(match[1], 10);
|
|
90
|
+
const end = match[2] ? Number.parseInt(match[2], 10) : start;
|
|
91
|
+
if (!Number.isSafeInteger(start) || !Number.isSafeInteger(end) || start < 1 || end < start) return;
|
|
92
|
+
return {
|
|
93
|
+
start,
|
|
94
|
+
end
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
function createGitHubPermalink(source) {
|
|
98
|
+
const fragment = source.lines ? `#${formatLineRange(source.lines)}` : "";
|
|
99
|
+
return `https://github.com/${source.repo}/blob/${encodeURIComponent(source.ref)}/${encodePath(source.path)}${fragment}`;
|
|
100
|
+
}
|
|
101
|
+
function parseGitHubPermalink(value) {
|
|
102
|
+
let url;
|
|
103
|
+
try {
|
|
104
|
+
url = new URL(value);
|
|
105
|
+
} catch {
|
|
106
|
+
return null;
|
|
107
|
+
}
|
|
108
|
+
if (url.protocol !== "https:" || url.hostname !== "github.com") return null;
|
|
109
|
+
let parts;
|
|
110
|
+
try {
|
|
111
|
+
parts = url.pathname.split("/").filter(Boolean).map((part) => decodeURIComponent(part));
|
|
112
|
+
} catch {
|
|
113
|
+
return null;
|
|
114
|
+
}
|
|
115
|
+
if (parts.length < 5 || parts[2] !== "blob") return null;
|
|
116
|
+
const repo = `${parts[0]}/${parts[1]}`;
|
|
117
|
+
const ref = parts[3];
|
|
118
|
+
const path = parts.slice(4).join("/");
|
|
119
|
+
if (!isSafeGitHubRepo(repo) || !isSafeGitHubRef(ref) || !isSafeGitHubPath(path)) return null;
|
|
120
|
+
const source = {
|
|
121
|
+
repo,
|
|
122
|
+
ref,
|
|
123
|
+
path,
|
|
124
|
+
lines: parseGitHubLineRange(url.hash)
|
|
125
|
+
};
|
|
126
|
+
return {
|
|
127
|
+
...source,
|
|
128
|
+
permalink: createGitHubPermalink(source)
|
|
129
|
+
};
|
|
130
|
+
}
|
|
31
131
|
/**
|
|
32
132
|
* Get element attribute value.
|
|
33
133
|
*/
|
|
@@ -76,6 +176,52 @@ async function fetchRepoData(repo, options) {
|
|
|
76
176
|
}
|
|
77
177
|
}
|
|
78
178
|
/**
|
|
179
|
+
* Fetch source file data from GitHub API.
|
|
180
|
+
*/
|
|
181
|
+
async function fetchGitHubSource(source, options) {
|
|
182
|
+
if (!isSafeGitHubRepo(source.repo) || !isSafeGitHubRef(source.ref) || !isSafeGitHubPath(source.path)) return null;
|
|
183
|
+
const key = sourceKey(source);
|
|
184
|
+
if (options.cache) {
|
|
185
|
+
const cached = sourceCache.get(key);
|
|
186
|
+
if (cached && Date.now() - cached.timestamp < options.cacheTTL) return cached.data;
|
|
187
|
+
}
|
|
188
|
+
try {
|
|
189
|
+
const headers = {
|
|
190
|
+
Accept: "application/vnd.github.v3+json",
|
|
191
|
+
"User-Agent": "ox-content-github-plugin"
|
|
192
|
+
};
|
|
193
|
+
if (options.token) headers.Authorization = `Bearer ${options.token}`;
|
|
194
|
+
const apiUrl = `https://api.github.com/repos/${source.repo}/contents/${encodePath(source.path)}?ref=${encodeURIComponent(source.ref)}`;
|
|
195
|
+
const response = await fetch(apiUrl, { headers });
|
|
196
|
+
if (!response.ok) {
|
|
197
|
+
console.warn(`Failed to fetch GitHub source ${source.permalink}: ${response.status}`);
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const data = await response.json();
|
|
201
|
+
if (data.type !== "file" || data.encoding !== "base64" || !data.content || (data.size ?? 0) > options.maxSourceBytes) return null;
|
|
202
|
+
const content = node_buffer.Buffer.from(data.content.replace(/\s/g, ""), "base64").toString("utf8");
|
|
203
|
+
if (node_buffer.Buffer.byteLength(content) > options.maxSourceBytes) return null;
|
|
204
|
+
const sourceData = {
|
|
205
|
+
repo: source.repo,
|
|
206
|
+
ref: source.ref,
|
|
207
|
+
path: source.path,
|
|
208
|
+
permalink: source.permalink,
|
|
209
|
+
content,
|
|
210
|
+
size: data.size ?? node_buffer.Buffer.byteLength(content),
|
|
211
|
+
html_url: data.html_url ?? source.permalink,
|
|
212
|
+
language: inferLanguage(source.path)
|
|
213
|
+
};
|
|
214
|
+
if (options.cache) sourceCache.set(key, {
|
|
215
|
+
data: sourceData,
|
|
216
|
+
timestamp: Date.now()
|
|
217
|
+
});
|
|
218
|
+
return sourceData;
|
|
219
|
+
} catch (error) {
|
|
220
|
+
console.warn(`Error fetching GitHub source ${source.permalink}:`, error);
|
|
221
|
+
return null;
|
|
222
|
+
}
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
79
225
|
* Create GitHub card element from repo data.
|
|
80
226
|
*/
|
|
81
227
|
function createGitHubCard(repoData) {
|
|
@@ -240,17 +386,184 @@ function createFallbackCard(repo) {
|
|
|
240
386
|
}]
|
|
241
387
|
};
|
|
242
388
|
}
|
|
389
|
+
function inferLanguage(path) {
|
|
390
|
+
const fileName = path.split("/").at(-1)?.toLowerCase() ?? "";
|
|
391
|
+
if (fileName === "dockerfile") return "dockerfile";
|
|
392
|
+
if (fileName === "makefile") return "makefile";
|
|
393
|
+
const extension = fileName.includes(".") ? fileName.split(".").at(-1) : void 0;
|
|
394
|
+
return extension ? EXTENSION_LANGUAGE_MAP.get(extension) ?? extension : null;
|
|
395
|
+
}
|
|
396
|
+
function normalizeSourceLines(content) {
|
|
397
|
+
const lines = content.replace(/\r\n?/g, "\n").split("\n");
|
|
398
|
+
if (lines.length > 1 && lines.at(-1) === "") lines.pop();
|
|
399
|
+
return lines.length > 0 ? lines : [""];
|
|
400
|
+
}
|
|
401
|
+
function createGitHubSourceCard(source, lines, options) {
|
|
402
|
+
const allLines = normalizeSourceLines(source.content);
|
|
403
|
+
const start = Math.min(lines?.start ?? 1, allLines.length);
|
|
404
|
+
const end = lines ? Math.min(lines.end, allLines.length) : Math.min(allLines.length, options.maxSourceLines);
|
|
405
|
+
const selectedLines = allLines.slice(start - 1, end);
|
|
406
|
+
const lineRange = {
|
|
407
|
+
start,
|
|
408
|
+
end
|
|
409
|
+
};
|
|
410
|
+
const loc = selectedLines.length;
|
|
411
|
+
const rangeLabel = formatLineRange(lineRange);
|
|
412
|
+
const locLabel = !lines && end < allLines.length ? `${rangeLabel} of ${allLines.length} LOC` : `${rangeLabel} - ${loc} LOC`;
|
|
413
|
+
const languageClass = source.language ? [`language-${source.language}`] : [];
|
|
414
|
+
return {
|
|
415
|
+
type: "element",
|
|
416
|
+
tagName: "figure",
|
|
417
|
+
properties: {
|
|
418
|
+
className: ["ox-github-code"],
|
|
419
|
+
"data-loc": String(loc),
|
|
420
|
+
"data-source": source.permalink
|
|
421
|
+
},
|
|
422
|
+
children: [{
|
|
423
|
+
type: "element",
|
|
424
|
+
tagName: "figcaption",
|
|
425
|
+
properties: { className: ["ox-github-code-header"] },
|
|
426
|
+
children: [{
|
|
427
|
+
type: "element",
|
|
428
|
+
tagName: "a",
|
|
429
|
+
properties: {
|
|
430
|
+
className: ["ox-github-code-title"],
|
|
431
|
+
href: source.permalink,
|
|
432
|
+
target: "_blank",
|
|
433
|
+
rel: "noopener noreferrer"
|
|
434
|
+
},
|
|
435
|
+
children: [{
|
|
436
|
+
type: "text",
|
|
437
|
+
value: `${source.repo}/${source.path}`
|
|
438
|
+
}]
|
|
439
|
+
}, {
|
|
440
|
+
type: "element",
|
|
441
|
+
tagName: "span",
|
|
442
|
+
properties: { className: ["ox-github-code-loc"] },
|
|
443
|
+
children: [{
|
|
444
|
+
type: "text",
|
|
445
|
+
value: locLabel
|
|
446
|
+
}]
|
|
447
|
+
}]
|
|
448
|
+
}, {
|
|
449
|
+
type: "element",
|
|
450
|
+
tagName: "pre",
|
|
451
|
+
properties: {
|
|
452
|
+
className: ["ox-github-code-block", ...languageClass],
|
|
453
|
+
...source.language ? { "data-language": source.language } : {}
|
|
454
|
+
},
|
|
455
|
+
children: [{
|
|
456
|
+
type: "element",
|
|
457
|
+
tagName: "code",
|
|
458
|
+
properties: { className: languageClass },
|
|
459
|
+
children: selectedLines.map((line, index) => {
|
|
460
|
+
const lineNumber = start + index;
|
|
461
|
+
return {
|
|
462
|
+
type: "element",
|
|
463
|
+
tagName: "span",
|
|
464
|
+
properties: {
|
|
465
|
+
className: ["line", "ox-github-code-line"],
|
|
466
|
+
"data-line": String(lineNumber)
|
|
467
|
+
},
|
|
468
|
+
children: [{
|
|
469
|
+
type: "element",
|
|
470
|
+
tagName: "span",
|
|
471
|
+
properties: { className: ["ox-github-code-line-number"] },
|
|
472
|
+
children: [{
|
|
473
|
+
type: "text",
|
|
474
|
+
value: String(lineNumber)
|
|
475
|
+
}]
|
|
476
|
+
}, {
|
|
477
|
+
type: "element",
|
|
478
|
+
tagName: "span",
|
|
479
|
+
properties: { className: ["ox-github-code-line-content"] },
|
|
480
|
+
children: [{
|
|
481
|
+
type: "text",
|
|
482
|
+
value: line || " "
|
|
483
|
+
}]
|
|
484
|
+
}]
|
|
485
|
+
};
|
|
486
|
+
})
|
|
487
|
+
}]
|
|
488
|
+
}]
|
|
489
|
+
};
|
|
490
|
+
}
|
|
243
491
|
/**
|
|
244
492
|
* Collect all GitHub repos from HTML for pre-fetching.
|
|
245
493
|
*/
|
|
246
494
|
async function collectGitHubRepos(html) {
|
|
247
495
|
const repos = [];
|
|
248
|
-
|
|
496
|
+
GITHUB_COMPONENT_RE.lastIndex = 0;
|
|
249
497
|
let match;
|
|
250
|
-
while ((match =
|
|
498
|
+
while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {
|
|
499
|
+
const attrs = parseAttributes(match[1]);
|
|
500
|
+
if (attrs.path || attrs.file || attrs.permalink || attrs.url || attrs.href) continue;
|
|
501
|
+
const repo = attrs.repo;
|
|
502
|
+
if (repo && isSafeGitHubRepo(repo)) repos.push(repo);
|
|
503
|
+
}
|
|
251
504
|
return repos;
|
|
252
505
|
}
|
|
253
506
|
/**
|
|
507
|
+
* Collect all GitHub source references from HTML for pre-fetching.
|
|
508
|
+
*/
|
|
509
|
+
async function collectGitHubSources(html) {
|
|
510
|
+
const sources = [];
|
|
511
|
+
GITHUB_COMPONENT_RE.lastIndex = 0;
|
|
512
|
+
let match;
|
|
513
|
+
while ((match = GITHUB_COMPONENT_RE.exec(html)) !== null) {
|
|
514
|
+
const source = sourceRefFromAttributes(parseAttributes(match[1]));
|
|
515
|
+
if (source) sources.push(source);
|
|
516
|
+
}
|
|
517
|
+
return sources;
|
|
518
|
+
}
|
|
519
|
+
function parseAttributes(raw) {
|
|
520
|
+
const attrs = {};
|
|
521
|
+
ATTRIBUTE_RE.lastIndex = 0;
|
|
522
|
+
let match;
|
|
523
|
+
while ((match = ATTRIBUTE_RE.exec(raw)) !== null) attrs[match[1].toLowerCase()] = match[2] ?? match[3] ?? match[4] ?? "";
|
|
524
|
+
return attrs;
|
|
525
|
+
}
|
|
526
|
+
function attributesFromElement(el) {
|
|
527
|
+
const attrs = {};
|
|
528
|
+
for (const name of [
|
|
529
|
+
"permalink",
|
|
530
|
+
"url",
|
|
531
|
+
"href",
|
|
532
|
+
"repo",
|
|
533
|
+
"path",
|
|
534
|
+
"file",
|
|
535
|
+
"ref",
|
|
536
|
+
"sha",
|
|
537
|
+
"branch",
|
|
538
|
+
"loc",
|
|
539
|
+
"lines",
|
|
540
|
+
"line"
|
|
541
|
+
]) {
|
|
542
|
+
const value = getAttribute(el, name);
|
|
543
|
+
if (value !== void 0) attrs[name] = value;
|
|
544
|
+
}
|
|
545
|
+
return attrs;
|
|
546
|
+
}
|
|
547
|
+
function sourceRefFromAttributes(attrs) {
|
|
548
|
+
const permalink = attrs.permalink ?? attrs.url ?? attrs.href;
|
|
549
|
+
if (permalink) return parseGitHubPermalink(permalink);
|
|
550
|
+
const repo = attrs.repo;
|
|
551
|
+
const path = attrs.path ?? attrs.file;
|
|
552
|
+
if (!repo || !path || !isSafeGitHubRepo(repo) || !isSafeGitHubPath(path)) return null;
|
|
553
|
+
const ref = attrs.ref ?? attrs.sha ?? attrs.branch ?? "main";
|
|
554
|
+
if (!isSafeGitHubRef(ref)) return null;
|
|
555
|
+
const source = {
|
|
556
|
+
repo,
|
|
557
|
+
ref,
|
|
558
|
+
path,
|
|
559
|
+
lines: parseGitHubLineRange(attrs.loc ?? attrs.lines ?? attrs.line)
|
|
560
|
+
};
|
|
561
|
+
return {
|
|
562
|
+
...source,
|
|
563
|
+
permalink: createGitHubPermalink(source)
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
254
567
|
* Pre-fetch all GitHub repos data.
|
|
255
568
|
*/
|
|
256
569
|
async function prefetchGitHubRepos(repos, options) {
|
|
@@ -259,22 +572,45 @@ async function prefetchGitHubRepos(repos, options) {
|
|
|
259
572
|
...options
|
|
260
573
|
};
|
|
261
574
|
const results = /* @__PURE__ */ new Map();
|
|
262
|
-
await Promise.all(repos.map(async (repo) => {
|
|
575
|
+
await Promise.all(Array.from(new Set(repos)).map(async (repo) => {
|
|
263
576
|
const data = await fetchRepoData(repo, mergedOptions);
|
|
264
577
|
results.set(repo, data);
|
|
265
578
|
}));
|
|
266
579
|
return results;
|
|
267
580
|
}
|
|
268
581
|
/**
|
|
582
|
+
* Pre-fetch all GitHub source files.
|
|
583
|
+
*/
|
|
584
|
+
async function prefetchGitHubSources(sources, options) {
|
|
585
|
+
const mergedOptions = {
|
|
586
|
+
...defaultOptions,
|
|
587
|
+
...options
|
|
588
|
+
};
|
|
589
|
+
const results = /* @__PURE__ */ new Map();
|
|
590
|
+
const uniqueSources = Array.from(new Map(sources.map((source) => [sourceKey(source), source])).values());
|
|
591
|
+
await Promise.all(uniqueSources.map(async (source) => {
|
|
592
|
+
const data = await fetchGitHubSource(source, mergedOptions);
|
|
593
|
+
results.set(sourceKey(source), data);
|
|
594
|
+
}));
|
|
595
|
+
return results;
|
|
596
|
+
}
|
|
597
|
+
/**
|
|
269
598
|
* Rehype plugin to transform GitHub components.
|
|
270
599
|
*/
|
|
271
|
-
function rehypeGitHub(repoDataMap) {
|
|
600
|
+
function rehypeGitHub(repoDataMap, sourceDataMap, options) {
|
|
272
601
|
return (tree) => {
|
|
273
602
|
const visit = (node) => {
|
|
274
603
|
if ("children" in node) for (let i = 0; i < node.children.length; i++) {
|
|
275
604
|
const child = node.children[i];
|
|
276
605
|
if (child.type === "element") if (child.tagName.toLowerCase() === "github") {
|
|
277
|
-
const
|
|
606
|
+
const attrs = attributesFromElement(child);
|
|
607
|
+
const source = sourceRefFromAttributes(attrs);
|
|
608
|
+
if (source) {
|
|
609
|
+
const sourceData = sourceDataMap.get(sourceKey(source));
|
|
610
|
+
node.children[i] = sourceData ? createGitHubSourceCard(sourceData, source.lines, options) : createFallbackCard(source.permalink);
|
|
611
|
+
continue;
|
|
612
|
+
}
|
|
613
|
+
const repo = attrs.repo;
|
|
278
614
|
if (repo) {
|
|
279
615
|
const repoData = repoDataMap.get(repo);
|
|
280
616
|
const cardElement = repoData ? createGitHubCard(repoData) : createFallbackCard(repo);
|
|
@@ -290,9 +626,14 @@ function rehypeGitHub(repoDataMap) {
|
|
|
290
626
|
* Transform GitHub components in HTML.
|
|
291
627
|
*/
|
|
292
628
|
async function transformGitHub(html, repoDataMap, options) {
|
|
629
|
+
const mergedOptions = {
|
|
630
|
+
...defaultOptions,
|
|
631
|
+
...options
|
|
632
|
+
};
|
|
293
633
|
let dataMap = repoDataMap;
|
|
294
|
-
if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html),
|
|
295
|
-
const
|
|
634
|
+
if (!dataMap) dataMap = await prefetchGitHubRepos(await collectGitHubRepos(html), mergedOptions);
|
|
635
|
+
const sourceDataMap = await prefetchGitHubSources(await collectGitHubSources(html), mergedOptions);
|
|
636
|
+
const result = await (0, unified.unified)().use(rehype_parse.default, { fragment: true }).use(rehypeGitHub, dataMap, sourceDataMap, mergedOptions).use(rehype_stringify.default).process(html);
|
|
296
637
|
return String(result);
|
|
297
638
|
}
|
|
298
639
|
//#endregion
|
|
@@ -302,6 +643,18 @@ Object.defineProperty(exports, "collectGitHubRepos", {
|
|
|
302
643
|
return collectGitHubRepos;
|
|
303
644
|
}
|
|
304
645
|
});
|
|
646
|
+
Object.defineProperty(exports, "collectGitHubSources", {
|
|
647
|
+
enumerable: true,
|
|
648
|
+
get: function() {
|
|
649
|
+
return collectGitHubSources;
|
|
650
|
+
}
|
|
651
|
+
});
|
|
652
|
+
Object.defineProperty(exports, "fetchGitHubSource", {
|
|
653
|
+
enumerable: true,
|
|
654
|
+
get: function() {
|
|
655
|
+
return fetchGitHubSource;
|
|
656
|
+
}
|
|
657
|
+
});
|
|
305
658
|
Object.defineProperty(exports, "fetchRepoData", {
|
|
306
659
|
enumerable: true,
|
|
307
660
|
get: function() {
|
|
@@ -314,12 +667,30 @@ Object.defineProperty(exports, "github_exports", {
|
|
|
314
667
|
return github_exports;
|
|
315
668
|
}
|
|
316
669
|
});
|
|
670
|
+
Object.defineProperty(exports, "parseGitHubLineRange", {
|
|
671
|
+
enumerable: true,
|
|
672
|
+
get: function() {
|
|
673
|
+
return parseGitHubLineRange;
|
|
674
|
+
}
|
|
675
|
+
});
|
|
676
|
+
Object.defineProperty(exports, "parseGitHubPermalink", {
|
|
677
|
+
enumerable: true,
|
|
678
|
+
get: function() {
|
|
679
|
+
return parseGitHubPermalink;
|
|
680
|
+
}
|
|
681
|
+
});
|
|
317
682
|
Object.defineProperty(exports, "prefetchGitHubRepos", {
|
|
318
683
|
enumerable: true,
|
|
319
684
|
get: function() {
|
|
320
685
|
return prefetchGitHubRepos;
|
|
321
686
|
}
|
|
322
687
|
});
|
|
688
|
+
Object.defineProperty(exports, "prefetchGitHubSources", {
|
|
689
|
+
enumerable: true,
|
|
690
|
+
get: function() {
|
|
691
|
+
return prefetchGitHubSources;
|
|
692
|
+
}
|
|
693
|
+
});
|
|
323
694
|
Object.defineProperty(exports, "transformGitHub", {
|
|
324
695
|
enumerable: true,
|
|
325
696
|
get: function() {
|
package/dist/github.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"github.cjs","names":["rehypeParse","rehypeStringify"],"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);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAmCA,MAAM,iBAA0C;CAC9C,OAAO;CACP,OAAO;CACP,UAAU;CACX;AAGD,MAAM,4BAAY,IAAI,KAA0D;AAChF,MAAM,iBA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AO,OAAO"}
|
|
1
|
+
{"version":3,"file":"github.cjs","names":["Buffer","rehypeParse","rehypeStringify"],"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,OAAO;CAChB,CAAC,OAAO,OAAO;CAChB,CAAC;AAEF,SAAgB,iBAAiB,MAAuB;AACtD,QACE,eAAe,KA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