Skip to content

Commit 1d0c518

Browse files
committed
DOC-13760 create an initial llms.txt
1 parent 974763a commit 1d0c518

File tree

1 file changed

+60
-4
lines changed

1 file changed

+60
-4
lines changed

lib/markdown-for-llm.js

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
const {convertHtmlToMarkdown} = require('dom-to-semantic-markdown')
44
const {JSDOM} = require('jsdom')
5+
const File = require('vinyl')
56

67
function overrideElementProcessing (element) {
78

@@ -57,19 +58,19 @@ function toMarkdown (html) {
5758

5859
function markdownify(page) {
5960
const html = page.contents.toString()
61+
62+
const link = `[View original HTML](${page.pub.url})\n\n`
6063
const markdown = toMarkdown(html)
6164

6265
page.out.path = page.out.path.replace(/\.html$/, '.md')
63-
if (page.pub.url) {
64-
page.pub.url = page.pub.url.replace(/\.html$/, '.md')
65-
}
66+
page.pub.url = page.pub.url.replace(/\.html$/, '.md')
6667

6768
page.contents = Buffer.from(markdown)
6869
}
6970

7071
module.exports.register = function ({ playbook, config }) {
7172
this.once('contextStarted', () => {
72-
const { createPageComposer: _createPageComposerDelegate } = this.getFunctions()
73+
const { createPageComposer: _delegate } = this.getFunctions()
7374

7475
this.replaceFunctions({
7576
// see https://gitlab.com/antora/antora/-/blob/v3.1.x/packages/page-composer/lib/create-page-composer.js
@@ -108,4 +109,59 @@ module.exports.register = function ({ playbook, config }) {
108109
markdownify(page)
109110
}
110111
})
112+
this.once('beforePublish', async ({ siteCatalog }) => {
113+
const nav = siteCatalog.getFiles().find(
114+
file => file.path === '_/js/site-navigation-data.js').contents.toString()
115+
const match = nav.match(/^siteNavigationData=(.+)$/s);
116+
// This file is created by @antora/site-generator-ms
117+
// eslint-disable-next-line no-eval
118+
const navObj = eval(match[1])
119+
120+
let output = ''
121+
122+
output+=`# Couchbase
123+
124+
> This is the official documentation for Couchbase, a leading NoSQL distributed database platform
125+
> designed for high performance, scalability, and flexibility. The documentation covers comprehensive
126+
> guides for developers and operations teams, including installation and configuration, development
127+
> tutorials, API references, administration, security, cloud deployment, and integration with various
128+
> programming languages and frameworks. Couchbase enables applications to handle massive data volumes
129+
> and high concurrency with its memory-first architecture and flexible JSON document model.\n\n`
130+
131+
output+=`\n## Docs\n`
132+
133+
for (const c of navObj) {
134+
const v = c.versions[0]
135+
if (! v.sets.length) { continue }
136+
137+
const version = v.version.match(/\d\.\d/) ? `(${v.version})` : ''
138+
output += `\n\n### ${c.title} ${version}\n`
139+
140+
function process(item, level=0) {
141+
if (item.content) {
142+
const content = item.url ?
143+
`[${item.content}](${item.url})` :
144+
item.content
145+
146+
output+=`${' '.repeat(4*(level))}- ${content}\n`
147+
}
148+
const indent = item.content ? 1 : 0
149+
150+
for (const i of item.items || []) {
151+
process(i, level+indent)
152+
}
153+
}
154+
155+
process({ items: v.sets })
156+
const file = new File({
157+
contents: Buffer.from(output),
158+
mediaType: 'text/markdown',
159+
out: { path: 'llms.txt' },
160+
path: 'llms.txt',
161+
pub: { url: `/llms.txt`, rootPath: '' },
162+
src: { stem: 'llms' },
163+
})
164+
siteCatalog.addFile(file)
165+
}
166+
})
111167
}

0 commit comments

Comments
 (0)