mirror of
https://github.com/facebook/docusaurus.git
synced 2025-05-17 02:56:57 +02:00
feat: properly type-check the Docusaurus config of new sites (#5589)
* fix: makes types DocusaurusConfig optional to match docs * add UserDocusaurusConfig with required keys for user config * convert UserDocusaurusConfig to use util type * Docusaurus website config should be type-checked by CI + fix all existing issues * add doc for config typechecking * Update template configs for TS autocompletion * fix last config typechecking bugs * reapply prettier * reapply prettier-docs * Fix TS doc: add missing () * fix some docu plugin types * add "const config" for simpler jsdoc annotation Co-authored-by: slorber <lorber.sebastien@gmail.com>
This commit is contained in:
parent
3f1f8255a2
commit
09550b0535
24 changed files with 115 additions and 35 deletions
|
@ -7,6 +7,7 @@
|
|||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import {PrismTheme} from 'prism-react-renderer';
|
||||
import {CSSProperties} from 'react';
|
||||
import {DeepPartial} from 'utility-types';
|
||||
|
||||
export type DocsVersionPersistence = 'localStorage' | 'none';
|
||||
|
||||
|
@ -16,7 +17,7 @@ export type NavbarItem = {
|
|||
items?: NavbarItem[];
|
||||
label?: string;
|
||||
position?: 'left' | 'right';
|
||||
};
|
||||
} & Record<string, unknown>;
|
||||
|
||||
export type NavbarLogo = {
|
||||
src: string;
|
||||
|
@ -90,6 +91,7 @@ export type TableOfContents = {
|
|||
maxHeadingLevel: number;
|
||||
};
|
||||
|
||||
// Theme config after validation/normalization
|
||||
export type ThemeConfig = {
|
||||
docs: {
|
||||
versionPersistence: DocsVersionPersistence;
|
||||
|
@ -112,6 +114,9 @@ export type ThemeConfig = {
|
|||
tableOfContents: TableOfContents;
|
||||
};
|
||||
|
||||
// User-provided theme config, unnormalized
|
||||
export type UserThemeConfig = DeepPartial<ThemeConfig>;
|
||||
|
||||
export function useThemeConfig(): ThemeConfig {
|
||||
return useDocusaurusContext().siteConfig.themeConfig as ThemeConfig;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue