Files
clawsec/utils/wikiPathHelpers.mjs
T
davida-ps fefecaa60a feat(wiki): add full in-app wiki browser and llms index (#80)
* 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
2026-02-26 10:43:36 +02:00

39 lines
1022 B
JavaScript

/**
* Normalize a wiki slug for route/path construction.
* @param {string} slug
* @returns {string}
*/
const normalizeWikiSlug = (slug) =>
String(slug ?? '')
.replace(/\\/g, '/')
.replace(/^\/+|\/+$/g, '');
/**
* Return whether a slug represents the wiki index page.
* @param {string} slug
* @returns {boolean}
*/
export const isWikiIndexSlug = (slug) => normalizeWikiSlug(slug).toLowerCase() === 'index';
/**
* Convert a wiki slug to app route path.
* @param {string} slug
* @returns {string}
*/
export const toWikiRoute = (slug) => {
const normalized = normalizeWikiSlug(slug);
if (!normalized || isWikiIndexSlug(normalized)) return '/wiki';
return `/wiki/${normalized}`;
};
/**
* Convert a wiki slug to its llms.txt endpoint path.
* @param {string} slug
* @returns {string}
*/
export const toWikiLlmsPath = (slug) => {
const normalized = normalizeWikiSlug(slug);
if (!normalized || isWikiIndexSlug(normalized)) return '/wiki/llms.txt';
return `/wiki/${normalized}/llms.txt`;
};