From cd69d5de3e91a37a5a7733980cd1953de52d8768 Mon Sep 17 00:00:00 2001 From: Dmitry Matiouchenko Date: Wed, 23 Aug 2023 17:04:44 -0700 Subject: [PATCH 1/3] feat: support noIndex bool in frontmatter --- packages/gatsby-theme-aio/algolia/index-records.js | 8 ++++++-- packages/gatsby-theme-aio/algolia/mdx-query.js | 1 + packages/gatsby-theme-aio/gatsby-node.js | 6 +++++- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/packages/gatsby-theme-aio/algolia/index-records.js b/packages/gatsby-theme-aio/algolia/index-records.js index 3435b44908..b340cfaffc 100644 --- a/packages/gatsby-theme-aio/algolia/index-records.js +++ b/packages/gatsby-theme-aio/algolia/index-records.js @@ -25,7 +25,7 @@ function indexRecords(isDryRun) { query: mdxQuery, transformer: async function ({ data: { - site: { pathPrefix }, + site: { pathPrefix, noIndexList }, github: { repository }, allFile: { nodes }, }, @@ -49,6 +49,10 @@ function indexRecords(isDryRun) { const markdownFiles = []; for (const node of nodes) { + + // skip file if noIndex is set true in frontmatter + if (node.childMdx.frontmatter.noIndex) continue; + markdownFiles.push({ birthTime: node.birthTime, category: node.childMdx.frontmatter.category, @@ -108,7 +112,7 @@ function indexRecords(isDryRun) { console.info( `- \x1b[42m${passCount} Pages have Title, Description, and Keywords\x1b[0m` ); - // Implement an Error or prompt to user when attempting to index frontmatter-less files + // Implement an Error or prompt to user when attempting to index frontmatter-less files if (warnCount) console.error(`\x1b[41m${warnCount} Pages are missing frontmatter\x1b[0m`); } diff --git a/packages/gatsby-theme-aio/algolia/mdx-query.js b/packages/gatsby-theme-aio/algolia/mdx-query.js index 7c26c9ccc6..7aa45bd3ad 100644 --- a/packages/gatsby-theme-aio/algolia/mdx-query.js +++ b/packages/gatsby-theme-aio/algolia/mdx-query.js @@ -50,6 +50,7 @@ const mdxQuery = ` hideBreadcrumbNav contributor_name contributor_link + noIndex } headings { value diff --git a/packages/gatsby-theme-aio/gatsby-node.js b/packages/gatsby-theme-aio/gatsby-node.js index f5fb3b20cb..360ad82074 100644 --- a/packages/gatsby-theme-aio/gatsby-node.js +++ b/packages/gatsby-theme-aio/gatsby-node.js @@ -184,7 +184,7 @@ exports.createResolvers = ({ createResolvers }) => { }, contributors: { type: '[String]', - resolve: source => source.contributors + resolve: source => source.contributors, }, contributor_link: { type: 'String', @@ -226,6 +226,10 @@ exports.createResolvers = ({ createResolvers }) => { type: 'Boolean', resolve: source => source.featured || false, }, + noIndex: { + type: 'Boolean', + resolve: source => source.noIndex || false, + }, }, }; createResolvers(resolvers); From 772ea459ff6648d41bf58977a215fe62f0cebcbe Mon Sep 17 00:00:00 2001 From: Dmitry Matiouchenko Date: Wed, 23 Aug 2023 17:23:57 -0700 Subject: [PATCH 2/3] chore: updated documentation to mention noIndex keyword for frontmatter --- README.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/README.md b/README.md index fba7978a73..661c4e0c25 100644 --- a/README.md +++ b/README.md @@ -289,6 +289,12 @@ For example, adding the `contributor_name` and `contributor_link` keywords to th ![attribution frontmatter keyword](docs/images/attribution_keyword_screenshot.png) +#### Hide page from search with noIndex + +Adding `noIndex: true` will flag the page to be skipped during local search indexing. This is required when storing transcluded files under `src/pages/` since we index all pages by default. + +Note: duplicate results in local search are likely due to not setting `noIndex: true` inside transcluded pages. + ### Markdown pages Make sure the markdown content is located under `src/pages`. From fe2acc36ec6a3aab51bdafdc89c0e114e6691247 Mon Sep 17 00:00:00 2001 From: Dmitry Matiouchenko Date: Wed, 23 Aug 2023 17:31:01 -0700 Subject: [PATCH 3/3] chore: cleanup missed unused variable --- packages/gatsby-theme-aio/algolia/index-records.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/gatsby-theme-aio/algolia/index-records.js b/packages/gatsby-theme-aio/algolia/index-records.js index b340cfaffc..88fc8b74b1 100644 --- a/packages/gatsby-theme-aio/algolia/index-records.js +++ b/packages/gatsby-theme-aio/algolia/index-records.js @@ -25,7 +25,7 @@ function indexRecords(isDryRun) { query: mdxQuery, transformer: async function ({ data: { - site: { pathPrefix, noIndexList }, + site: { pathPrefix }, github: { repository }, allFile: { nodes }, },