From c8605d679d363787e424d85b7a74b47d4ca41d2c Mon Sep 17 00:00:00 2001 From: Shu Ding Date: Thu, 4 Aug 2022 01:53:58 +0200 Subject: [PATCH] New layout implementation (#631) * refactor loader and layout resolution * use global css import * test ssg * fix fast refresh * upadte snapshot * add changeset * remove @edge-runtime/vm * fix test * fix test * apply review suggestions * fix string template * update snapshot * deprecate the Nextra.* component * fix import * fix import * fix import --- .changeset/silent-phones-own.md | 7 ++ examples/blog/next.config.mjs | 18 +++- examples/blog/pages/_app.js | 8 -- examples/docs/next.config.js | 18 +++- examples/docs/src/pages/get-started.mdx | 34 ++++---- examples/docs/src/pages/themes/docs/bleed.mdx | 24 +++--- .../docs/src/pages/themes/docs/callout.mdx | 30 ++++--- examples/docs/src/pages/themes/docs/index.mdx | 41 +++++---- examples/docs/src/pages/themes/docs/tabs.mdx | 44 +++++----- examples/swr-site/next.config.js | 16 ++++ examples/swr-site/pages/_app.js | 6 +- .../swr-site/pages/docs/change-log.en-US.mdx | 21 +++++ packages/nextra-theme-blog/package.json | 31 +++---- packages/nextra-theme-blog/postcss.config.js | 6 +- packages/nextra-theme-blog/src/index.tsx | 50 ++++++++--- packages/nextra-theme-docs/package.json | 29 ++++--- packages/nextra-theme-docs/postcss.config.js | 6 +- packages/nextra-theme-docs/src/index.tsx | 67 ++++++++++----- packages/nextra-theme-docs/src/misc/theme.tsx | 86 +++++++++---------- .../__snapshots__/compile.test.ts.snap | 18 ++-- packages/nextra/__test__/compile.test.ts | 2 +- packages/nextra/src/compile.ts | 7 +- packages/nextra/src/constants.ts | 2 + packages/nextra/src/index.js | 53 ++++++++---- packages/nextra/src/loader.ts | 69 +++++++++++---- packages/nextra/src/ssg.ts | 23 +---- packages/nextra/src/types.ts | 1 + pnpm-lock.yaml | 59 +++++++++++++ turbo.json | 10 +-- 29 files changed, 507 insertions(+), 279 deletions(-) create mode 100644 .changeset/silent-phones-own.md delete mode 100644 examples/blog/pages/_app.js diff --git a/.changeset/silent-phones-own.md b/.changeset/silent-phones-own.md new file mode 100644 index 0000000000..da51cf5b64 --- /dev/null +++ b/.changeset/silent-phones-own.md @@ -0,0 +1,7 @@ +--- +'nextra': patch +'nextra-theme-blog': patch +'nextra-theme-docs': patch +--- + +feat: New layout implementation diff --git a/examples/blog/next.config.mjs b/examples/blog/next.config.mjs index 6c1f3b59a9..fcbcfbfbf6 100644 --- a/examples/blog/next.config.mjs +++ b/examples/blog/next.config.mjs @@ -7,5 +7,21 @@ const withNextra = nextra({ }) export default withNextra({ - reactStrictMode: true + reactStrictMode: true, + webpack(config) { + // To make pnpm workspace and themes work in this monorepo, we need to + // disable webpack's symlinks feature here. Otherwise the symlink + // `./node_modules/nextra-theme-docs/style.css` will be resolved as + // `../../packages/nextra-theme-docs/style.css`, which doesn't contain + // `node_modules` in its full path and webpack can't pick the correct loader + // for it due to: + // https://github.com/vercel/next.js/blob/213c42f446874d29d07fa2cca6e6b11fc9c3b711/packages/next/build/webpack/config/blocks/css/index.ts#L305 + // This is not needed for normal usage, only a workaround for this + // development repository. + config.resolve = { + ...config.resolve, + symlinks: false + } + return config + } }) diff --git a/examples/blog/pages/_app.js b/examples/blog/pages/_app.js deleted file mode 100644 index 7f0719e1ff..0000000000 --- a/examples/blog/pages/_app.js +++ /dev/null @@ -1,8 +0,0 @@ -import 'nextra-theme-blog/style.css' - -export default function MyApp({ Component, pageProps }) { - // Use the layout defined at the page level, if available - const getLayout = Component.getLayout || (page => page) - - return getLayout() -} diff --git a/examples/docs/next.config.js b/examples/docs/next.config.js index 635ef549ec..97c69e8276 100644 --- a/examples/docs/next.config.js +++ b/examples/docs/next.config.js @@ -8,5 +8,21 @@ const withNextra = require('nextra')({ }) module.exports = withNextra({ - reactStrictMode: true + reactStrictMode: true, + webpack(config) { + // To make pnpm workspace and themes work in this monorepo, we need to + // disable webpack's symlinks feature here. Otherwise the symlink + // `./node_modules/nextra-theme-docs/style.css` will be resolved as + // `../../packages/nextra-theme-docs/style.css`, which doesn't contain + // `node_modules` in its full path and webpack can't pick the correct loader + // for it due to: + // https://github.com/vercel/next.js/blob/213c42f446874d29d07fa2cca6e6b11fc9c3b711/packages/next/build/webpack/config/blocks/css/index.ts#L305 + // This is not needed for normal usage, only a workaround for this + // development repository. + config.resolve = { + ...config.resolve, + symlinks: false + } + return config + } }) diff --git a/examples/docs/src/pages/get-started.mdx b/examples/docs/src/pages/get-started.mdx index c791c9c30b..819b88aba3 100644 --- a/examples/docs/src/pages/get-started.mdx +++ b/examples/docs/src/pages/get-started.mdx @@ -15,43 +15,45 @@ Nextra works like a Next.js plugin, and it accepts a theme config (layout) to re 1. Install Next.js, Nextra and React - - +import { Tabs, Tab } from 'nextra-theme-docs/tabs' + + + ```bash npm i react react-dom next nextra ``` - - + + ```bash yarn add react react-dom next nextra ``` - - + + ```bash pnpm i react react-dom next nextra ``` - - + + 2. Install the docs theme - - + + ```bash npm i nextra-theme-docs ``` - - + + ```bash yarn add nextra-theme-docs ``` - - + + ```bash pnpm i nextra-theme-docs ``` - - + + 3. Create the following Next.js config and theme config under the root directory: diff --git a/examples/docs/src/pages/themes/docs/bleed.mdx b/examples/docs/src/pages/themes/docs/bleed.mdx index 57d80d5d50..e9c3967906 100644 --- a/examples/docs/src/pages/themes/docs/bleed.mdx +++ b/examples/docs/src/pages/themes/docs/bleed.mdx @@ -7,21 +7,23 @@ A built-in component provided by `nextra-theme-docs`. When wrapping your content with ``, it will be slightly wider than the container and will overflow on both sides. - +import Bleed from 'nextra-theme-docs/bleed' + +
_There is nothing to writing. All you do is sit down at a typewriter and **bleed**._ — Ernest Hemingway
-
+
It provides a better reading experience when you want to present some graphical information, which normally looks nicer in a larger size. For example you can put text, image, video or any component inside: - +