Skip to content

Commit 32e80d7

Browse files
authored
Merge pull request #113 from raifdmueller/feature/link-llms-txt-and-all-anchors
feat: Render all-anchors.adoc in frontend via inlined web version
2 parents 8491b05 + 890b6a5 commit 32e80d7

3 files changed

Lines changed: 72 additions & 3 deletions

File tree

scripts/generate-llms-txt.js

Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,66 @@ function generateLlmsTxt() {
246246
console.warn(`Generated: website/public/llms.txt (${totalAnchors} anchors, ~${kb} KB)`)
247247
}
248248

249+
// ─── Generate website/public/docs/all-anchors.adoc (inlined, no includes) ────
250+
251+
/**
252+
* Shift AsciiDoc heading levels by offset (e.g. +1 turns = into ==)
253+
*/
254+
function shiftHeadings(content, offset) {
255+
return content.replace(/^(=+)( .+)$/gm, (_, eq, rest) => '='.repeat(eq.length + offset) + rest)
256+
}
257+
258+
/**
259+
* Strip document-level AsciiDoc attributes (:key: value) used as metadata
260+
*/
261+
function stripDocAttrs(content) {
262+
return content.replace(/^:[a-z][a-z0-9-]*:.*$/gm, '')
263+
}
264+
265+
function generateAllAnchorsWebAdoc() {
266+
const WEB_DOCS = path.join(ROOT, 'website/public/docs')
267+
fs.mkdirSync(WEB_DOCS, { recursive: true })
268+
269+
const lines = [
270+
'= Semantic Anchors — Complete Reference',
271+
':toc:',
272+
':toc-placement: preamble',
273+
':toclevels: 2',
274+
'',
275+
]
276+
277+
const aboutPath = path.join(ROOT, 'docs/about.adoc')
278+
if (fs.existsSync(aboutPath)) {
279+
const aboutContent = fs.readFileSync(aboutPath, 'utf-8')
280+
lines.push(shiftHeadings(stripDocAttrs(aboutContent), 1))
281+
lines.push('')
282+
lines.push("'''")
283+
lines.push('')
284+
}
285+
286+
for (const category of categories) {
287+
lines.push(`== ${category.name}`)
288+
lines.push('')
289+
for (const anchorId of category.anchors) {
290+
const filepath = path.join(ROOT, 'docs/anchors', `${anchorId}.adoc`)
291+
if (fs.existsSync(filepath)) {
292+
const anchorContent = fs.readFileSync(filepath, 'utf-8')
293+
lines.push(shiftHeadings(stripDocAttrs(anchorContent), 2))
294+
lines.push('')
295+
}
296+
}
297+
lines.push("'''")
298+
lines.push('')
299+
}
300+
301+
const output = lines.join('\n')
302+
fs.writeFileSync(path.join(WEB_DOCS, 'all-anchors.adoc'), output, 'utf-8')
303+
const kb = Math.round(Buffer.byteLength(output, 'utf-8') / 1024)
304+
console.warn(`Generated: website/public/docs/all-anchors.adoc (~${kb} KB, inlined)`)
305+
}
306+
249307
// ─── Main ────────────────────────────────────────────────────────────────────
250308

251309
generateAllAnchorsAdoc()
310+
generateAllAnchorsWebAdoc()
252311
generateLlmsTxt()

website/src/components/footer.js

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,7 @@ export function renderFooter(version) {
3131
>${i18n.t('footer.llmsTxt')}</a>
3232
<span class="text-gray-300 dark:text-gray-600">|</span>
3333
<a
34-
href="https://github.com/LLM-Coding/Semantic-Anchors/blob/main/docs/all-anchors.adoc"
35-
target="_blank"
36-
rel="noopener noreferrer"
34+
href="#/all-anchors"
3735
class="text-sm text-[var(--color-text-secondary)] hover:text-[var(--color-text)] transition-colors"
3836
data-i18n="footer.allAnchors"
3937
>${i18n.t('footer.allAnchors')}</a>

website/src/main.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ function initApp() {
9797
addRoute('/', renderHomePage)
9898
addRoute('/about', renderAboutPage)
9999
addRoute('/contributing', renderContributingPage)
100+
addRoute('/all-anchors', renderAllAnchorsPage)
100101

101102
const app = document.querySelector('#app')
102103
if (!app) return
@@ -161,6 +162,15 @@ function renderContributingPage() {
161162
loadDocContent('CONTRIBUTING.adoc')
162163
}
163164

165+
function renderAllAnchorsPage() {
166+
const pageContent = document.getElementById('page-content')
167+
if (!pageContent) return
168+
169+
pageContent.innerHTML = renderDocPage('Full Reference')
170+
updateActiveNavLink()
171+
loadDocContent('docs/all-anchors.adoc')
172+
}
173+
164174
function updateActiveNavLink() {
165175
const currentRoute = window.location.hash.slice(1) || '/'
166176
document.querySelectorAll('.nav-link').forEach((link) => {
@@ -282,6 +292,8 @@ function handleLanguageChange() {
282292
loadDocContent('docs/about.adoc')
283293
} else if (currentRoute === '/contributing') {
284294
loadDocContent('CONTRIBUTING.adoc')
295+
} else if (currentRoute === '/all-anchors') {
296+
loadDocContent('docs/all-anchors.adoc')
285297
} else if (currentRoute === '/') {
286298
initCardGridVisualization()
287299
}

0 commit comments

Comments
 (0)