mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-10 15:47:23 +02:00
Fix wrong sitemap for alternate URL (#828)
This commit is contained in:
parent
9c070f020d
commit
3566483aa5
5 changed files with 45 additions and 13 deletions
|
@ -46,4 +46,30 @@ describe('utils', () => {
|
||||||
utils.extractBlogPostSummary(blogPostWithoutTruncateContents)
|
utils.extractBlogPostSummary(blogPostWithoutTruncateContents)
|
||||||
).toMatchSnapshot();
|
).toMatchSnapshot();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('getPath', () => {
|
||||||
|
expect(utils.getPath('/docs/en/versioning.html', true)).toBe(
|
||||||
|
'/docs/en/versioning'
|
||||||
|
);
|
||||||
|
expect(utils.getPath('/en/users.html', true)).toBe('/en/users');
|
||||||
|
expect(utils.getPath('/docs/en/asd/index.html', true)).toBe('/docs/en/asd');
|
||||||
|
expect(utils.getPath('/en/help/index.html', true)).toBe('/en/help');
|
||||||
|
expect(utils.getPath('/en/help.a.b.c.d.e.html', true)).toBe(
|
||||||
|
'/en/help.a.b.c.d.e'
|
||||||
|
);
|
||||||
|
expect(utils.getPath('/en/help.js', true)).toBe('/en/help');
|
||||||
|
expect(utils.getPath('/docs/en/versioning.html', false)).toBe(
|
||||||
|
'/docs/en/versioning.html'
|
||||||
|
);
|
||||||
|
expect(utils.getPath('/en/users.html', false)).toBe('/en/users.html');
|
||||||
|
});
|
||||||
|
|
||||||
|
test('removeExtension', () => {
|
||||||
|
expect(utils.removeExtension('/endiliey.html')).toBe('/endiliey');
|
||||||
|
expect(utils.removeExtension('/a.b/')).toBe('/a.b/');
|
||||||
|
expect(utils.removeExtension('/a.b/c.png')).toBe('/a.b/c');
|
||||||
|
expect(utils.removeExtension('/a.b/c.d.e')).toBe('/a.b/c.d');
|
||||||
|
expect(utils.removeExtension('/docs/test')).toBe('/docs/test');
|
||||||
|
expect(utils.removeExtension('pages.js')).toBe('pages');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|
|
@ -20,12 +20,16 @@ function extractBlogPostSummary(content) {
|
||||||
return content.substring(0, BLOG_POST_SUMMARY_LENGTH);
|
return content.substring(0, BLOG_POST_SUMMARY_LENGTH);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function removeExtension(path) {
|
||||||
|
return path.replace(/\.[^/.]+$/, '');
|
||||||
|
}
|
||||||
|
|
||||||
function getPath(path, cleanUrl = false) {
|
function getPath(path, cleanUrl = false) {
|
||||||
if (cleanUrl) {
|
if (cleanUrl) {
|
||||||
if (path.endsWith('/index.html')) {
|
if (path.endsWith('/index.html')) {
|
||||||
return path.replace(/\/index.html$/, '');
|
return path.replace(/\/index.html$/, '');
|
||||||
} else {
|
} else {
|
||||||
return path.replace(/\.html$/, '');
|
return removeExtension(path);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return path;
|
return path;
|
||||||
|
@ -36,4 +40,5 @@ module.exports = {
|
||||||
extractBlogPostBeforeTruncate,
|
extractBlogPostBeforeTruncate,
|
||||||
extractBlogPostSummary,
|
extractBlogPostSummary,
|
||||||
getPath,
|
getPath,
|
||||||
|
removeExtension,
|
||||||
};
|
};
|
||||||
|
|
|
@ -16,6 +16,7 @@ async function execute() {
|
||||||
const readMetadata = require('./readMetadata.js');
|
const readMetadata = require('./readMetadata.js');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const getTOC = require('../core/getTOC.js');
|
const getTOC = require('../core/getTOC.js');
|
||||||
|
const utils = require('../core/utils.js');
|
||||||
const React = require('react');
|
const React = require('react');
|
||||||
const mkdirp = require('mkdirp');
|
const mkdirp = require('mkdirp');
|
||||||
const glob = require('glob');
|
const glob = require('glob');
|
||||||
|
@ -164,7 +165,7 @@ async function execute() {
|
||||||
// replace any links to markdown files to their website html links
|
// replace any links to markdown files to their website html links
|
||||||
Object.keys(mdToHtml).forEach(function(key, index) {
|
Object.keys(mdToHtml).forEach(function(key, index) {
|
||||||
let link = mdToHtml[key];
|
let link = mdToHtml[key];
|
||||||
link = siteConfig.cleanUrl ? link.replace(/\.html$/, '') : link;
|
link = utils.getPath(link, siteConfig.cleanUrl);
|
||||||
link = link.replace('/en/', '/' + language + '/');
|
link = link.replace('/en/', '/' + language + '/');
|
||||||
link = link.replace(
|
link = link.replace(
|
||||||
'/VERSION/',
|
'/VERSION/',
|
||||||
|
@ -205,9 +206,10 @@ async function execute() {
|
||||||
env.translation.enabled &&
|
env.translation.enabled &&
|
||||||
metadata.permalink.indexOf('docs/en') !== -1
|
metadata.permalink.indexOf('docs/en') !== -1
|
||||||
) {
|
) {
|
||||||
const redirectlink = siteConfig.cleanUrl
|
const redirectlink = utils.getPath(
|
||||||
? metadata.permalink.replace(/\.html$/, '')
|
metadata.permalink,
|
||||||
: metadata.permalink;
|
siteConfig.cleanUrl
|
||||||
|
);
|
||||||
const redirectComp = (
|
const redirectComp = (
|
||||||
<Redirect
|
<Redirect
|
||||||
metadata={metadata}
|
metadata={metadata}
|
||||||
|
|
|
@ -17,6 +17,7 @@ function execute(port, options) {
|
||||||
const fs = require('fs-extra');
|
const fs = require('fs-extra');
|
||||||
const path = require('path');
|
const path = require('path');
|
||||||
const getTOC = require('../core/getTOC');
|
const getTOC = require('../core/getTOC');
|
||||||
|
const utils = require('../core/utils');
|
||||||
const {
|
const {
|
||||||
blogRouting,
|
blogRouting,
|
||||||
docsRouting,
|
docsRouting,
|
||||||
|
@ -226,7 +227,7 @@ function execute(port, options) {
|
||||||
// replace any links to markdown files to their website html links
|
// replace any links to markdown files to their website html links
|
||||||
Object.keys(mdToHtml).forEach(function(key, index) {
|
Object.keys(mdToHtml).forEach(function(key, index) {
|
||||||
let link = mdToHtml[key];
|
let link = mdToHtml[key];
|
||||||
link = siteConfig.cleanUrl ? link.replace(/\.html$/, '') : link;
|
link = utils.getPath(link, siteConfig.cleanUrl);
|
||||||
link = link.replace('/en/', '/' + language + '/');
|
link = link.replace('/en/', '/' + language + '/');
|
||||||
link = link.replace(
|
link = link.replace(
|
||||||
'/VERSION/',
|
'/VERSION/',
|
||||||
|
|
|
@ -11,6 +11,7 @@ const glob = require('glob');
|
||||||
const CWD = process.cwd();
|
const CWD = process.cwd();
|
||||||
|
|
||||||
const sitemap = require('sitemap');
|
const sitemap = require('sitemap');
|
||||||
|
const utils = require('../core/utils');
|
||||||
|
|
||||||
const siteConfig = require(CWD + '/siteConfig.js');
|
const siteConfig = require(CWD + '/siteConfig.js');
|
||||||
|
|
||||||
|
@ -67,9 +68,7 @@ module.exports = function(callback) {
|
||||||
|
|
||||||
MetadataBlog.map(blog => {
|
MetadataBlog.map(blog => {
|
||||||
urls.push({
|
urls.push({
|
||||||
url:
|
url: '/blog/' + utils.getPath(blog.path, siteConfig.cleanUrl),
|
||||||
'/blog/' +
|
|
||||||
(siteConfig.cleanUrl ? blog.path.replace(/\.html$/, '') : blog.path),
|
|
||||||
changefreq: 'weekly',
|
changefreq: 'weekly',
|
||||||
priority: 0.3,
|
priority: 0.3,
|
||||||
});
|
});
|
||||||
|
@ -79,14 +78,13 @@ module.exports = function(callback) {
|
||||||
.filter(key => Metadata[key].language === 'en')
|
.filter(key => Metadata[key].language === 'en')
|
||||||
.map(key => {
|
.map(key => {
|
||||||
let doc = Metadata[key];
|
let doc = Metadata[key];
|
||||||
|
let docUrl = utils.getPath(doc.permalink, siteConfig.cleanUrl);
|
||||||
let links = enabledLanguages.map(lang => {
|
let links = enabledLanguages.map(lang => {
|
||||||
let langUrl = doc.permalink.replace('docs/en/', `docs/${lang.tag}/`);
|
let langUrl = docUrl.replace('docs/en/', `docs/${lang.tag}/`);
|
||||||
return {lang: lang.tag, url: langUrl};
|
return {lang: lang.tag, url: langUrl};
|
||||||
});
|
});
|
||||||
urls.push({
|
urls.push({
|
||||||
url: siteConfig.cleanUrl
|
url: docUrl,
|
||||||
? doc.permalink.replace(/\.html$/, '')
|
|
||||||
: doc.permalink,
|
|
||||||
changefreq: 'hourly',
|
changefreq: 'hourly',
|
||||||
priority: 1.0,
|
priority: 1.0,
|
||||||
links,
|
links,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue