Skip to content

Commit

Permalink
[v4] sync with nextra 3.0.15 / bump to Next 15 (#3508)
Browse files Browse the repository at this point in the history
* aa

* more

* more

* more

* aa

* pnpm-lock.yaml

* yoyoyo

* more

* rrr

* fix

* pnpm i

* dedupe

* Update examples/blog/mdx-components.jsx

* yoyo
  • Loading branch information
dimaMachina authored Oct 19, 2024
1 parent 63369a1 commit 2c8a8ab
Show file tree
Hide file tree
Showing 36 changed files with 507 additions and 579 deletions.
14 changes: 14 additions & 0 deletions .changeset/serious-pets-design.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
---
'nextra-theme-blog': patch
'nextra-theme-docs': patch
'nextra': patch
---

- sync with nextra 3.0.15
- bump to Next 15
- remove importing of `style.css` in themes, you need to import now manually by

```js
import 'nextra-theme-docs/style.css' // for docs theme
import 'nextra-theme-blog/style.css' // for blog theme
```
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ the docs repository, with the current website title prefilled:

| | | |
| ---------------- | ------------------------------------- | ----------------------------------------------------------------------------------- |
| feedback.content | `string \| ReactElement \| null{:ts}` | Content of the feedback link.<br/>Default: `"Question? Give us feedback"{:json}` |
| feedback.content | `string \| ReactElement \| null{:ts}` | Content of the feedback link.<br/>Default: `"Question? Give us feedback"{:json}` |
| feedback.labels | `string{:ts}` | Labels that can be added to the new created issue.<br/>Default: `"feedback"{:json}` |

</Table>
Expand Down
2 changes: 0 additions & 2 deletions docs/app/docs/guide/markdown/page.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,7 @@ export function Counter({ children }) {

Generates:

import { StarsIcon } from '@components/icons'
import { Shadow } from '@components/utils/shadow'
import { Cards } from 'nextra/components'
import { Counter } from './_counter'

<div className="mt-6 rounded-xl border border-gray-200 p-4 dark:border-gray-900">
Expand Down
2 changes: 1 addition & 1 deletion docs/app/docs/guide/organize-files/page.mdx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { FileIcon, NewsletterIcon } from '@components/icons'
import { Callout, Cards, FileTree } from 'nextra/components'
import { Cards, FileTree } from 'nextra/components'

# Organize Files

Expand Down
6 changes: 6 additions & 0 deletions docs/app/env.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
declare module '*.svg?svgr' {
import type { FC, SVGProps } from 'react'
const ReactComponent: FC<SVGProps<SVGElement>>

export default ReactComponent
}
23 changes: 11 additions & 12 deletions docs/app/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { getPageMap } from 'nextra/page-map'
import type { ReactNode } from 'react'
import './globals.css'
import cn from 'clsx'
import 'nextra-theme-docs/style.css'

export const viewport: Viewport = Head.viewport

Expand Down Expand Up @@ -57,6 +58,15 @@ export default async function RootLayout({
}: {
children: ReactNode
}) {
const logo = (
<NextraLogo
height="20"
className={cn(
'[mask-position:0] [mask-size:400%] [mask-image:linear-gradient(60deg,#000_25%,rgba(0,0,0,.2)_50%,#000_75%)]',
'hover:[mask-position:100%] hover:[transition:mask-position_1s_ease]'
)}
/>
)
return (
<html
lang="en"
Expand All @@ -80,18 +90,7 @@ export default async function RootLayout({
</Link>
</div>
</Banner>
<Navbar
logo={
<NextraLogo
height="20"
className={cn(
'[mask-position:0] [mask-size:400%] [mask-image:linear-gradient(60deg,#000_25%,rgba(0,0,0,.2)_50%,#000_75%)]',
'hover:[mask-position:100%] hover:[transition:mask-position_1s_ease]'
)}
/>
}
projectLink="https:/shuding/nextra"
/>
<Navbar logo={logo} projectLink="https:/shuding/nextra" />
{children}
<Footer className="flex-col items-center md:items-start">
<a
Expand Down
58 changes: 29 additions & 29 deletions docs/components/icons/index.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
export { default as FilesIcon } from './files.svg'
export { default as TailwindIcon } from './tailwind.svg'
export { default as LinkIcon } from './link.svg'
export { default as LightningIcon } from './lightning.svg'
export { default as GlobeIcon } from './globe.svg'
export { default as PictureIcon } from './picture.svg'
export { default as CodeIcon } from './code.svg'
export { default as BrushIcon } from './brush.svg'
export { default as DropperIcon } from './dropper.svg'
export { default as StarsIcon } from './stars.svg'
export { default as FormulaIcon } from './formula.svg'
export { default as WarningIcon } from './warning.svg'
export { default as ChevronRightIcon } from './chevron-right.svg'
export { default as BoxIcon } from './box.svg'
export { default as GearIcon } from './gear.svg'
export { default as RowsIcon } from './rows.svg'
export { default as CardsIcon } from './cards.svg'
export { default as OneIcon } from './one.svg'
export { default as CloudIcon } from './cloud.svg'
export { default as TableIcon } from './table.svg'
export { default as FileIcon } from './file.svg'
export { default as NewsletterIcon } from './newsletter.svg'
export { default as ArrowRightIcon } from './arrow-right.svg'
export { default as SwitchIcon } from './switch.svg'
export { default as DiagramIcon } from './diagram.svg'
export { default as FolderTreeIcon } from './folder-tree.svg'
export { default as IdCardIcon } from './id-card.svg'
export { default as VercelLogo } from './vercel.svg'
export { default as NextraLogo } from './nextra.svg'
export { default as FilesIcon } from './files.svg?svgr'
export { default as TailwindIcon } from './tailwind.svg?svgr'
export { default as LinkIcon } from './link.svg?svgr'
export { default as LightningIcon } from './lightning.svg?svgr'
export { default as GlobeIcon } from './globe.svg?svgr'
export { default as PictureIcon } from './picture.svg?svgr'
export { default as CodeIcon } from './code.svg?svgr'
export { default as BrushIcon } from './brush.svg?svgr'
export { default as DropperIcon } from './dropper.svg?svgr'
export { default as StarsIcon } from './stars.svg?svgr'
export { default as FormulaIcon } from './formula.svg?svgr'
export { default as WarningIcon } from './warning.svg?svgr'
export { default as ChevronRightIcon } from './chevron-right.svg?svgr'
export { default as BoxIcon } from './box.svg?svgr'
export { default as GearIcon } from './gear.svg?svgr'
export { default as RowsIcon } from './rows.svg?svgr'
export { default as CardsIcon } from './cards.svg?svgr'
export { default as OneIcon } from './one.svg?svgr'
export { default as CloudIcon } from './cloud.svg?svgr'
export { default as TableIcon } from './table.svg?svgr'
export { default as FileIcon } from './file.svg?svgr'
export { default as NewsletterIcon } from './newsletter.svg?svgr'
export { default as ArrowRightIcon } from './arrow-right.svg?svgr'
export { default as SwitchIcon } from './switch.svg?svgr'
export { default as DiagramIcon } from './diagram.svg?svgr'
export { default as FolderTreeIcon } from './folder-tree.svg?svgr'
export { default as IdCardIcon } from './id-card.svg?svgr'
export { default as VercelLogo } from './vercel.svg?svgr'
export { default as NextraLogo } from './nextra.svg?svgr'
32 changes: 13 additions & 19 deletions docs/next.config.mjs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import path from 'node:path'
import nextra from 'nextra'

/**
Expand All @@ -9,10 +8,6 @@ const withNextra = nextra({
defaultShowCopyCode: true
})

const sep = path.sep === '/' ? '/' : '\\\\'

const ALLOWED_SVG_RE = new RegExp(`components${sep}icons${sep}.+\\.svg$`)

/**
* @type {import('next').NextConfig}
*/
Expand Down Expand Up @@ -45,27 +40,26 @@ export default withNextra({
}
],
webpack(config) {
const fileLoaderRule = config.module.rules.find(rule =>
rule.test?.test?.('.svg')
// rule.exclude doesn't work starting from Next.js 15
const { test: _test, ...imageLoaderOptions } = config.module.rules.find(
rule => rule.test?.test?.('.svg')
)
fileLoaderRule.exclude = ALLOWED_SVG_RE

config.module.rules.push({
test: ALLOWED_SVG_RE,
use: [
test: /\.svg$/,
oneOf: [
{
loader: '@svgr/webpack',
options: {
svgoConfig: {
plugins: ['removeXMLNS']
}
}
}
resourceQuery: /svgr/,
use: ['@svgr/webpack']
},
imageLoaderOptions
]
})
return config
},
experimental: {
optimizePackageImports: ['@components/icons', 'nextra/components']
optimizePackageImports: [
// '@components/icons',
'nextra/components'
]
}
})
6 changes: 4 additions & 2 deletions examples/blog/app/tags/[tag]/page.jsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import { PostCard } from 'nextra-theme-blog'
import { getPosts, getTags } from '../../posts/get-posts'

export function generateMetadata({ params }) {
export async function generateMetadata(props) {
const params = await props.params
return {
title: `Posts Tagged with “${decodeURIComponent(params.tag)}”`
}
Expand All @@ -12,7 +13,8 @@ export async function generateStaticParams() {
return [...new Set(allTags)].map(tag => ({ tag }))
}

export default async function TagPage({ params }) {
export default async function TagPage(props) {
const params = await props.params
return (
<>
<h1>{generateMetadata({ params }).title}</h1>
Expand Down
50 changes: 27 additions & 23 deletions examples/blog/mdx-components.jsx
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
import { useMDXComponents as useBlogMDXComponents } from 'nextra-theme-blog'
import { useMDXComponents as getBlogMDXComponents } from 'nextra-theme-blog'

// In case you want to overwrite some of the components
export function useMDXComponents() {
return useBlogMDXComponents({
h1: ({ children }) => (
<h1
style={{
WebkitBackgroundClip: 'text',
WebkitTextFillColor: 'transparent',
backgroundClip: 'text',
backgroundImage: 'linear-gradient(90deg,#7928CA,#FF0080)'
}}
>
{children}
</h1>
),
DateFormatter: ({ date }) =>
`Last updated at ${date.toLocaleDateString('en', {
day: 'numeric',
month: 'long',
year: 'numeric'
})}`
})
const blogComponents = getBlogMDXComponents({
h1: ({ children }) => (
<h1
style={{
WebkitBackgroundClip: 'text',
WebkitTextFillColor: 'transparent',
backgroundClip: 'text',
backgroundImage: 'linear-gradient(90deg,#7928CA,#FF0080)'
}}
>
{children}
</h1>
),
DateFormatter: ({ date }) =>
`Last updated at ${date.toLocaleDateString('en', {
day: 'numeric',
month: 'long',
year: 'numeric'
})}`
})

export function useMDXComponents(components) {
return {
...blogComponents,
...components
}
}
8 changes: 0 additions & 8 deletions examples/blog/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,5 @@
"nextra-theme-blog": "workspace:*",
"react": "18.3.1",
"react-dom": "18.3.1"
},
"dependenciesMeta": {
"nextra": {
"injected": true
},
"nextra-theme-blog": {
"injected": true
}
}
}
8 changes: 5 additions & 3 deletions examples/docs/app/[[...mdxPath]]/page.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,21 @@ import { generateStaticParamsFor, importPage } from 'nextra/pages'
export const generateStaticParams = generateStaticParamsFor('mdxPath')

export async function generateMetadata(props) {
const { metadata } = await importPage(props.params.mdxPath)
const params = await props.params
const { metadata } = await importPage(params.mdxPath)
return metadata
}

export default async function Page(props) {
const result = await importPage(props.params.mdxPath)
const params = await props.params
const result = await importPage(params.mdxPath)
const { default: MDXContent, useTOC, metadata, title } = result

const Wrapper = useMDXComponents().wrapper

return (
<Wrapper toc={useTOC()} metadata={metadata} title={title}>
<MDXContent {...props} />
<MDXContent {...props} params={params} />
</Wrapper>
)
}
1 change: 1 addition & 0 deletions examples/docs/app/layout.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
import { Layout, Navbar } from 'nextra-theme-docs'
import { Banner, Head } from 'nextra/components'
import { getPageMap } from 'nextra/page-map'
import 'nextra-theme-docs/style.css'

export const { viewport } = Head

Expand Down
9 changes: 5 additions & 4 deletions examples/swr-site/app/[lang]/[[...mdxPath]]/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { useMDXComponents } from '../../../mdx-components'

export const generateStaticParams = generateStaticParamsFor('mdxPath')

export async function generateMetadata({ params }: PageProps) {
export async function generateMetadata(props: PageProps) {
const params = await props.params
const { metadata } = await importPage(params.mdxPath, params.lang)
return metadata
}
Expand All @@ -18,14 +19,14 @@ type PageProps = {
}

export default async function Page(props: PageProps) {
const { mdxPath, lang } = props.params
const result = await importPage(mdxPath, lang)
const params = await props.params
const result = await importPage(params.mdxPath, params.lang)
const { default: MDXContent, useTOC, metadata, title } = result
const Wrapper = useMDXComponents().wrapper

return (
<Wrapper toc={useTOC()} metadata={metadata} title={title}>
<MDXContent {...props} />
<MDXContent {...props} params={params} />
</Wrapper>
)
}
3 changes: 2 additions & 1 deletion examples/swr-site/app/[lang]/layout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@ export const metadata: Metadata = {
}
}

export default async function RootLayout({ children, params: { lang } }) {
export default async function RootLayout({ children, params }) {
const { lang } = await params
const dictionary = await getDictionary(lang)
let pageMap = await getPageMap(lang)

Expand Down
Loading

0 comments on commit 2c8a8ab

Please sign in to comment.