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

@vuepress-seach / Searchable paths #1032

Merged
merged 3 commits into from
Dec 12, 2018
Merged

@vuepress-seach / Searchable paths #1032

merged 3 commits into from
Dec 12, 2018

Conversation

robsontenorio
Copy link
Contributor

Summary

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update
  • Refactor
  • Docs
  • Build-related changes
  • Other, please describe:

Does this PR introduce a breaking change?

  • Yes
  • No

The PR fulfills these requirements:

You have tested in the following browsers: (Providing a detailed version will be better.)

  • Chrome (latest)
  • Firefox (latest)
  • Safari
  • Edge
  • IE

If adding a new feature, the PR's description includes:

  • A convincing reason for adding this feature
  • Related documents have been updated
  • Related tests have been updated

Other information

searchPaths

  • Type: array
  • Default: []
    Set the array of searchable paths. Default value (a empty array) will search on all paths. Considering you have this structure:
docs/
├── .vuepress/            
│    └── ...
│
├── 1.0/               
│    └── ...
│
└── 2.0/               
    └── ...                       

You can restrict the searching setting with searchPaths as ['/1.0/']. Otherwise, the default search will return duplications, once you can have similar content between folders /1.0/ and /2.0/.

@matrunchyk
Copy link

Please, please, it's very important!

@chrissm79
Copy link

This would be 💯

Copy link
Member

@ulivz ulivz left a comment

Choose a reason for hiding this comment

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

Thanks for the contribution, but I think that it's best to implement this API as string | RegExp | Array<RegExp> instead of only indexOf check.

})
return searchable
},

Copy link
Member

Choose a reason for hiding this comment

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

Code here can be simplified as:

isSearchable (page) {
  const searchPaths = SEARCH_PATHS
  // all paths searchables
  if (searchPaths.length === 0) { return true }

  return searchPaths.filter(path => {
    return page.path.indexOf(path) !== -1
  }).length > 0
},

@ulivz
Copy link
Member

ulivz commented Nov 29, 2018

So I recommend to name this API as test:

  • RegExp:
module.exports = {
  plugins: [
    ['@vuepress/search', {
      test: /1\.0/
    }]
  ]
}
  • Array<RegExp>:
module.exports = {
  plugins: [
    ['@vuepress/search', {
      test: [ /1\.0/, /2\.0/ ]
    }]
  ]
}
  • Function (This can be done in another PR)
module.exports = {
  plugins: [
    ['@vuepress/search', {
      test: (currentPage, pages) => { }
    }]
  ]
}

@robsontenorio
Copy link
Contributor Author

@ulivz Done!

@ulivz ulivz merged commit d6bddf1 into vuejs:master Dec 12, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants