mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-21 04:57:05 +02:00
Fix: transformation of url to cleanUrl / pretty url (#923)
* fix: pretty url should only remove html extension * cleanUrl of '/index.html' should be '/'
This commit is contained in:
parent
ba76eddc87
commit
d18b09954b
2 changed files with 28 additions and 19 deletions
|
@ -15,17 +15,17 @@ function extractBlogPostBeforeTruncate(content) {
|
|||
return content.split(TRUNCATE_MARKER)[0];
|
||||
}
|
||||
|
||||
function removeExtension(path) {
|
||||
return path.replace(/\.[^/.]+$/, '');
|
||||
function removeExtension(pathStr) {
|
||||
return pathStr.replace(/\.[^/.]+$/, '');
|
||||
}
|
||||
|
||||
function getPath(path, cleanUrl = false) {
|
||||
if (cleanUrl) {
|
||||
return path.endsWith('/index.html')
|
||||
? path.replace(/\/index.html$/, '')
|
||||
: removeExtension(path);
|
||||
function getPath(pathStr, cleanUrl = false) {
|
||||
if (!pathStr || !cleanUrl || !pathStr.endsWith('.html')) {
|
||||
return pathStr;
|
||||
}
|
||||
return path;
|
||||
return pathStr.endsWith('/index.html')
|
||||
? pathStr.replace(/index\.html$/, '')
|
||||
: removeExtension(pathStr);
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue