Skip to content

Question: Exclude from Local Search and display Frontmatter data #2344

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

Closed
mitchellknight opened this issue May 5, 2023 · 2 comments
Closed
Labels
contribution welcome The team would welcome a contribution from the community for this issue

Comments

@mitchellknight
Copy link

The new Local Search is great! I just have a few questions:

  1. How do I exclude results from Local Search? For example, let's say I had a /secret/ folder that I would like to exclude all subpages from search results, how would I do that?
  2. How do I get Local Search to use frontmatter data (see screenshot)?

Frontmatter

@jeremyriverain
Copy link
Contributor

Hi,

I am currently migrating a doc website from Vuepress to Vitepress. I would like to exclude certain content from the search results but I can't find a way to do it with Vitepress. This ticket seems to indicate that it could be an improvement to Vitepress. Is this a possible development?

I have time to work on this subject. I can contribute.

Is there a particular direction you would like to take on this subject? Which API expose?

I imagine 2 ways to exclude content from search results.

  1. from the .vitepress/config.ts file, by adding a new parameter, like isSearchable:
// .vitepress/config
export default defineConfig({
  themeConfig: {
    search: {
      provider: 'local',
      options: {
        isSearchable (pageData) {
          return !pageData.startsWith('/excluded-folder')
        },
      },
    },
})
  1. at the level of each page, by taking into account a new frontmatter property:
---
search: false
---

<!-- excluded-folder/index.md -->
# my content excluded from search results

What do you think ?

@brc-dd brc-dd added the contribution welcome The team would welcome a contribution from the community for this issue label Jul 4, 2023
@brc-dd
Copy link
Member

brc-dd commented Jul 4, 2023

Yeah contributions are welcome. Make the API something like this:

interface LocalSearchOptions {
  exclude: (pageData: PageData) => boolean
}

So that function can be:

return pageData.relativePath.startsWith('/excluded-folder') || pageData.frontmatter.search === false

@brc-dd brc-dd closed this as completed in 37d5b27 Jul 21, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jul 29, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
contribution welcome The team would welcome a contribution from the community for this issue
Projects
None yet
Development

No branches or pull requests

3 participants