diff --git a/scripts/stage-port-docs.mjs b/scripts/stage-port-docs.mjs index cec96bf13..b6135cab5 100644 --- a/scripts/stage-port-docs.mjs +++ b/scripts/stage-port-docs.mjs @@ -303,6 +303,11 @@ export function stagedPortGuides(port, artifact) { const guides = new Map((artifact.guides ?? []).map((guide) => [guide.path, guide.content])) const files = new Map() const descriptions = new Map() + const checkoutGuidePaths = new Set(port === 'lua' ? artifact.checkoutGuidePaths : undefined) + const sourceFor = (path) => ({ + repo: artifact.source.repository, path, + ...(checkoutGuidePaths.has(path) ? { workingCopy: true } : { ref: artifact.source.revision }), + }) const titles = new Map(Object.entries(routes).map(([path, entry]) => [entry.route, entry.title ?? titleAndBody(guides.get(path) ?? '', path).title])) for (const [sourcePath, guide] of Object.entries(routes)) { const { route, product, package: packageId, domain, aliases, equivalence, sidebar } = guide @@ -327,7 +332,7 @@ export function stagedPortGuides(port, artifact) { ...(aliases.length ? { aliases } : {}), ...(equivalence ? { equivalence } : {}), route, - source: { repo: artifact.source.repository, path: sourcePath, ref: artifact.source.revision }, + source: sourceFor(sourcePath), sidebar: sidebar ?? { group: product ? (product === 'mcp' ? 'MCP' : 'Workspace Manager') : route === 'reference' ? 'API reference' : route.split('/')[0].replace(/^./, (letter) => letter.toUpperCase()) }, } @@ -336,7 +341,7 @@ export function stagedPortGuides(port, artifact) { files.set(`${port}/${route}/index.md`, `---\n${frontmatter}\n---\n\n${rewritten.trim()}\n`) } { - const source = { repo: artifact.source.repository, path: Object.keys(routes)[0], ref: artifact.source.revision } + const source = sourceFor(Object.keys(routes)[0]) const writeIndex = (route, title, body, cards = []) => { const data = { title, description: leadSentence(body) || `${title} for ${identity.packageName}.`, port, route, source, cards, sidebar: { group: route === 'reference' ? 'API reference' : route[0].toUpperCase() + route.slice(1), label: 'Overview', order: 1 } } @@ -421,7 +426,7 @@ function linkDocumenter(content, source) { } /** Read the integrated commit even when a contributor's working tree has advanced. */ -export function artifactFromRevision(port, checkout, revision) { +export function artifactFromRevision(port, checkout, revision, { allowMissing = false } = {}) { if (!/^[a-f0-9]{40}$/.test(revision)) throw new Error(`${port.slug}: invalid integrated source revision`) const git = (...args) => execFileSync('git', ['-C', checkout, ...args], { encoding: 'utf8', stdio: 'pipe' }) try { @@ -439,6 +444,10 @@ export function artifactFromRevision(port, checkout, revision) { for (const path of paths) { const end = blobs.indexOf(10, offset) const header = blobs.subarray(offset, end).toString('ascii') + if (end >= offset && allowMissing && header === `${revision}:${path} missing`) { + offset = end + 1 + continue + } const match = /^[a-f0-9]{40} blob (\d+)$/.exec(header) const size = match && Number(match[1]) if (end < offset || size === null || !Number.isSafeInteger(size) || size < 0 || @@ -452,11 +461,26 @@ export function artifactFromRevision(port, checkout, revision) { const readSource = (file) => contents.get(file) ?? git('show', `${revision}:${file}`) return { source: { repository: port.repo, revision }, - guides: paths.map((path) => { - const content = readSource(path) - return { path, content: port.slug === 'julia' ? expandDocumenter(content, path, readSource) : content } - }), + guides: [...contents].map(([path, content]) => ({ + path, content: port.slug === 'julia' ? expandDocumenter(content, path, readSource) : content, + })), + } +} + +function luaCheckoutGuides(port, checkout, artifact) { + const { revision } = artifact.source + const pinned = artifactFromRevision(port, checkout, revision, { allowMissing: true }) + const contents = new Map(pinned.guides.map(({ path, content }) => [path, content])) + const checkoutGuidePaths = [] + for (const { path, content } of artifact.guides ?? []) { + if (!Object.hasOwn(ROUTES.lua, path) || typeof content !== 'string' || contents.get(path) === content) continue + const file = join(checkout, path) + if (!existsSync(file) || readFileSync(file, 'utf8') !== content) { + throw new Error(`lua: exported guide ${path} differs from both ${revision} and ${file}. Regenerate docs/_build/api.json from the selected checkout.`) + } + checkoutGuidePaths.push(path) } + return checkoutGuidePaths.length ? { ...artifact, checkoutGuidePaths } : artifact } export function run() { @@ -495,12 +519,14 @@ export function run() { if (expected && artifact.source?.revision !== expected) { throw new Error(`${port.slug}: expected source ${expected}, artifact records ${artifact.source?.revision}`) } + const stagingArtifact = port.slug === 'lua' && !cached && !integrated && !fromSource && existsSync(join(checkout, '.git')) + ? luaCheckoutGuides(port, checkout, artifact) : artifact if (!check && (refreshCache || selectedSource)) { mkdirSync(cacheRoot, { recursive: true }) - const content = `${JSON.stringify(artifact, null, 2)}\n` + const content = `${JSON.stringify(stagingArtifact, null, 2)}\n` if (!existsSync(cachePath) || readFileSync(cachePath, 'utf8') !== content) writeFileSync(cachePath, content) } - for (const [file, content] of stagedPortGuides(port.slug, artifact)) generated.set(file, content) + for (const [file, content] of stagedPortGuides(port.slug, stagingArtifact)) generated.set(file, content) } const actual = new Map() diff --git a/site/src/components/SiteFooter.astro b/site/src/components/SiteFooter.astro index 633c426db..d18b9edd4 100644 --- a/site/src/components/SiteFooter.astro +++ b/site/src/components/SiteFooter.astro @@ -32,6 +32,7 @@ interface Props { const { locale, port, version, pagePath, source, markdownHref, llmsRoot, githubUrl, flush = false, compact = false } = Astro.props const inventories = inventoryLinks(port, version, pagePath) +const rawSource = source && rawSourceUrl(source) ---