Skip to content

Commit

Permalink
feat: add the ability to filter pages from search (#776)
Browse files Browse the repository at this point in the history
Co-authored-by: Vince Picone <Vincent.Patrick.Picone@ibm.com>
  • Loading branch information
vpicone and vpicone authored Mar 10, 2020
1 parent 3f908f9 commit 8755c25
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
6 changes: 3 additions & 3 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
{
"extends": ["wesbos"],
"rules": {
"react/prop-types": false,
"react/destructuring-assignment": false,
"react/no-access-state-in-setstate": false,
"react/prop-types": 0,
"react/destructuring-assignment": 0,
"react/no-access-state-in-setstate": 0,
"no-useless-escape": 0
}
}
6 changes: 5 additions & 1 deletion packages/example/src/pages/guides/MDX.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,17 @@ layout.
## Frontmatter

You can declare frontmatter in your `.mdx` files to provide specific metadata for the theme to use.
The most important of which is the `title`. You can also provide a description and keywords which will be added to the `head` of your document.
- `title`: Main page title: search results and SEO
- `description`: SEO and search results
- `keywords`: just SEO (optional)
- `hiddenFromSearch`: if true, page will be excluded from search

```md
---
title: Markdown
description: Usage instructions for the Markdown component
keywords: 'ibm,carbon,gatsby,mdx,markdown'
hiddenFromSearch: true
---
```

Expand Down
6 changes: 5 additions & 1 deletion packages/gatsby-theme-carbon/config/lunr-options.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ module.exports = {
languages: [
{
name: 'en',
filterNodes: node => node.context && node.context.MdxNode,
filterNodes: node =>
// Lunr let's you filter non-mdx nodes. We only want to filter MDX nodes that aren't hiddenFromSearch
node.context &&
node.context.MdxNode &&
!node.context.frontmatter.hiddenFromSearch,
},
],
fields: [
Expand Down

1 comment on commit 8755c25

@vercel
Copy link

@vercel vercel bot commented on 8755c25 Mar 10, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.