Skip to content

Commit

Permalink
Merge pull request #88 from Danielku15/feature/docusaurus-2.1.0
Browse files Browse the repository at this point in the history
Fix plugin for Docusuarus 2.1.0
  • Loading branch information
praveenn77 authored Oct 30, 2022
2 parents 18ea72d + 4068381 commit d2419e4
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 13 deletions.
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,17 +30,17 @@ npm i docusaurus-lunr-search --save
```
npm install
```
3. Then run docusaurus swizzle
```
npm run swizzle docusaurus-lunr-search SearchBar -- --danger
```
4. Add the docusaurus-lunr-search plugin to your `docusaurus.config.js`
3. Add the docusaurus-lunr-search plugin to your `docusaurus.config.js`
```
module.exports = {
// ...
plugins: [require.resolve('docusaurus-lunr-search')],
}
```
4. Then run docusaurus swizzle
```
npm run swizzle docusaurus-lunr-search SearchBar -- --eject --danger
```
5. Then build your Docusaurus project
```
npm run build
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion src/theme/SearchBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ const Search = props => {
Promise.all([
getSearchDoc(),
getLunrIndex(),
import("./lib/DocSearch"),
import("./DocSearch"),
import("./algolia.css")
]).then(([searchDocs, searchIndex, { default: DocSearch }]) => {
if (searchDocs.length === 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class LunrSearchAdapter {
lvl0: doc.pageTitle || doc.title,
lvl1: doc.type === 0 ? null : doc.title
},
url: this.baseUrl + doc.url,
url: this.baseUrl !== '/' || doc.url.charAt(0) !== '/' ? this.baseUrl + doc.url : doc.url,
_snippetResult: formattedContent ? {
content: {
value: formattedContent,
Expand Down
File renamed without changes.
File renamed without changes.
16 changes: 10 additions & 6 deletions src/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,17 +64,21 @@ function getFilePaths(routesPaths, outDir, baseUrl, options = {}) {
if (route === `${baseUrl}404.html`) return

const isBaseUrl = route === baseUrl
let filePath;

if (isBaseUrl && !indexBaseUrl) {
return;
}

route = route.substring(baseUrl.length)
if (isBaseUrl || route.endsWith(path.sep)) {
filePath = path.join(outDir, route, "index.html")
} else {
filePath = path.join(outDir, `${route}.html`)
const candidatePaths = [
path.join(outDir, `${route}.html`),
path.join(outDir, route, "index.html")
]

const filePath = candidatePaths.find(fs.existsSync);
if(!fs.existsSync(filePath)) {
// if this error occurs, likely docusaurus changed some file generation aspects
// and we need to update the candidates above
console.warn(`docusaurus-lunr-search: could not resolve file for route '${route}', it will be missing in the search index`);
}

// In case docs only mode routesPaths has baseUrl twice
Expand Down

0 comments on commit d2419e4

Please sign in to comment.