mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-15 01:57:28 +02:00
refactor(v2): simplify code by removing wip i18n & translation (#1431)
* refactor(v2): remove i18n & versioning + cleaner code * totally remove i18n and versioning from plugin
This commit is contained in:
parent
0813920349
commit
373d17ee72
123 changed files with 170 additions and 4162 deletions
|
@ -7,7 +7,7 @@
|
|||
|
||||
import path from 'path';
|
||||
|
||||
import loadSetup from '../../../docusaurus/test/loadSetup';
|
||||
import loadSetup from '../../../docusaurus/lib/server/load/__tests__/loadSetup';
|
||||
import DocusaurusPluginContentPages from '../index';
|
||||
|
||||
describe('docusaurus-plugin-content-pages', () => {
|
||||
|
@ -26,93 +26,9 @@ describe('docusaurus-plugin-content-pages', () => {
|
|||
},
|
||||
],
|
||||
],
|
||||
[
|
||||
'versioned',
|
||||
pagesDir => [
|
||||
{
|
||||
permalink: '/',
|
||||
source: path.join(pagesDir, 'index.js'),
|
||||
},
|
||||
{
|
||||
permalink: '/hello/world',
|
||||
source: path.join(pagesDir, 'hello', 'world.js'),
|
||||
},
|
||||
],
|
||||
],
|
||||
[
|
||||
'translated',
|
||||
pagesDir => [
|
||||
{
|
||||
language: 'en',
|
||||
permalink: '/',
|
||||
source: path.join(pagesDir, 'index.js'),
|
||||
},
|
||||
{
|
||||
language: 'en',
|
||||
permalink: '/en/',
|
||||
source: path.join(pagesDir, 'index.js'),
|
||||
},
|
||||
{
|
||||
language: 'ko',
|
||||
permalink: '/ko/',
|
||||
source: path.join(pagesDir, 'index.js'),
|
||||
},
|
||||
{
|
||||
language: 'en',
|
||||
permalink: '/hello/world',
|
||||
source: path.join(pagesDir, 'hello', 'world.js'),
|
||||
},
|
||||
{
|
||||
language: 'en',
|
||||
permalink: '/en/hello/world',
|
||||
source: path.join(pagesDir, 'hello', 'world.js'),
|
||||
},
|
||||
{
|
||||
language: 'ko',
|
||||
permalink: '/ko/hello/world',
|
||||
source: path.join(pagesDir, 'hello', 'world.js'),
|
||||
},
|
||||
],
|
||||
[
|
||||
'transversioned',
|
||||
pagesDir => [
|
||||
{
|
||||
language: 'en',
|
||||
permalink: '/',
|
||||
source: path.join(pagesDir, 'index.js'),
|
||||
},
|
||||
{
|
||||
language: 'en',
|
||||
permalink: '/en/',
|
||||
source: path.join(pagesDir, 'index.js'),
|
||||
},
|
||||
{
|
||||
language: 'ko',
|
||||
permalink: '/ko/',
|
||||
source: path.join(pagesDir, 'index.js'),
|
||||
},
|
||||
{
|
||||
language: 'en',
|
||||
permalink: '/hello/world',
|
||||
source: path.join(pagesDir, 'hello', 'world.js'),
|
||||
},
|
||||
{
|
||||
language: 'en',
|
||||
permalink: '/en/hello/world',
|
||||
source: path.join(pagesDir, 'hello', 'world.js'),
|
||||
},
|
||||
{
|
||||
language: 'ko',
|
||||
permalink: '/ko/hello/world',
|
||||
source: path.join(pagesDir, 'hello', 'world.js'),
|
||||
},
|
||||
],
|
||||
],
|
||||
],
|
||||
])('%s website', async (type, expected) => {
|
||||
const {env, siteDir, siteConfig} = await loadSetup(type);
|
||||
const {siteDir, siteConfig} = await loadSetup(type);
|
||||
const plugin = new DocusaurusPluginContentPages({
|
||||
env,
|
||||
siteDir,
|
||||
siteConfig,
|
||||
});
|
||||
|
|
|
@ -7,7 +7,7 @@
|
|||
|
||||
const globby = require('globby');
|
||||
const path = require('path');
|
||||
const {encodePath, fileToPath, idx, docuHash} = require('@docusaurus/utils');
|
||||
const {encodePath, fileToPath, docuHash} = require('@docusaurus/utils');
|
||||
|
||||
const DEFAULT_OPTIONS = {
|
||||
path: 'pages', // Path to data on filesystem, relative to site dir.
|
||||
|
@ -37,7 +37,7 @@ class DocusaurusPluginContentPages {
|
|||
|
||||
async loadContent() {
|
||||
const {include} = this.options;
|
||||
const {env, siteConfig} = this.context;
|
||||
const {siteConfig} = this.context;
|
||||
const pagesDir = this.contentPath;
|
||||
|
||||
const {baseUrl} = siteConfig;
|
||||
|
@ -48,44 +48,16 @@ class DocusaurusPluginContentPages {
|
|||
// Prepare metadata container.
|
||||
const pagesMetadatas = [];
|
||||
|
||||
// Translation.
|
||||
const translationEnabled = idx(env, ['translation', 'enabled']);
|
||||
const enabledLanguages =
|
||||
translationEnabled && idx(env, ['translation', 'enabledLanguages']);
|
||||
const enabledLangTags =
|
||||
(enabledLanguages && enabledLanguages.map(lang => lang.tag)) || [];
|
||||
const defaultLangTag = idx(env, ['translation', 'defaultLanguage', 'tag']);
|
||||
|
||||
await Promise.all(
|
||||
pagesFiles.map(async relativeSource => {
|
||||
const source = path.join(pagesDir, relativeSource);
|
||||
const pathName = encodePath(fileToPath(relativeSource));
|
||||
if (translationEnabled && enabledLangTags.length > 0) {
|
||||
enabledLangTags.forEach(langTag => {
|
||||
// Default lang should also be available. E.g: /en/users and /users is the same.
|
||||
if (langTag === defaultLangTag) {
|
||||
pagesMetadatas.push({
|
||||
permalink: pathName.replace(/^\//, baseUrl),
|
||||
language: langTag,
|
||||
source,
|
||||
});
|
||||
}
|
||||
|
||||
const metadata = {
|
||||
permalink: pathName.replace(/^\//, `${baseUrl}${langTag}/`),
|
||||
language: langTag,
|
||||
source,
|
||||
};
|
||||
pagesMetadatas.push(metadata);
|
||||
});
|
||||
} else {
|
||||
// Default Language.
|
||||
const metadata = {
|
||||
permalink: pathName.replace(/^\//, baseUrl),
|
||||
source,
|
||||
};
|
||||
pagesMetadatas.push(metadata);
|
||||
}
|
||||
// Default Language.
|
||||
const metadata = {
|
||||
permalink: pathName.replace(/^\//, baseUrl),
|
||||
source,
|
||||
};
|
||||
pagesMetadatas.push(metadata);
|
||||
}),
|
||||
);
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue