@docusaurus/theme-classic 0.0.0-4685 → 0.0.0-4687

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/lib/index.js CHANGED
@@ -112,25 +112,22 @@ function getInfimaCSSFile(direction) {
112
112
 
113
113
  function docusaurusThemeClassic(context, options) {
114
114
  const {
115
- siteConfig: {
116
- themeConfig: roughlyTypedThemeConfig
117
- },
118
115
  i18n: {
119
116
  currentLocale,
120
117
  localeConfigs
121
118
  }
122
119
  } = context;
123
- const themeConfig = roughlyTypedThemeConfig || {};
120
+ const themeConfig = context.siteConfig.themeConfig;
124
121
  const {
125
122
  announcementBar,
126
123
  colorMode,
127
124
  prism: {
128
- additionalLanguages = []
129
- } = {}
125
+ additionalLanguages
126
+ }
130
127
  } = themeConfig;
131
128
  const {
132
129
  customCss
133
- } = options || {};
130
+ } = options ?? {};
134
131
  const {
135
132
  direction
136
133
  } = localeConfigs[currentLocale];
@@ -257,7 +257,7 @@ const ThemeConfigSchema = _utilsValidation.Joi.object({
257
257
  style: _utilsValidation.Joi.string().equal('dark', 'light').default('light'),
258
258
  logo: _utilsValidation.Joi.object({
259
259
  alt: _utilsValidation.Joi.string().allow(''),
260
- src: _utilsValidation.Joi.string(),
260
+ src: _utilsValidation.Joi.string().required(),
261
261
  srcDark: _utilsValidation.Joi.string(),
262
262
  // TODO infer this from reading the image
263
263
  width: _utilsValidation.Joi.alternatives().try(_utilsValidation.Joi.string(), _utilsValidation.Joi.number()),
@@ -45,7 +45,7 @@ function YearsSection({years}) {
45
45
  function listPostsByYears(blogPosts) {
46
46
  const postsByYear = blogPosts.reduceRight((posts, post) => {
47
47
  const year = post.metadata.date.split('-')[0];
48
- const yearPosts = posts.get(year) || [];
48
+ const yearPosts = posts.get(year) ?? [];
49
49
  return posts.set(year, [post, ...yearPosts]);
50
50
  }, new Map());
51
51
  return Array.from(postsByYear, ([year, posts]) => ({
@@ -8,7 +8,7 @@ import React from 'react';
8
8
  import clsx from 'clsx';
9
9
  import Link from '@docusaurus/Link';
10
10
  import {useThemeConfig} from '@docusaurus/theme-common';
11
- import useBaseUrl from '@docusaurus/useBaseUrl';
11
+ import useBaseUrl, {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
12
12
  import isInternalUrl from '@docusaurus/isInternalUrl';
13
13
  import styles from './styles.module.css';
14
14
  import ThemedImage from '@theme/ThemedImage';
@@ -42,16 +42,37 @@ function FooterLink({to, href, label, prependBaseUrlToHref, ...props}) {
42
42
  );
43
43
  }
44
44
 
45
- function FooterLogo({sources, alt, width, height}) {
46
- return (
45
+ function FooterLogo({logo}) {
46
+ const {withBaseUrl} = useBaseUrlUtils();
47
+
48
+ if (!logo?.src) {
49
+ return null;
50
+ }
51
+
52
+ const sources = {
53
+ light: withBaseUrl(logo.src),
54
+ dark: withBaseUrl(logo.srcDark ?? logo.src),
55
+ };
56
+ const image = (
47
57
  <ThemedImage
48
58
  className="footer__logo"
49
- alt={alt}
59
+ alt={logo.alt}
50
60
  sources={sources}
51
- width={width}
52
- height={height}
61
+ width={logo.width}
62
+ height={logo.height}
53
63
  />
54
64
  );
65
+ return (
66
+ <div className="margin-bottom--sm">
67
+ {logo.href ? (
68
+ <Link href={logo.href} className={styles.footerLogoLink}>
69
+ {image}
70
+ </Link>
71
+ ) : (
72
+ image
73
+ )}
74
+ </div>
75
+ );
55
76
  }
56
77
 
57
78
  function MultiColumnLinks({links}) {
@@ -115,16 +136,12 @@ function isMultiColumnFooterLinks(links) {
115
136
 
116
137
  function Footer() {
117
138
  const {footer} = useThemeConfig();
118
- const {copyright, links = [], logo = {}} = footer || {};
119
- const sources = {
120
- light: useBaseUrl(logo.src),
121
- dark: useBaseUrl(logo.srcDark || logo.src),
122
- };
123
139
 
124
140
  if (!footer) {
125
141
  return null;
126
142
  }
127
143
 
144
+ const {copyright, links, logo} = footer;
128
145
  return (
129
146
  <footer
130
147
  className={clsx('footer', {
@@ -144,28 +161,8 @@ function Footer() {
144
161
  ))}
145
162
  {(logo || copyright) && (
146
163
  <div className="footer__bottom text--center">
147
- {logo && (logo.src || logo.srcDark) && (
148
- <div className="margin-bottom--sm">
149
- {logo.href ? (
150
- <Link href={logo.href} className={styles.footerLogoLink}>
151
- <FooterLogo
152
- alt={logo.alt}
153
- sources={sources}
154
- width={logo.width}
155
- height={logo.height}
156
- />
157
- </Link>
158
- ) : (
159
- <FooterLogo
160
- alt={logo.alt}
161
- sources={sources}
162
- width={logo.width}
163
- height={logo.height}
164
- />
165
- )}
166
- </div>
167
- )}
168
- {copyright ? (
164
+ <FooterLogo logo={logo} />
165
+ {copyright && (
169
166
  <div
170
167
  className="footer__copyright" // Developer provided the HTML, so assume it's safe.
171
168
  // eslint-disable-next-line react/no-danger
@@ -173,7 +170,7 @@ function Footer() {
173
170
  __html: copyright,
174
171
  }}
175
172
  />
176
- ) : null}
173
+ )}
177
174
  </div>
178
175
  )}
179
176
  </div>
@@ -12,7 +12,7 @@ import styles from './styles.module.css';
12
12
  export default function ThemedImage(props) {
13
13
  const isBrowser = useIsBrowser();
14
14
  const {isDarkTheme} = useColorMode();
15
- const {sources, className, alt = '', ...propsRest} = props;
15
+ const {sources, className, alt, ...propsRest} = props;
16
16
  const clientThemes = isDarkTheme ? ['dark'] : ['light'];
17
17
  const renderedSourceNames = isBrowser
18
18
  ? clientThemes // We need to render both images on the server to avoid flash
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@docusaurus/theme-classic",
3
- "version": "0.0.0-4685",
3
+ "version": "0.0.0-4687",
4
4
  "description": "Classic theme for Docusaurus",
5
5
  "main": "lib/index.js",
6
6
  "types": "src/theme-classic.d.ts",
@@ -21,15 +21,15 @@
21
21
  "format:lib-next": "prettier --config ../../.prettierrc --write \"lib-next/**/*.{js,ts,jsx,tsc}\""
22
22
  },
23
23
  "dependencies": {
24
- "@docusaurus/core": "0.0.0-4685",
25
- "@docusaurus/plugin-content-blog": "0.0.0-4685",
26
- "@docusaurus/plugin-content-docs": "0.0.0-4685",
27
- "@docusaurus/plugin-content-pages": "0.0.0-4685",
28
- "@docusaurus/theme-common": "0.0.0-4685",
29
- "@docusaurus/theme-translations": "0.0.0-4685",
30
- "@docusaurus/utils": "0.0.0-4685",
31
- "@docusaurus/utils-common": "0.0.0-4685",
32
- "@docusaurus/utils-validation": "0.0.0-4685",
24
+ "@docusaurus/core": "0.0.0-4687",
25
+ "@docusaurus/plugin-content-blog": "0.0.0-4687",
26
+ "@docusaurus/plugin-content-docs": "0.0.0-4687",
27
+ "@docusaurus/plugin-content-pages": "0.0.0-4687",
28
+ "@docusaurus/theme-common": "0.0.0-4687",
29
+ "@docusaurus/theme-translations": "0.0.0-4687",
30
+ "@docusaurus/utils": "0.0.0-4687",
31
+ "@docusaurus/utils-common": "0.0.0-4687",
32
+ "@docusaurus/utils-validation": "0.0.0-4687",
33
33
  "@mdx-js/react": "^1.6.22",
34
34
  "clsx": "^1.1.1",
35
35
  "copy-text-to-clipboard": "^3.0.1",
@@ -42,8 +42,8 @@
42
42
  "rtlcss": "^3.3.0"
43
43
  },
44
44
  "devDependencies": {
45
- "@docusaurus/module-type-aliases": "0.0.0-4685",
46
- "@docusaurus/types": "0.0.0-4685",
45
+ "@docusaurus/module-type-aliases": "0.0.0-4687",
46
+ "@docusaurus/types": "0.0.0-4687",
47
47
  "@types/mdx-js__react": "^1.5.5",
48
48
  "@types/prismjs": "^1.26.0",
49
49
  "@types/rtlcss": "^3.1.2",
@@ -59,5 +59,5 @@
59
59
  "engines": {
60
60
  "node": ">=14"
61
61
  },
62
- "gitHead": "3a492428ff3bf2051bc6b660803a735d67c8ae66"
62
+ "gitHead": "07732e16aa86d21c9c5713e03c7159201c2457de"
63
63
  }
package/src/index.ts CHANGED
@@ -97,16 +97,15 @@ export default function docusaurusThemeClassic(
97
97
  options: Options,
98
98
  ): Plugin<void> {
99
99
  const {
100
- siteConfig: {themeConfig: roughlyTypedThemeConfig},
101
100
  i18n: {currentLocale, localeConfigs},
102
101
  } = context;
103
- const themeConfig = (roughlyTypedThemeConfig || {}) as ThemeConfig;
102
+ const themeConfig = context.siteConfig.themeConfig as ThemeConfig;
104
103
  const {
105
104
  announcementBar,
106
105
  colorMode,
107
- prism: {additionalLanguages = []} = {},
106
+ prism: {additionalLanguages},
108
107
  } = themeConfig;
109
- const {customCss} = options || {};
108
+ const {customCss} = options ?? {};
110
109
  const {direction} = localeConfigs[currentLocale]!;
111
110
 
112
111
  return {
@@ -50,14 +50,11 @@ function YearsSection({years}: {years: YearProp[]}) {
50
50
  }
51
51
 
52
52
  function listPostsByYears(blogPosts: readonly ArchiveBlogPost[]): YearProp[] {
53
- const postsByYear: Map<string, ArchiveBlogPost[]> = blogPosts.reduceRight(
54
- (posts, post) => {
55
- const year = post.metadata.date.split('-')[0];
56
- const yearPosts = posts.get(year) || [];
57
- return posts.set(year, [post, ...yearPosts]);
58
- },
59
- new Map(),
60
- );
53
+ const postsByYear = blogPosts.reduceRight((posts, post) => {
54
+ const year = post.metadata.date.split('-')[0]!;
55
+ const yearPosts = posts.get(year) ?? [];
56
+ return posts.set(year, [post, ...yearPosts]);
57
+ }, new Map<string, ArchiveBlogPost[]>());
61
58
 
62
59
  return Array.from(postsByYear, ([year, posts]) => ({
63
60
  year,
@@ -15,10 +15,10 @@ import {
15
15
  type MultiColumnFooter,
16
16
  type SimpleFooter,
17
17
  } from '@docusaurus/theme-common';
18
- import useBaseUrl from '@docusaurus/useBaseUrl';
18
+ import useBaseUrl, {useBaseUrlUtils} from '@docusaurus/useBaseUrl';
19
19
  import isInternalUrl from '@docusaurus/isInternalUrl';
20
20
  import styles from './styles.module.css';
21
- import ThemedImage, {type Props as ThemedImageProps} from '@theme/ThemedImage';
21
+ import ThemedImage from '@theme/ThemedImage';
22
22
  import IconExternalLink from '@theme/IconExternalLink';
23
23
 
24
24
  function FooterLink({
@@ -54,21 +54,35 @@ function FooterLink({
54
54
  );
55
55
  }
56
56
 
57
- function FooterLogo({
58
- sources,
59
- alt,
60
- width,
61
- height,
62
- }: Pick<ThemedImageProps, 'sources' | 'alt' | 'width' | 'height'>) {
63
- return (
57
+ function FooterLogo({logo}: {logo: SimpleFooter['logo']}) {
58
+ const {withBaseUrl} = useBaseUrlUtils();
59
+ if (!logo?.src) {
60
+ return null;
61
+ }
62
+ const sources = {
63
+ light: withBaseUrl(logo.src),
64
+ dark: withBaseUrl(logo.srcDark ?? logo.src),
65
+ };
66
+ const image = (
64
67
  <ThemedImage
65
68
  className="footer__logo"
66
- alt={alt}
69
+ alt={logo.alt}
67
70
  sources={sources}
68
- width={width}
69
- height={height}
71
+ width={logo.width}
72
+ height={logo.height}
70
73
  />
71
74
  );
75
+ return (
76
+ <div className="margin-bottom--sm">
77
+ {logo.href ? (
78
+ <Link href={logo.href} className={styles.footerLogoLink}>
79
+ {image}
80
+ </Link>
81
+ ) : (
82
+ image
83
+ )}
84
+ </div>
85
+ );
72
86
  }
73
87
 
74
88
  function MultiColumnLinks({links}: {links: MultiColumnFooter['links']}) {
@@ -136,16 +150,10 @@ function isMultiColumnFooterLinks(
136
150
 
137
151
  function Footer(): JSX.Element | null {
138
152
  const {footer} = useThemeConfig();
139
-
140
- const {copyright, links = [], logo = {}} = footer || {};
141
- const sources = {
142
- light: useBaseUrl(logo.src),
143
- dark: useBaseUrl(logo.srcDark || logo.src),
144
- };
145
-
146
153
  if (!footer) {
147
154
  return null;
148
155
  }
156
+ const {copyright, links, logo} = footer;
149
157
 
150
158
  return (
151
159
  <footer
@@ -166,28 +174,8 @@ function Footer(): JSX.Element | null {
166
174
  ))}
167
175
  {(logo || copyright) && (
168
176
  <div className="footer__bottom text--center">
169
- {logo && (logo.src || logo.srcDark) && (
170
- <div className="margin-bottom--sm">
171
- {logo.href ? (
172
- <Link href={logo.href} className={styles.footerLogoLink}>
173
- <FooterLogo
174
- alt={logo.alt}
175
- sources={sources}
176
- width={logo.width}
177
- height={logo.height}
178
- />
179
- </Link>
180
- ) : (
181
- <FooterLogo
182
- alt={logo.alt}
183
- sources={sources}
184
- width={logo.width}
185
- height={logo.height}
186
- />
187
- )}
188
- </div>
189
- )}
190
- {copyright ? (
177
+ <FooterLogo logo={logo} />
178
+ {copyright && (
191
179
  <div
192
180
  className="footer__copyright"
193
181
  // Developer provided the HTML, so assume it's safe.
@@ -196,7 +184,7 @@ function Footer(): JSX.Element | null {
196
184
  __html: copyright,
197
185
  }}
198
186
  />
199
- ) : null}
187
+ )}
200
188
  </div>
201
189
  )}
202
190
  </div>
@@ -17,7 +17,7 @@ import styles from './styles.module.css';
17
17
  export default function ThemedImage(props: Props): JSX.Element {
18
18
  const isBrowser = useIsBrowser();
19
19
  const {isDarkTheme} = useColorMode();
20
- const {sources, className, alt = '', ...propsRest} = props;
20
+ const {sources, className, alt, ...propsRest} = props;
21
21
 
22
22
  type SourceName = keyof Props['sources'];
23
23
 
@@ -304,7 +304,7 @@ export const ThemeConfigSchema = Joi.object({
304
304
  style: Joi.string().equal('dark', 'light').default('light'),
305
305
  logo: Joi.object({
306
306
  alt: Joi.string().allow(''),
307
- src: Joi.string(),
307
+ src: Joi.string().required(),
308
308
  srcDark: Joi.string(),
309
309
  // TODO infer this from reading the image
310
310
  width: Joi.alternatives().try(Joi.string(), Joi.number()),