mirror of
https://github.com/prompt-security/clawsec.git
synced 2026-06-13 05:28:02 +03:00
fefecaa60a
* feat(wiki): add full in-app wiki browser and llms index * feat(wiki): auto-generate per-page llms exports * vuln package * fix(wiki): guard malformed route decoding * fix(wiki): preserve markdown anchor fragments across page links * refactor(markdown): share default render components * fix(wiki): block unsafe markdown link schemes * fix(wiki): block unsafe markdown image schemes * docs(wiki): migrate root docs into wiki pages * chore(wiki): de-track generated llms exports * chore(wiki): ignore generated public wiki artifacts * fix(wiki): align llms urls with per-page endpoint pattern * fix(wiki): derive llms index from wiki index page * refactor(markdown): share frontmatter and title helpers * refactor(wiki): share route and llms path mapping * ci(pages): add pr verify workflow and tighten deploy triggers
41 lines
1.2 KiB
JavaScript
41 lines
1.2 KiB
JavaScript
const FRONTMATTER_REGEX = /^---\s*\n[\s\S]*?\n---\s*\n/;
|
|
|
|
/**
|
|
* Remove a leading YAML frontmatter block from markdown content.
|
|
* @param {string} content
|
|
* @returns {string}
|
|
*/
|
|
export const stripFrontmatter = (content) =>
|
|
String(content ?? '').replace(FRONTMATTER_REGEX, '');
|
|
|
|
/**
|
|
* Build a readable fallback title from a markdown file path.
|
|
* @param {string} filePath
|
|
* @returns {string}
|
|
*/
|
|
export const fallbackTitleFromPath = (filePath) => {
|
|
const normalized = String(filePath ?? '');
|
|
const filename = normalized.split('/').pop() ?? normalized;
|
|
const stem = filename.replace(/\.md$/i, '');
|
|
return stem
|
|
.split(/[-_]/)
|
|
.filter(Boolean)
|
|
.map((part) => {
|
|
if (part.toUpperCase() === part && part.length > 1) return part;
|
|
return part.charAt(0).toUpperCase() + part.slice(1);
|
|
})
|
|
.join(' ');
|
|
};
|
|
|
|
/**
|
|
* Extract the first H1 title from markdown; fall back to path-derived title.
|
|
* @param {string} content
|
|
* @param {string} filePath
|
|
* @returns {string}
|
|
*/
|
|
export const extractTitleFromMarkdown = (content, filePath) => {
|
|
const cleaned = stripFrontmatter(content).trim();
|
|
const match = cleaned.match(/^#\s+(.+)$/m);
|
|
return match?.[1]?.trim() || fallbackTitleFromPath(filePath);
|
|
};
|