mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-12 08:37:25 +02:00
Enable clean / extension-less url (#677)
This commit is contained in:
parent
aee255219b
commit
31f0c27f81
14 changed files with 124 additions and 50 deletions
|
@ -41,8 +41,14 @@ async function execute() {
|
|||
// create the folder path for a file if it does not exist, then write the file
|
||||
function writeFileAndCreateFolder(file, content) {
|
||||
mkdirp.sync(path.dirname(file));
|
||||
|
||||
fs.writeFileSync(file, content);
|
||||
|
||||
// build extra file for extension-less url if "cleanUrl" siteConfig is true
|
||||
if (siteConfig.cleanUrl && file.indexOf('index.html') === -1) {
|
||||
const extraFile = file.replace(/\.html$/, '/index.html');
|
||||
mkdirp.sync(path.dirname(extraFile));
|
||||
fs.writeFileSync(extraFile, content);
|
||||
}
|
||||
}
|
||||
|
||||
const TABLE_OF_CONTENTS_TOKEN = '<AUTOGENERATED_TABLE_OF_CONTENTS>';
|
||||
|
@ -156,6 +162,7 @@ async function execute() {
|
|||
// replace any links to markdown files to their website html links
|
||||
Object.keys(mdToHtml).forEach(function(key, index) {
|
||||
let link = mdToHtml[key];
|
||||
link = siteConfig.cleanUrl ? link.replace(/\.html$/, '') : link;
|
||||
link = link.replace('/en/', '/' + language + '/');
|
||||
link = link.replace(
|
||||
'/VERSION/',
|
||||
|
@ -196,12 +203,15 @@ async function execute() {
|
|||
env.translation.enabled &&
|
||||
metadata.permalink.indexOf('docs/en') !== -1
|
||||
) {
|
||||
const redirectlink = siteConfig.cleanUrl
|
||||
? metadata.permalink.replace(/\.html$/, '')
|
||||
: metadata.permalink;
|
||||
const redirectComp = (
|
||||
<Redirect
|
||||
metadata={metadata}
|
||||
language={language}
|
||||
config={siteConfig}
|
||||
redirect={siteConfig.baseUrl + metadata.permalink}
|
||||
redirect={siteConfig.baseUrl + redirectlink}
|
||||
/>
|
||||
);
|
||||
const redirectStr = renderToStaticMarkupWithDoctype(redirectComp);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue