mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-17 19:16:58 +02:00
feat: Allow modifying docs
url prefix (#914)
* Allow other routes than /docs in the URL siteConfig.js has a new mandatory field named *docsRoute* which default value is 'docs' and that can be customized by the user. This change will allow users who uses the library to host guides and tutorials to customize their websites by assign 'docsRoute' values like 'tutorials' or 'guides'. Fixes #879 * Make "docsRoute" field optional * Isolate docsRoute login in getDocsRoute function * Rename docsRoute to docsUrl * Run prettier * Remove old folders * fix: Restore docusaurus reference link * fix: Add `docsUrl` param fallback. Refactor multiple function calls * Fix linting errors * Update description for docsUrl field * Reduce redundant calls to getDocsUrl * Replace a missed use case for `docsUrl` instead of the function call * Move `getDocsUrl` out from `server/routing.js` to `server/utils.js` **Why?** Because `routing.js` is exporting all router RegEx's, and the `getDocsUrl` suffices more as a util * WiP: Align leading slashes and fix routing around `docsUrl` Checklist: - [x] Added `removeDuplicateLeadingSlashes` util to make sure there is only one leading slash - [-] Fix edge cases for routing: - [x] `docsUrl: ''` - [ ] `docsUrl: '/'` - [ ] make it work with languages - [ ] make it work with versioning * Make leading slashes canonical cross routing and generated links This ensures correct routing for customized `baseUrl` and `docsUrl`. - Changed all routing functions to take `siteConfig` instead of `siteConfig.baseUrl` - Updated tests accordingly * Alternative fallback for `docsUrl` * rework/ fix implementation * cleanup * refactor and add docs for config props * fix typo * fix broken url
This commit is contained in:
parent
ff22074ff7
commit
61078e38a9
28 changed files with 423 additions and 319 deletions
|
@ -4,11 +4,11 @@
|
|||
* This source code is licensed under the MIT license found in the
|
||||
* LICENSE file in the root directory of this source tree.
|
||||
*/
|
||||
const routing = require('../routing');
|
||||
const routing = require('../routing.js');
|
||||
|
||||
describe('Blog routing', () => {
|
||||
const blogRegex = routing.blog('/');
|
||||
const blogRegex2 = routing.blog('/react/');
|
||||
const blogRegex = routing.blog({baseUrl: '/'});
|
||||
const blogRegex2 = routing.blog({baseUrl: '/react/'});
|
||||
|
||||
test('valid blog', () => {
|
||||
expect('/blog/test.html').toMatch(blogRegex);
|
||||
|
@ -34,8 +34,8 @@ describe('Blog routing', () => {
|
|||
});
|
||||
|
||||
describe('Docs routing', () => {
|
||||
const docsRegex = routing.docs('/');
|
||||
const docsRegex2 = routing.docs('/reason/');
|
||||
const docsRegex = routing.docs({baseUrl: '/', docsUrl: 'docs'});
|
||||
const docsRegex2 = routing.docs({baseUrl: '/reason/', docsUrl: 'docs'});
|
||||
|
||||
test('valid docs', () => {
|
||||
expect('/docs/en/test.html').toMatch(docsRegex);
|
||||
|
@ -87,8 +87,8 @@ describe('Dot routing', () => {
|
|||
});
|
||||
|
||||
describe('Feed routing', () => {
|
||||
const feedRegex = routing.feed('/');
|
||||
const feedRegex2 = routing.feed('/reason/');
|
||||
const feedRegex = routing.feed({baseUrl: '/'});
|
||||
const feedRegex2 = routing.feed({baseUrl: '/reason/'});
|
||||
|
||||
test('valid feed url', () => {
|
||||
expect('/blog/atom.xml').toMatch(feedRegex);
|
||||
|
@ -137,8 +137,8 @@ describe('Extension-less url routing', () => {
|
|||
});
|
||||
|
||||
describe('Page routing', () => {
|
||||
const pageRegex = routing.page('/');
|
||||
const pageRegex2 = routing.page('/reason/');
|
||||
const pageRegex = routing.page({baseUrl: '/', docsUrl: 'docs'});
|
||||
const pageRegex2 = routing.page({baseUrl: '/reason/', docsUrl: 'docs'});
|
||||
|
||||
test('valid page url', () => {
|
||||
expect('/index.html').toMatch(pageRegex);
|
||||
|
@ -164,8 +164,8 @@ describe('Page routing', () => {
|
|||
});
|
||||
|
||||
describe('Sitemap routing', () => {
|
||||
const sitemapRegex = routing.sitemap('/');
|
||||
const sitemapRegex2 = routing.sitemap('/reason/');
|
||||
const sitemapRegex = routing.sitemap({baseUrl: '/'});
|
||||
const sitemapRegex2 = routing.sitemap({baseUrl: '/reason/'});
|
||||
|
||||
test('valid sitemap url', () => {
|
||||
expect('/sitemap.xml').toMatch(sitemapRegex);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue