Skip to content

Commit

Permalink
fix: support trailingSlash = false
Browse files Browse the repository at this point in the history
Closes #52
  • Loading branch information
cmfcmf committed Dec 14, 2021
1 parent f00f41a commit 371d60a
Show file tree
Hide file tree
Showing 6 changed files with 32 additions and 8 deletions.
14 changes: 9 additions & 5 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,18 @@ jobs:
- run: yarn --cwd packages/docusaurus-search-local build:server
- run: yarn --cwd packages/docusaurus-search-local build:client

- run: yarn --cwd packages/example-docs build
- run: yarn test

- run: yarn --cwd packages/example-docs serve &

# Install OS dependencies
# Run `apt update` beforehand to avoid 404 Not Found errors during apt install.
- run: sudo apt update && yarn playwright install-deps
# Install Browsers
- run: yarn playwright install

- run: yarn --cwd packages/example-docs build
- run: yarn test
- run: yarn --cwd packages/example-docs serve &
- run: yarn test:e2e --browser=all

# TODO: Cannot run browser tests for these for now.
- run: yarn --cwd packages/example-docs build --config docusaurus.config.noTrailingSlash.js
- run: yarn --cwd packages/example-docs build --config docusaurus.config.subDirectory.js
- run: yarn --cwd packages/example-docs build --config docusaurus.config.noTrailingSlashSubdirectory.js
4 changes: 2 additions & 2 deletions packages/docusaurus-search-local/src/server/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,7 +354,7 @@ export const tokenize = (input) => lunr.tokenizer(input)
const data = routesPaths
.flatMap((url) => {
// baseUrl includes the language prefix, thus `route` will be language-agnostic.
const route = url.substr(baseUrl.length);
const route = url.substring(baseUrl.length);
if (!url.startsWith(baseUrl)) {
throw new Error(
`The route must start with the baseUrl ${baseUrl}, but was ${route}. This is a bug, please report it.`
Expand Down Expand Up @@ -453,7 +453,7 @@ export const tokenize = (input) => lunr.tokenizer(input)
.map(({ route, url, type }) => {
const file =
trailingSlash === false
? path.join(outDir, `${route}.html`)
? path.join(outDir, `${route === "" ? "index" : route}.html`)
: path.join(outDir, route, "index.html");
return {
file,
Expand Down
5 changes: 5 additions & 0 deletions packages/example-docs/docusaurus.config.noTrailingSlash.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('@docusaurus/types').DocusaurusConfig} */
module.exports = {
...require("./docusaurus.config.js"),
trailingSlash: false,
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/** @type {import('@docusaurus/types').DocusaurusConfig} */
module.exports = {
...require("./docusaurus.config.js"),
trailingSlash: false,
baseUrl: '/foo/',
};
5 changes: 5 additions & 0 deletions packages/example-docs/docusaurus.config.subDirectory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import('@docusaurus/types').DocusaurusConfig} */
module.exports = {
...require("./docusaurus.config.js"),
baseUrl: '/foo/',
};
6 changes: 5 additions & 1 deletion scripts/publish.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,8 @@ yarn --cwd packages/example-docs serve &
yarn test:e2e
pkill -9 -f packages/example-docs

yarn lerna publish
yarn --cwd packages/example-docs build --config docusaurus.config.noTrailingSlash.js
yarn --cwd packages/example-docs build --config docusaurus.config.subDirectory.js
yarn --cwd packages/example-docs build --config docusaurus.config.noTrailingSlashSubdirectory.js

yarn lerna publish "$@"

0 comments on commit 371d60a

Please sign in to comment.