fix: wrong sidebar_label and title on versioned_docs (#1265)

* fix: wrong sidebar_label and title on versioned_docs

* nits
This commit is contained in:
Endilie Yacop Sucipto 2019-03-07 02:41:05 +08:00 committed by Yangshun Tay
parent 0f94c062a5
commit c73da00252

View file

@ -72,16 +72,13 @@ function execute() {
// look through markdown headers of docs for titles and categories to translate // look through markdown headers of docs for titles and categories to translate
const docsDir = nodePath.join(CWD, '../', readMetadata.getDocsPath()); const docsDir = nodePath.join(CWD, '../', readMetadata.getDocsPath());
const versionedDocsDir = nodePath.join(CWD, 'versioned_docs'); const versionedDocsDir = nodePath.join(CWD, 'versioned_docs');
let files = [
...glob.sync(`${docsDir}/**`), const translateDoc = (file, refDir) => {
...glob.sync(`${versionedDocsDir}/**`),
];
files.forEach(file => {
const extension = nodePath.extname(file); const extension = nodePath.extname(file);
if (extension === '.md' || extension === '.markdown') { if (extension === '.md' || extension === '.markdown') {
let res; let res;
try { try {
res = readMetadata.processMetadata(file, docsDir); res = readMetadata.processMetadata(file, refDir);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
process.exit(1); process.exit(1);
@ -100,7 +97,12 @@ function execute() {
metadata.sidebar_label; metadata.sidebar_label;
} }
} }
}); };
glob.sync(`${docsDir}/**`).forEach(file => translateDoc(file, docsDir));
glob
.sync(`${versionedDocsDir}/**`)
.forEach(file => translateDoc(file, versionedDocsDir));
// look through header links for text to translate // look through header links for text to translate
siteConfig.headerLinks.forEach(link => { siteConfig.headerLinks.forEach(link => {
if (link.label) { if (link.label) {
@ -116,8 +118,7 @@ function execute() {
}); });
}); });
files = glob.sync(`${CWD}/versioned_sidebars/*`); glob.sync(`${CWD}/versioned_sidebars/*`).forEach(file => {
files.forEach(file => {
if (!file.endsWith('-sidebars.json')) { if (!file.endsWith('-sidebars.json')) {
if (file.endsWith('-sidebar.json')) { if (file.endsWith('-sidebar.json')) {
console.warn( console.warn(
@ -143,8 +144,7 @@ function execute() {
}); });
// go through pages to look for text inside translate tags // go through pages to look for text inside translate tags
files = glob.sync(`${CWD}/pages/en/**`); glob.sync(`${CWD}/pages/en/**`).forEach(file => {
files.forEach(file => {
const extension = nodePath.extname(file); const extension = nodePath.extname(file);
if (extension === '.js') { if (extension === '.js') {
const ast = babylon.parse(fs.readFileSync(file, 'utf8'), { const ast = babylon.parse(fs.readFileSync(file, 'utf8'), {