refactor(theme-classic): completely migrate package to TypeScript (#5459)

* Migrate

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

* Migrate prism as well

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

* Fix

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

* Fix lock file

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

* Fix typing

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

* refactor a bit CodeBlock

* simplify versionBanner typing => use null instead of "none" (apart plugin options for retrocompatibility)

* Remove return signatures

Signed-off-by: Josh-Cena <sidachen2003@gmail.com>

Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
Joshua Chen 2021-09-01 20:34:26 +08:00 committed by GitHub
parent 5f003bcabd
commit 78d84006bb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
19 changed files with 153 additions and 95 deletions

View file

@ -514,7 +514,7 @@ Object {
\\"pluginId\\": \\"default\\",
\\"version\\": \\"current\\",
\\"label\\": \\"Next\\",
\\"banner\\": \\"none\\",
\\"banner\\": null,
\\"badge\\": false,
\\"className\\": \\"docs-version-current\\",
\\"isLast\\": true,
@ -1025,7 +1025,7 @@ Object {
\\"pluginId\\": \\"community\\",
\\"version\\": \\"1.0.0\\",
\\"label\\": \\"1.0.0\\",
\\"banner\\": \\"none\\",
\\"banner\\": null,
\\"badge\\": true,
\\"className\\": \\"docs-version-1.0.0\\",
\\"isLast\\": true,
@ -1722,7 +1722,7 @@ Object {
\\"pluginId\\": \\"default\\",
\\"version\\": \\"1.0.1\\",
\\"label\\": \\"1.0.1\\",
\\"banner\\": \\"none\\",
\\"banner\\": null,
\\"badge\\": true,
\\"className\\": \\"docs-version-1.0.1\\",
\\"isLast\\": true,

View file

@ -81,7 +81,7 @@ describe('simple site', () => {
versionLabel: 'Next',
versionName: 'current',
versionPath: '/docs',
versionBanner: 'none',
versionBanner: null,
versionBadge: false,
versionClassName: 'docs-version-current',
};
@ -262,7 +262,7 @@ describe('versioned site, pluginId=default', () => {
versionLabel: '1.0.1',
versionName: '1.0.1',
versionPath: '/docs',
versionBanner: 'none',
versionBanner: null,
versionBadge: true,
versionClassName: 'docs-version-1.0.1',
};
@ -554,7 +554,7 @@ describe('versioned site, pluginId=default', () => {
routePriority: -1,
tagsPath: '/docs/tags',
versionPath: '/docs',
versionBanner: 'none',
versionBanner: null,
versionBadge: false,
},
]);
@ -702,7 +702,7 @@ describe('versioned site, pluginId=community', () => {
versionLabel: '1.0.0',
versionName: '1.0.0',
versionPath: '/communityBasePath',
versionBanner: 'none',
versionBanner: null,
versionBadge: true,
versionClassName: 'docs-version-1.0.0',
};
@ -750,7 +750,7 @@ describe('versioned site, pluginId=community', () => {
routePriority: -1,
tagsPath: '/communityBasePath/tags',
versionPath: '/communityBasePath',
versionBanner: 'none',
versionBanner: null,
versionBadge: false,
},
]);

View file

@ -11,7 +11,7 @@ declare module '@docusaurus/plugin-content-docs' {
// TODO public api surface types should rather be exposed as "@docusaurus/plugin-content-docs"
declare module '@docusaurus/plugin-content-docs-types' {
type VersionBanner = import('./types').VersionBanner;
export type VersionBanner = import('./types').VersionBanner;
type GlobalDataVersion = import('./types').GlobalVersion;
type GlobalDataDoc = import('./types').GlobalDoc;
type VersionTag = import('./types').VersionTag;
@ -22,7 +22,7 @@ declare module '@docusaurus/plugin-content-docs-types' {
pluginId: string;
version: string;
label: string;
banner: VersionBanner;
banner: VersionBanner | null;
badge: boolean;
className: string;
isLast: boolean;

View file

@ -32,7 +32,7 @@ export type VersionMetadata = ContentPaths & {
tagsPath: string;
versionEditUrl?: string | undefined;
versionEditUrlLocalized?: string | undefined;
versionBanner: VersionBanner;
versionBanner: VersionBanner | null;
versionBadge: boolean;
versionClassName: string;
isLast: boolean;
@ -65,12 +65,12 @@ export type PathOptions = {
};
// TODO support custom version banner? {type: "error", content: "html content"}
export type VersionBanner = 'none' | 'unreleased' | 'unmaintained';
export type VersionBanner = 'unreleased' | 'unmaintained';
export type VersionOptions = {
path?: string;
label?: string;
banner?: VersionBanner;
banner?: 'none' | VersionBanner;
badge?: boolean;
className?: string;
};

View file

@ -264,10 +264,10 @@ function getDefaultVersionBanner({
versionName: string;
versionNames: string[];
lastVersionName: string;
}): VersionBanner {
}): VersionBanner | null {
// Current version: good, no banner
if (versionName === lastVersionName) {
return 'none';
return null;
}
// Upcoming versions: unreleased banner
else if (
@ -291,17 +291,16 @@ function getVersionBanner({
versionNames: string[];
lastVersionName: string;
options: Pick<PluginOptions, 'versions'>;
}): VersionBanner {
const versionOptionBanner = options.versions[versionName]?.banner;
return (
versionOptionBanner ??
getDefaultVersionBanner({
versionName,
versionNames,
lastVersionName,
})
);
}): VersionBanner | null {
const versionBannerOption = options.versions[versionName]?.banner;
if (versionBannerOption) {
return versionBannerOption === 'none' ? null : versionBannerOption;
}
return getDefaultVersionBanner({
versionName,
versionNames,
lastVersionName,
});
}
function getVersionBadge({