mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-17 11:07:07 +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
|
@ -14,8 +14,9 @@ const metadataUtils = require('./metadataUtils');
|
|||
|
||||
const env = require('./env.js');
|
||||
const utils = require('./utils.js');
|
||||
const loadConfig = require('./config');
|
||||
|
||||
const siteConfig = require(`${CWD}/siteConfig.js`);
|
||||
const siteConfig = loadConfig(`${CWD}/siteConfig.js`);
|
||||
|
||||
const ENABLE_TRANSLATION = fs.existsSync(`${CWD}/languages.js`);
|
||||
|
||||
|
@ -187,14 +188,16 @@ function processVersionMetadata(file, version, useVersion, language) {
|
|||
|
||||
const latestVersion = versions[0];
|
||||
|
||||
const docsPart = `${siteConfig.docsUrl ? `${siteConfig.docsUrl}/` : ''}`;
|
||||
const versionPart = `${version !== latestVersion ? `${version}/` : ''}`;
|
||||
if (!ENABLE_TRANSLATION && !siteConfig.useEnglishUrl) {
|
||||
metadata.permalink = `docs/${
|
||||
version !== latestVersion ? `${version}/` : ''
|
||||
}${metadata.original_id}.html`;
|
||||
metadata.permalink = `${docsPart}${versionPart}${
|
||||
metadata.original_id
|
||||
}.html`;
|
||||
} else {
|
||||
metadata.permalink = `docs/${language}/${
|
||||
version !== latestVersion ? `${version}/` : ''
|
||||
}${metadata.original_id}.html`;
|
||||
metadata.permalink = `${docsPart}${language}/${versionPart}${
|
||||
metadata.original_id
|
||||
}.html`;
|
||||
}
|
||||
metadata.id = metadata.id.replace(
|
||||
`version-${useVersion}-`,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue