diff --git a/website/scripts/sandboxes.js b/website/scripts/sandboxes.js index 6797a6267..ca5a8cbad 100644 --- a/website/scripts/sandboxes.js +++ b/website/scripts/sandboxes.js @@ -1,7 +1,9 @@ import { cp, glob, - rm + readFile, + rm, + writeFile } from 'node:fs/promises' import { join, @@ -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('')) { + throw new Error(`No in ${page}`) + } + + const title = html.includes('') ? '' : `<title>Preview of the ${sandbox} example` + + await writeFile(page, html.replace('', `${title}`)) +} + await rm(targetRoot, { recursive: true, force: true @@ -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++ }