Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions website/scripts/sandboxes.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import {
cp,
glob,
rm
readFile,
rm,
writeFile
} from 'node:fs/promises'
import {
join,
Expand All @@ -12,6 +14,20 @@ import {
const sandboxesRoot = new URL('../../sandboxes/', import.meta.url).pathname
const targetRoot = new URL('../public/sandboxes/', import.meta.url).pathname

// A sandbox alone is a chart without text, so search engines should index the example that embeds it.
// Only the copy changes: StackBlitz opens the sandbox from the repository as it is
async function hideFromSearch(page, sandbox) {
const html = await readFile(page, 'utf8')

if (!html.includes('</head>')) {
throw new Error(`No </head> in ${page}`)
}

const title = html.includes('<title>') ? '' : `<title>Preview of the ${sandbox} example</title>`

await writeFile(page, html.replace('</head>', `<meta name="robots" content="noindex" />${title}</head>`))
}

await rm(targetRoot, {
recursive: true,
force: true
Expand All @@ -21,10 +37,12 @@ let count = 0

for await (const dist of glob(join(sandboxesRoot, '*/*/dist'))) {
const sandbox = relative(sandboxesRoot, dist).replace(/\/dist$/, '')
const target = join(targetRoot, sandbox)

await cp(dist, join(targetRoot, sandbox), {
await cp(dist, target, {
recursive: true
})
await hideFromSearch(join(target, 'index.html'), sandbox)
count++
}

Expand Down