mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 04:57:05 +02:00
feat(v2): add trailingSlash config option (#4908)
* POC: add trailingSlash option * integrate the preferFoldersOutput option of fork @slorber/static-site-generator-webpack-plugin * Fix broken links when using trailing slash => using md links is more reliable * fix TS issue * minor polish * fix doc page being sensitive to trailing slashes * Add tests for applyTrailingSlash * rename test files * extract and test applyRouteTrailingSlash * update snapshot * add trailing slash config to serve command * fix getSidebar() => still sensitive to trailing slash setting * never apply trailing slash to an anchor link * Add documentation for trailingSlash setting
This commit is contained in:
parent
77264f1eb0
commit
df8a900f9c
28 changed files with 469 additions and 67 deletions
|
@ -13,16 +13,27 @@ Markdown docs have their own [Markdown frontmatter](../../api/plugins/plugin-con
|
|||
|
||||
## Referencing other documents {#referencing-other-documents}
|
||||
|
||||
If you want to reference another document file, you could use the name of the document you want to reference. Docusaurus will convert the file path to be the final website path (and remove the `.md`).
|
||||
If you want to reference another document file, you could use the relative path of the document you want to link to.
|
||||
|
||||
For example, if you are in `doc2.md` and you want to reference `doc1.md` and `folder/doc3.md`:
|
||||
Docusaurus will convert the file path to be the final document url path (and remove the `.md` extension).
|
||||
|
||||
For example, if you are in `folder/doc1.md` and you want to reference `folder/doc2.md`, `folder/subfolder/doc3.md` and `otherFolder/doc4.md`:
|
||||
|
||||
```md
|
||||
I am referencing a [document](doc1.md). Reference to another [document in a folder](folder/doc3.md).
|
||||
I am referencing a [document](doc2.md).
|
||||
|
||||
[Relative document](../doc2.md) referencing works as well.
|
||||
Reference to another [document in a subfolder](subfolder/doc3.md).
|
||||
|
||||
[Relative document](../otherFolder/doc4.md) referencing works as well.
|
||||
```
|
||||
|
||||
One benefit of this approach is that the links to external files will still work if you are viewing the file on GitHub.
|
||||
:::tip
|
||||
|
||||
Another benefit, for versioned docs, is that one versioned doc will link to another doc of the exact same version.
|
||||
It is better to use relative file paths links instead of relative links:
|
||||
|
||||
- links will keep working on the GitHub interface
|
||||
- you can customize the document slugs without having to update all the links
|
||||
- a versioned doc will link to another doc of the exact same version
|
||||
- relative links are very likely to break if you update the [`trailingSlash` config](../../api/docusaurus.config.js.md#trailing-slash)
|
||||
|
||||
:::
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue