|
2 | 2 |
|
3 | 3 | const {convertHtmlToMarkdown} = require('dom-to-semantic-markdown') |
4 | 4 | const {JSDOM} = require('jsdom') |
| 5 | +const File = require('vinyl') |
5 | 6 |
|
6 | 7 | function overrideElementProcessing (element) { |
7 | 8 |
|
@@ -57,19 +58,19 @@ function toMarkdown (html) { |
57 | 58 |
|
58 | 59 | function markdownify(page) { |
59 | 60 | const html = page.contents.toString() |
| 61 | + |
| 62 | + const link = `[View original HTML](${page.pub.url})\n\n` |
60 | 63 | const markdown = toMarkdown(html) |
61 | 64 |
|
62 | 65 | 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') |
66 | 67 |
|
67 | 68 | page.contents = Buffer.from(markdown) |
68 | 69 | } |
69 | 70 |
|
70 | 71 | module.exports.register = function ({ playbook, config }) { |
71 | 72 | this.once('contextStarted', () => { |
72 | | - const { createPageComposer: _createPageComposerDelegate } = this.getFunctions() |
| 73 | + const { createPageComposer: _delegate } = this.getFunctions() |
73 | 74 |
|
74 | 75 | this.replaceFunctions({ |
75 | 76 | // 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 }) { |
108 | 109 | markdownify(page) |
109 | 110 | } |
110 | 111 | }) |
| 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 | + }) |
111 | 167 | } |
0 commit comments