Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 37 additions & 2 deletions website/.vitepress/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ function escapeVueSyntax(src: string): string {
}).join('\n')
}

const KNOWN_TAGS = /^<\/?(?:a|abbr|address|area|article|aside|audio|b|base|bdi|bdo|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|data|datalist|dd|del|details|dfn|dialog|div|dl|dt|em|embed|fieldset|figcaption|figure|footer|form|h[1-6]|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|label|legend|li|link|main|map|mark|menu|meta|meter|nav|noscript|object|ol|optgroup|option|output|p|param|picture|pre|progress|q|rp|rt|ruby|s|samp|script|search|section|select|slot|small|source|span|strong|style|sub|summary|sup|table|tbody|td|template|textarea|tfoot|th|thead|time|title|tr|track|u|ul|var|video|wbr|svg|path|g|circle|rect|line|polyline|polygon|text|defs|use|symbol)[\s>\/!]/i
const KNOWN_TAGS = /^<\/?(?:a|abbr|address|area|article|aside|audio|b|base|bdi|bdo|blockquote|body|br|button|canvas|caption|cite|code|col|colgroup|data|datalist|dd|del|details|dfn|dialog|div|dl|dt|em|embed|fieldset|figcaption|figure|footer|form|h[1-6]|head|header|hgroup|hr|html|i|iframe|img|input|ins|kbd|label|legend|li|link|main|map|mark|menu|meta|meter|nav|noscript|object|ol|optgroup|option|output|p|param|picture|pre|progress|q|rp|rt|ruby|s|samp|script|search|section|select|slot|small|source|span|strong|style|sub|summary|sup|table|tbody|td|template|textarea|tfoot|th|thead|time|title|tr|track|u|ul|var|video|wbr|svg|path|g|circle|rect|line|polyline|polygon|text|defs|use|symbol)[\s>/!]/i

function escapeLine(line: string): string {
let result = ''
Expand Down Expand Up @@ -316,7 +316,7 @@ export default defineConfig({
},
preConfig: (md) => {
const defaultParse = md.parse.bind(md)
md.parse = (src: string, env: any) => {
md.parse = (src: string, env: Record<string, unknown>) => {
return defaultParse(escapeVueSyntax(src), env)
}
},
Expand All @@ -330,6 +330,41 @@ export default defineConfig({
return defaultCodeInline(tokens, idx, options, env, self)
}

// Rewrite relative links that escape the docs/ directory to GitHub
// source URLs, and rewrite README.md links to directory index paths
// (only for links that stay within docs/).
md.core.ruler.push('rewrite-links', (state) => {
for (const token of state.tokens) {
if (!token.children) continue
for (const child of token.children) {
if (child.type !== 'link_open') continue
const href = child.attrGet('href')
if (!href || href.startsWith('http') || href.startsWith('#') || href.startsWith('mailto:')) continue

// Check if the link escapes docs/ (more ../ than directory depth)
const docPath = state.env?.relativePath || ''
const docDir = docPath.split('/').slice(0, -1)
const parts = href.split('#')
const linkPath = parts[0]
const anchor = parts[1] ? '#' + parts[1] : ''
const segments = linkPath.split('/')
let depth = 0
for (const s of segments) { if (s === '..') depth++; else break }
if (depth > docDir.length) {
const remainder = segments.slice(depth).join('/')
const prefix = /\.[a-zA-Z0-9]+$/.test(remainder) && !remainder.endsWith('/') ? 'blob' : 'tree'
child.attrSet('href', `https://github.com/fullsend-ai/fullsend/${prefix}/main/${remainder}${anchor}`)
continue
}
Comment thread
waynesun09 marked this conversation as resolved.

// For links staying within docs/, rewrite README.md to directory index
if (/README\.md(#.*)?$/.test(href)) {
child.attrSet('href', href.replace(/README\.md(#.*)?$/, (_: string, a: string) => a || './'))
}
}
}
})

const defaultFence = md.renderer.rules.fence!.bind(md.renderer.rules)
md.renderer.rules.fence = (tokens, idx, options, env, self) => {
if (tokens[idx].info.trim() === 'mermaid') {
Expand Down
Loading