mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-08 19:06:15 -08:00
refactor(docs): [SITE-AI-DOCS-01] make generation offline and translation draft based
This commit is contained in:
1 parent
647f3e7f12
commit
078cd9ef72
27 files changed
+8642
-4263
No files matched your search
@@ -0,0 +1,88 @@
|
||||
import assert from 'node:assert/strict'
|
||||
import { globSync } from 'glob'
|
||||
import ts from 'typescript'
|
||||
import { ownedPath, read, sha256 } from './files.ts'
|
||||
|
||||
export function buildCorpus(root: string): Map<string, string> {
|
||||
const common = ts.createSourceFile(
|
||||
'common.js',
|
||||
read(ownedPath(root, 'docs/assets/js/common.js')),
|
||||
ts.ScriptTarget.Latest,
|
||||
true,
|
||||
ts.ScriptKind.JS,
|
||||
)
|
||||
const declarations: string[] = []
|
||||
let lists = 0
|
||||
function visit(node: ts.Node): void {
|
||||
if (
|
||||
ts.isVariableDeclaration(node)
|
||||
&& ts.isIdentifier(node.name)
|
||||
&& node.name.text === 'libUris'
|
||||
) {
|
||||
lists++
|
||||
assert(
|
||||
node.initializer && ts.isArrayLiteralExpression(node.initializer),
|
||||
'Expected literal editor library list',
|
||||
)
|
||||
for (const element of node.initializer.elements) {
|
||||
assert(
|
||||
ts.isStringLiteral(element)
|
||||
&& /^\.\/assets\/ts\/[\w.-]+\.d\.ts$/.test(element.text),
|
||||
'Unexpected editor library path',
|
||||
)
|
||||
declarations.push(`docs/${element.text.slice(2)}`)
|
||||
}
|
||||
}
|
||||
ts.forEachChild(node, visit)
|
||||
}
|
||||
visit(common)
|
||||
assert(
|
||||
lists === 1
|
||||
&& declarations.length
|
||||
&& new Set(declarations).size === declarations.length,
|
||||
'Missing or duplicate editor library list',
|
||||
)
|
||||
const sections = [
|
||||
{
|
||||
title: 'Documentation Summary',
|
||||
files: globSync('packages/artplayer-vitepress/docs/en/**/*.md', {
|
||||
cwd: root,
|
||||
posix: true,
|
||||
}).sort(),
|
||||
},
|
||||
{ title: 'Type Definitions Overview', files: declarations },
|
||||
{
|
||||
title: 'Examples Summary',
|
||||
files: globSync('docs/assets/example/*.js', {
|
||||
cwd: root,
|
||||
posix: true,
|
||||
}).sort(),
|
||||
},
|
||||
{
|
||||
title: 'Third-party Type Notices',
|
||||
files: ['docs/assets/ts/artplayer-plugin-vast.LICENSE.txt'],
|
||||
},
|
||||
]
|
||||
const sources: { file: string, sha256Lf: string }[] = []
|
||||
let text
|
||||
= 'ArtPlayer documentation source bundle\nGenerated offline by yarn build:llm. Source text is preserved after LF normalization.\nThese are source references, not proof that every example or documented feature has passed release review.\n'
|
||||
for (const section of sections) {
|
||||
assert(
|
||||
section.files.length,
|
||||
`Empty documentation section: ${section.title}`,
|
||||
)
|
||||
text += `\n===== ${section.title} =====\n`
|
||||
for (const file of section.files) {
|
||||
const content = read(ownedPath(root, file))
|
||||
sources.push({ file, sha256Lf: sha256(content) })
|
||||
text += `\n===== ${file} =====\n\n${content}\n`
|
||||
}
|
||||
}
|
||||
return new Map([
|
||||
['docs/llms.txt', text],
|
||||
[
|
||||
'docs/llms.manifest.json',
|
||||
`${JSON.stringify({ schemaVersion: 1, generation: 'offline-source-preserving', sources, outputSha256Lf: sha256(text) }, null, 2)}\n`,
|
||||
],
|
||||
])
|
||||
}
|
||||
Reference in new issue
Block a user