Publish curated Knowledge Hub source from 2ed833f290b439a7bc91e5fd19b042c269e3bee9
This commit is contained in:
1 parent
10f2edcd29
commit
59f15b2d08
218 files changed
+23995
-1849
No files matched your search
@@ -28,4 +28,49 @@ if (!Array.isArray(manifest.files) || manifest.files.length === 0) {
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Public source structure passed (${manifest.files.length} allowlisted files).`);
|
||||
const markdownFiles = [];
|
||||
function walkMarkdown(directory) {
|
||||
for (const entry of fs.readdirSync(directory, { withFileTypes: true })) {
|
||||
if ([".git", "node_modules", "__pycache__"].includes(entry.name)) continue;
|
||||
const fullPath = path.join(directory, entry.name);
|
||||
if (entry.isDirectory()) walkMarkdown(fullPath);
|
||||
else if (entry.isFile() && entry.name.toLowerCase().endsWith(".md")) markdownFiles.push(fullPath);
|
||||
}
|
||||
}
|
||||
|
||||
function stripCode(markdown) {
|
||||
const withoutFences = markdown.replace(/```[\s\S]*?```|~~~[\s\S]*?~~~/g, (block) =>
|
||||
block.replace(/[^\n]/g, " "));
|
||||
return withoutFences.replace(/`[^`\n]*`/g, (span) => " ".repeat(span.length));
|
||||
}
|
||||
|
||||
walkMarkdown(process.cwd());
|
||||
const errors = [];
|
||||
const linkPattern = /\[[^\]]+\]\(([^)]+)\)/g;
|
||||
for (const markdownFile of markdownFiles) {
|
||||
const content = stripCode(fs.readFileSync(markdownFile, "utf8"));
|
||||
for (const match of content.matchAll(linkPattern)) {
|
||||
let target = match[1].trim();
|
||||
if (target.startsWith("#") || /^[a-z][a-z0-9+.-]*:/i.test(target) || target.startsWith("//")) continue;
|
||||
target = target.split("#", 1)[0].split("?", 1)[0];
|
||||
if (!target) continue;
|
||||
try {
|
||||
target = decodeURIComponent(target);
|
||||
} catch {
|
||||
errors.push(`Could not URL-decode link in ${path.relative(process.cwd(), markdownFile)}: ${target}`);
|
||||
continue;
|
||||
}
|
||||
const resolved = path.resolve(path.dirname(markdownFile), target);
|
||||
if (!fs.existsSync(resolved)) {
|
||||
errors.push(`Broken local Markdown link in ${path.relative(process.cwd(), markdownFile)}: ${match[1]}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (errors.length > 0) {
|
||||
console.error("Public source validation failed:");
|
||||
for (const error of errors) console.error(`- ${error}`);
|
||||
process.exit(1);
|
||||
}
|
||||
|
||||
console.log(`Public source structure passed (${manifest.files.length} allowlisted files, ${markdownFiles.length} Markdown files, local links resolved).`);
|
||||
Reference in new issue
Block a user