Skip to content

Commit

Permalink
fix(content-docs): translate generated index pagination title
Browse files Browse the repository at this point in the history
  • Loading branch information
Josh-Cena committed Oct 26, 2022
1 parent 006d440 commit 0835d5f
Show file tree
Hide file tree
Showing 9 changed files with 28 additions and 237 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"drafts": [],
"isLast": true,
"label": "current label (translated)",
"noIndex": false,
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",
Expand Down Expand Up @@ -399,6 +400,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"drafts": [],
"isLast": true,
"label": "2.0.0 label (translated)",
"noIndex": false,
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",
Expand Down Expand Up @@ -575,6 +577,7 @@ exports[`translateLoadedContent returns translated loaded content 1`] = `
"drafts": [],
"isLast": true,
"label": "1.0.0 label (translated)",
"noIndex": false,
"path": "/docs/",
"routePriority": undefined,
"sidebarFilePath": "any",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ import {DisabledSidebars} from '../sidebars';
import * as cliDocs from '../cli';
import {validateOptions} from '../options';

import type {FullVersion} from '../types';
import type {RouteConfig, Validate, Plugin} from '@docusaurus/types';
import type {
LoadedVersion,
Expand Down Expand Up @@ -108,7 +109,9 @@ Entries created:
const versionMetadataProp = getCreatedDataByPrefix(
`version-${_.kebabCase(version.versionName)}-metadata-prop`,
);
expect(versionMetadataProp.docsSidebars).toEqual(toSidebarsProp(version));
expect(versionMetadataProp.docsSidebars).toEqual(
toSidebarsProp(version as FullVersion),
);
},

expectSnapshot: () => {
Expand Down Expand Up @@ -608,7 +611,7 @@ describe('site with doc label', () => {
it('label in sidebar.json is used', async () => {
const {content} = await loadSite();
const loadedVersion = content.loadedVersions[0]!;
const sidebarProps = toSidebarsProp(loadedVersion);
const sidebarProps = toSidebarsProp(loadedVersion as FullVersion);

expect((sidebarProps.docs![0] as PropSidebarItemLink).label).toBe(
'Hello One',
Expand All @@ -618,7 +621,7 @@ describe('site with doc label', () => {
it('sidebar_label in doc has higher precedence over label in sidebar.json', async () => {
const {content} = await loadSite();
const loadedVersion = content.loadedVersions[0]!;
const sidebarProps = toSidebarsProp(loadedVersion);
const sidebarProps = toSidebarsProp(loadedVersion as FullVersion);

expect((sidebarProps.docs![1] as PropSidebarItemLink).label).toBe(
'Hello 2 From Doc',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ function createSampleVersion(
badge: true,
className: '',
drafts: [],
noIndex: false,
docs: [
createSampleDoc({id: 'doc1'}),
createSampleDoc({id: 'doc2'}),
Expand Down
21 changes: 2 additions & 19 deletions packages/docusaurus-plugin-content-docs/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,7 @@ import {
} from '@docusaurus/utils';
import {loadSidebars, resolveSidebarPathOption} from './sidebars';
import {CategoryMetadataFilenamePattern} from './sidebars/generator';
import {
readVersionDocs,
processDocMetadata,
addDocNavigation,
type DocEnv,
} from './docs';
import {readVersionDocs, processDocMetadata, type DocEnv} from './docs';
import {readVersionsMetadata, toFullVersion} from './versions';
import {cliDocsVersionCommand} from './cli';
import {VERSIONS_JSON_FILE} from './constants';
Expand All @@ -36,7 +31,6 @@ import {
getLoadedContentTranslationFiles,
} from './translations';
import {createAllRoutes} from './routes';
import {createSidebarsUtils} from './sidebars/utils';

import type {
PluginOptions,
Expand Down Expand Up @@ -171,18 +165,7 @@ export default async function pluginContentDocs(
categoryLabelSlugger: createSlugger(),
});

const sidebarsUtils = createSidebarsUtils(sidebars);

return {
...versionMetadata,
docs: addDocNavigation(
docs,
sidebarsUtils,
versionMetadata.sidebarFilePath as string,
),
drafts,
sidebars,
};
return {...versionMetadata, docs, drafts, sidebars};
}

async function loadVersion(versionMetadata: VersionMetadata) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -559,8 +559,8 @@ declare module '@docusaurus/plugin-content-docs' {
};

export type LoadedVersion = VersionMetadata & {
docs: DocMetadata[];
drafts: DocMetadata[];
docs: DocMetadataBase[];
drafts: DocMetadataBase[];
sidebars: import('./sidebars/types').Sidebars;
};

Expand Down
9 changes: 4 additions & 5 deletions packages/docusaurus-plugin-content-docs/src/props.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

import _ from 'lodash';
import {createDocsByIdIndex} from './docs';
import type {VersionTag, VersionTags} from './types';
import type {VersionTag, VersionTags, FullVersion} from './types';
import type {
SidebarItemDoc,
SidebarItem,
Expand All @@ -25,10 +25,9 @@ import type {
PropSidebarItemLink,
PropVersionDocs,
DocMetadata,
LoadedVersion,
} from '@docusaurus/plugin-content-docs';

export function toSidebarsProp(loadedVersion: LoadedVersion): PropSidebars {
export function toSidebarsProp(loadedVersion: FullVersion): PropSidebars {
const docsById = createDocsByIdIndex(loadedVersion.docs);

function getDocById(docId: string): DocMetadata {
Expand Down Expand Up @@ -119,7 +118,7 @@ Available document ids are:
);
}

function toVersionDocsProp(loadedVersion: LoadedVersion): PropVersionDocs {
function toVersionDocsProp(loadedVersion: FullVersion): PropVersionDocs {
return Object.fromEntries(
loadedVersion.docs.map((doc) => [
doc.unversionedId,
Expand All @@ -135,7 +134,7 @@ function toVersionDocsProp(loadedVersion: LoadedVersion): PropVersionDocs {

export function toVersionMetadataProp(
pluginId: string,
loadedVersion: LoadedVersion,
loadedVersion: FullVersion,
): PropVersionMetadata {
return {
pluginId,
Expand Down
5 changes: 4 additions & 1 deletion packages/docusaurus-plugin-content-docs/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import type {BrokenMarkdownLink, Tag} from '@docusaurus/utils';
import type {
VersionMetadata,
LoadedVersion,
DocMetadata,
CategoryGeneratedIndexMetadata,
} from '@docusaurus/plugin-content-docs';
import type {SidebarsUtils} from './sidebars/utils';
Expand All @@ -32,7 +33,9 @@ export type VersionTags = {
[permalink: string]: VersionTag;
};

export type FullVersion = LoadedVersion & {
export type FullVersion = Omit<LoadedVersion, 'docs' | 'drafts'> & {
docs: DocMetadata[];
drafts: DocMetadata[];
sidebarsUtils: SidebarsUtils;
categoryGeneratedIndices: CategoryGeneratedIndexMetadata[];
};
Expand Down
6 changes: 6 additions & 0 deletions packages/docusaurus-plugin-content-docs/src/versions/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
} from './files';
import {createSidebarsUtils} from '../sidebars/utils';
import {getCategoryGeneratedIndexMetadataList} from '../categoryGeneratedIndex';
import {addDocNavigation} from '../docs';
import type {FullVersion} from '../types';
import type {LoadContext} from '@docusaurus/types';
import type {
Expand Down Expand Up @@ -261,6 +262,11 @@ export function toFullVersion(version: LoadedVersion): FullVersion {
const sidebarsUtils = createSidebarsUtils(version.sidebars);
return {
...version,
docs: addDocNavigation(
version.docs,
sidebarsUtils,
version.sidebarFilePath as string,
),
sidebarsUtils,
categoryGeneratedIndices: getCategoryGeneratedIndexMetadataList({
docs: version.docs,
Expand Down

0 comments on commit 0835d5f

Please sign in to comment.