Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(v2): new docs edit options: editCurrentVersion + editLocalizedDocs #3949

Merged
merged 4 commits into from
Dec 28, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,8 @@ module.exports = {
url: 'https://your-docusaurus-test-site.com',
baseUrl: '/',
favicon: 'img/favicon.ico',
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
},
};
Original file line number Diff line number Diff line change
@@ -1 +1 @@
Hello `1.0.0` ! (translated)
Hello `1.0.0` ! (translated en)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Hello `1.0.0` ! (translated fr)
Original file line number Diff line number Diff line change
Expand Up @@ -936,7 +936,7 @@ Object {
\\"id\\": \\"version-1.0.0/hello\\",
\\"isDocsHomePage\\": true,
\\"title\\": \\"hello\\",
\\"description\\": \\"Hello 1.0.0 ! (translated)\\",
\\"description\\": \\"Hello 1.0.0 ! (translated en)\\",
\\"source\\": \\"@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md\\",
\\"slug\\": \\"/\\",
\\"permalink\\": \\"/docs/1.0.0/\\",
Expand Down
183 changes: 147 additions & 36 deletions packages/docusaurus-plugin-content-docs/src/__tests__/docs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import {
DocMetadataBase,
MetadataOptions,
VersionMetadata,
PluginOptions,
} from '../types';
import {LoadContext} from '@docusaurus/types';
import {DEFAULT_PLUGIN_ID} from '@docusaurus/core/lib/constants';
Expand Down Expand Up @@ -42,6 +43,7 @@ ${markdown}
source,
content,
lastUpdate: {},
docsDirPath: 'docs',
filePath: source,
};
};
Expand Down Expand Up @@ -111,19 +113,19 @@ function createTestUtils({
}

describe('simple site', () => {
async function loadSite() {
async function loadSite(
loadSiteOptions: {options: Partial<PluginOptions>} = {options: {}},
) {
const siteDir = path.join(fixtureDir, 'simple-site');
const context = await loadContext(siteDir);
const options = {
id: DEFAULT_PLUGIN_ID,
...DEFAULT_OPTIONS,
...loadSiteOptions.options,
};
const versionsMetadata = readVersionsMetadata({
context,
options: {
id: DEFAULT_PLUGIN_ID,
...DEFAULT_OPTIONS,
},
options,
});
expect(versionsMetadata.length).toEqual(1);
const [currentVersion] = versionsMetadata;
Expand Down Expand Up @@ -191,12 +193,14 @@ describe('simple site', () => {
});

test('homePageId doc', async () => {
const {siteDir, context, options, currentVersion} = await loadSite();
const {siteDir, context, options, currentVersion} = await loadSite({
options: {homePageId: 'hello'},
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options: {...options, homePageId: 'hello'},
options,
versionMetadata: currentVersion,
});

Expand All @@ -213,12 +217,14 @@ describe('simple site', () => {
});

test('homePageId doc nested', async () => {
const {siteDir, context, options, currentVersion} = await loadSite();
const {siteDir, context, options, currentVersion} = await loadSite({
options: {homePageId: 'foo/bar'},
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options: {...options, homePageId: 'foo/bar'},
options,
versionMetadata: currentVersion,
});

Expand All @@ -235,15 +241,16 @@ describe('simple site', () => {
});

test('docs with editUrl', async () => {
const {siteDir, context, options, currentVersion} = await loadSite();
const {siteDir, context, options, currentVersion} = await loadSite({
options: {
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website',
},
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options: {
...options,
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website',
},
options,
versionMetadata: currentVersion,
});

Expand Down Expand Up @@ -278,16 +285,17 @@ describe('simple site', () => {
});

test('docs with last update time and author', async () => {
const {siteDir, context, options, currentVersion} = await loadSite();

const testUtilsLocal = createTestUtils({
siteDir,
context,
const {siteDir, context, options, currentVersion} = await loadSite({
options: {
...options,
showLastUpdateAuthor: true,
showLastUpdateTime: true,
},
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options,
versionMetadata: currentVersion,
});

Expand Down Expand Up @@ -361,15 +369,16 @@ describe('simple site', () => {
});

test('docs with slug on doc home', async () => {
const {siteDir, context, options, currentVersion} = await loadSite();
const {siteDir, context, options, currentVersion} = await loadSite({
options: {
homePageId: 'homePageId',
},
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options: {
...options,
homePageId: 'homePageId',
},
options,
versionMetadata: currentVersion,
});
expect(() => {
Expand All @@ -388,19 +397,23 @@ describe('simple site', () => {
});

describe('versioned site', () => {
async function loadSite() {
async function loadSite(
loadSiteOptions: {options: Partial<PluginOptions>; locale?: string} = {
options: {},
},
) {
const siteDir = path.join(fixtureDir, 'versioned-site');
const context = await loadContext(siteDir);
const context = await loadContext(siteDir, {
locale: loadSiteOptions.locale,
});
const options = {
id: DEFAULT_PLUGIN_ID,
...DEFAULT_OPTIONS,
...loadSiteOptions.options,
};
const versionsMetadata = readVersionsMetadata({
context,
options: {
id: DEFAULT_PLUGIN_ID,
...DEFAULT_OPTIONS,
},
options,
});
expect(versionsMetadata.length).toEqual(4);
const [
Expand Down Expand Up @@ -495,7 +508,7 @@ describe('versioned site', () => {
permalink: '/docs/1.0.0/hello',
slug: '/hello',
title: 'hello',
description: 'Hello 1.0.0 ! (translated)',
description: 'Hello 1.0.0 ! (translated en)',
version: '1.0.0',
source:
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
Expand Down Expand Up @@ -582,15 +595,48 @@ describe('versioned site', () => {
});

test('translated doc with editUrl', async () => {
const {siteDir, context, options, version100} = await loadSite();
const {siteDir, context, options, version100} = await loadSite({
options: {
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website',
// editCurrentVersion: true,
},
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options,
versionMetadata: version100,
});

await testUtilsLocal.testMeta(path.join('hello.md'), {
id: 'version-1.0.0/hello',
unversionedId: 'hello',
isDocsHomePage: false,
permalink: '/docs/1.0.0/hello',
slug: '/hello',
title: 'hello',
description: 'Hello 1.0.0 ! (translated en)',
version: '1.0.0',
source:
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/versioned_docs/version-1.0.0/hello.md',
});
});

test('translated en doc with editUrl and editCurrentVersion=true', async () => {
const {siteDir, context, options, version100} = await loadSite({
options: {
...options,
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website',
editCurrentVersion: true,
},
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options,
versionMetadata: version100,
});

Expand All @@ -601,12 +647,77 @@ describe('versioned site', () => {
permalink: '/docs/1.0.0/hello',
slug: '/hello',
title: 'hello',
description: 'Hello 1.0.0 ! (translated)',
description: 'Hello 1.0.0 ! (translated en)',
version: '1.0.0',
source:
'@site/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/i18n/en/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
'https://github.com/facebook/docusaurus/edit/master/website/docs/hello.md',
});
});

test('translated fr doc with editUrl and editLocalizedDocs=true', async () => {
const {siteDir, context, options, version100} = await loadSite({
options: {
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website',
editLocalizedDocs: true,
},
locale: 'fr',
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options,
versionMetadata: version100,
});

await testUtilsLocal.testMeta(path.join('hello.md'), {
id: 'version-1.0.0/hello',
unversionedId: 'hello',
isDocsHomePage: false,
permalink: '/fr/docs/1.0.0/hello',
slug: '/hello',
title: 'hello',
description: 'Hello 1.0.0 ! (translated fr)',
version: '1.0.0',
source:
'@site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
});
});

test('translated fr doc with editUrl and editLocalizedDocs=true + editCurrentVersion=true', async () => {
const {siteDir, context, options, version100} = await loadSite({
options: {
editUrl: 'https://github.com/facebook/docusaurus/edit/master/website',
editCurrentVersion: true,
editLocalizedDocs: true,
},
locale: 'fr',
});

const testUtilsLocal = createTestUtils({
siteDir,
context,
options,
versionMetadata: version100,
});

await testUtilsLocal.testMeta(path.join('hello.md'), {
id: 'version-1.0.0/hello',
unversionedId: 'hello',
isDocsHomePage: false,
permalink: '/fr/docs/1.0.0/hello',
slug: '/hello',
title: 'hello',
description: 'Hello 1.0.0 ! (translated fr)',
version: '1.0.0',
source:
'@site/i18n/fr/docusaurus-plugin-content-docs/version-1.0.0/hello.md',
editUrl:
'https://github.com/facebook/docusaurus/edit/master/website/i18n/fr/docusaurus-plugin-content-docs/current/hello.md',
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ describe('normalizeDocsPluginOptions', () => {
excludeNextVersionDocs: true,
includeCurrentVersion: false,
disableVersioning: true,
editCurrentVersion: true,
editLocalizedDocs: true,
versions: {
current: {
path: 'next',
Expand Down
Loading