diff --git a/.changeset/moody-jars-film.md b/.changeset/moody-jars-film.md new file mode 100644 index 00000000000..3babe0188eb --- /dev/null +++ b/.changeset/moody-jars-film.md @@ -0,0 +1,6 @@ +--- +"nextra-theme-docs": patch +"nextra": patch +--- + +add `bottomContent` prop for `` component, e.g. to put some content after pagination in `nextra-theme-docs` diff --git a/.changeset/sharp-foxes-carry.md b/.changeset/sharp-foxes-carry.md new file mode 100644 index 00000000000..51e3eeb3e70 --- /dev/null +++ b/.changeset/sharp-foxes-carry.md @@ -0,0 +1,7 @@ +--- +"nextra-theme-blog": patch +"nextra-theme-docs": patch +"nextra": patch +--- + +fix `colorSchema` for HEX format with 4 chars, e.g. `#111` diff --git a/.changeset/short-bulldogs-matter.md b/.changeset/short-bulldogs-matter.md new file mode 100644 index 00000000000..5eb71ba09d2 --- /dev/null +++ b/.changeset/short-bulldogs-matter.md @@ -0,0 +1,5 @@ +--- +"nextra-theme-blog": patch +--- + +make nextThemes optional prop, to avoid ts errors diff --git a/packages/nextra-theme-blog/src/components/layout.tsx b/packages/nextra-theme-blog/src/components/layout.tsx index 0f0b822b7d1..5df42dca30d 100644 --- a/packages/nextra-theme-blog/src/components/layout.tsx +++ b/packages/nextra-theme-blog/src/components/layout.tsx @@ -14,7 +14,7 @@ export const Footer: FC<{ export const Layout: FC<{ children: ReactNode - nextThemes: Omit, 'children'> + nextThemes?: Omit, 'children'> banner?: ReactElement }> = ({ children, nextThemes, banner }) => { return ( diff --git a/packages/nextra-theme-docs/src/mdx-components/index.tsx b/packages/nextra-theme-docs/src/mdx-components/index.tsx index dfd7adda74f..679c87ead52 100644 --- a/packages/nextra-theme-docs/src/mdx-components/index.tsx +++ b/packages/nextra-theme-docs/src/mdx-components/index.tsx @@ -82,7 +82,7 @@ const DEFAULT_COMPONENTS = getNextraMDXComponents({ {...props} /> ), - wrapper({ toc, children, metadata, ...props }) { + wrapper({ toc, children, metadata, bottomContent, ...props }) { // @ts-expect-error fixme toc = toc.map(item => ({ ...item, @@ -96,7 +96,11 @@ const DEFAULT_COMPONENTS = getNextraMDXComponents({ > - +
{ +export const ClientWrapper: MDXWrapper = ({ + toc, + children, + metadata, + bottomContent +}) => { const { activeType, activeThemeContext: themeContext, @@ -57,6 +62,7 @@ export const ClientWrapper: MDXWrapper = ({ toc, children, metadata }) => {
)} {themeContext.pagination && activeType !== 'page' && } + {bottomContent} ) diff --git a/packages/nextra/src/client/components/head.tsx b/packages/nextra/src/client/components/head.tsx index cfe80321342..b0fe3a6192e 100644 --- a/packages/nextra/src/client/components/head.tsx +++ b/packages/nextra/src/client/components/head.tsx @@ -12,25 +12,40 @@ const darkLightSchema = z ]) .transform(v => (typeof v === 'number' ? { dark: v, light: v } : v)) -function hexToRgb(hex: `#${string}`): string { - const bigint = Number.parseInt(hex.slice(1), 16) +function hexToRgb(hex: string): string { + hex = hex.slice(1) + if (hex.length === 3) { + hex = hex + // eslint-disable-next-line unicorn/prefer-spread -- https://github.com/sindresorhus/eslint-plugin-unicorn/issues/2521#issuecomment-2564033898 + .split('') + .map(char => char + char) + .join('') + } + const bigint = Number.parseInt(hex, 16) const r = (bigint >> 16) & 255 const g = (bigint >> 8) & 255 const b = bigint & 255 return `${r},${g},${b}` } +const RGB_RE = /^rgb\((?.*?)\)$/ +const HEX_RE = /^#(?[0-9a-f]{3,6})$/i + const colorSchema = z - .union([ - z.string().startsWith('#'), - z.string().startsWith('rgb('), - z.string().regex(/^\d{1,3},\d{1,3},\d{1,3}$/) - ]) + .string() + .refine(str => { + if (HEX_RE.test(str) || RGB_RE.test(str)) { + return true + } + throw new Error( + 'Color format should be in HEX or RGB format. E.g. #000, #112233 or rgb(255,255,255)' + ) + }) .transform(value => { if (value.startsWith('#')) { - return hexToRgb(value as `#${string}`) + return hexToRgb(value) } - const rgb = value.match(/^rgb\((?.*?)\)$/)?.groups!.rgb + const rgb = value.match(RGB_RE)?.groups!.rgb if (rgb) { return rgb.replaceAll(' ', '') } diff --git a/packages/nextra/src/types.ts b/packages/nextra/src/types.ts index 2a69b16b2c4..26991656936 100644 --- a/packages/nextra/src/types.ts +++ b/packages/nextra/src/types.ts @@ -99,6 +99,7 @@ export type MDXWrapper = FC<{ toc: Heading[] children: ReactNode metadata: NextraMetadata + bottomContent?: ReactNode }> export type MetaRecord = Record>