diff --git a/docs/.eleventy.js b/docs/.eleventy.js index 50d40f039..02f3a1e6f 100644 --- a/docs/.eleventy.js +++ b/docs/.eleventy.js @@ -153,6 +153,15 @@ export default function (eleventyConfig) { ]), ); + eleventyConfig.addPreprocessor('unpublished', '*', (data, content) => { + if (data.unpublished && process.env.ELEVENTY_RUN_MODE === 'build') { + // Exclude "unpublished" pages from final builds. + return false; + } + + return content; + }); + // Build the search index eleventyConfig.addPlugin( searchPlugin({ diff --git a/docs/_includes/head.njk b/docs/_includes/head.njk index 215699f92..3f3a2668e 100644 --- a/docs/_includes/head.njk +++ b/docs/_includes/head.njk @@ -1,7 +1,7 @@ -{% if noindex %}{% endif %} +{% if noindex or unlisted %}{% endif %} {{ title }} diff --git a/docs/_utils/search.js b/docs/_utils/search.js index 7fb567712..90d06c40e 100644 --- a/docs/_utils/search.js +++ b/docs/_utils/search.js @@ -24,9 +24,23 @@ export function searchPlugin(options = {}) { }; return function (eleventyConfig) { - const pagesToIndex = []; + const pagesToIndex = new Map(); + + eleventyConfig.addPreprocessor('exclude-unlisted-from-search', '*', function (data, content) { + if (data.unlisted) { + // no-op + } else { + pagesToIndex.set(data.page.inputPath, {}); + } + + return content; + }); eleventyConfig.addTransform('search', function (content) { + if (!pagesToIndex.has(this.page.inputPath)) { + return content; + } + const doc = parse(content, { blockTextElements: { script: false, @@ -42,7 +56,7 @@ export function searchPlugin(options = {}) { doc.querySelectorAll(selector).forEach(el => el.remove()); }); - pagesToIndex.push({ + pagesToIndex.set(this.page.inputPath, { title: collapseWhitespace(options.getTitle(doc)), description: collapseWhitespace(options.getDescription(doc)), headings: options.getHeadings(doc).map(collapseWhitespace), @@ -65,7 +79,7 @@ export function searchPlugin(options = {}) { this.field('h', { boost: 10 }); this.field('c'); - for (const page of pagesToIndex) { + for (const [_inputPath, page] of pagesToIndex) { this.add({ id: index, t: page.title, h: page.headings, c: page.content }); map[index] = { title: page.title, description: page.description, url: page.url }; index++; diff --git a/docs/docs/components/cheatsheet/index.njk b/docs/docs/components/cheatsheet/index.njk index 6a84aba51..ab597156f 100644 --- a/docs/docs/components/cheatsheet/index.njk +++ b/docs/docs/components/cheatsheet/index.njk @@ -1,7 +1,7 @@ --- title: Component Cheatsheet layout: docs -unlisted: true +unpublished: true ---