Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ignore md pages when indexing if noIndex keyword set true #1535

Merged
merged 3 commits into from
Aug 24, 2023
Merged
Show file tree
Hide file tree
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
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-theme-aio/algolia/index-records.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
timkim marked this conversation as resolved.
Show resolved Hide resolved

markdownFiles.push({
birthTime: node.birthTime,
category: node.childMdx.frontmatter.category,
Expand Down Expand Up @@ -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`);
}
Expand Down
1 change: 1 addition & 0 deletions packages/gatsby-theme-aio/algolia/mdx-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const mdxQuery = `
hideBreadcrumbNav
contributor_name
contributor_link
noIndex
}
headings {
value
Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-theme-aio/gatsby-node.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ exports.createResolvers = ({ createResolvers }) => {
},
contributors: {
type: '[String]',
resolve: source => source.contributors
resolve: source => source.contributors,
},
contributor_link: {
type: 'String',
Expand Down Expand Up @@ -226,6 +226,10 @@ exports.createResolvers = ({ createResolvers }) => {
type: 'Boolean',
resolve: source => source.featured || false,
},
noIndex: {
type: 'Boolean',
resolve: source => source.noIndex || false,
},
},
};
createResolvers(resolvers);
Expand Down