diff --git a/.github/contributing.md b/.github/contributing.md index 19b86097..ce0753c7 100644 --- a/.github/contributing.md +++ b/.github/contributing.md @@ -42,7 +42,7 @@ $ pnpm run dev And then you can execute: ```sh -$ pnpm run docs:dev +$ pnpm run dev:docs ``` Visit http://localhost:5173 and try modifying the source code. You'll get live update. diff --git a/docs/.island/config.ts b/docs/.island/config.ts index 72259b2a..e3116b79 100644 --- a/docs/.island/config.ts +++ b/docs/.island/config.ts @@ -2,6 +2,7 @@ import { defineConfig } from '../../dist'; export default defineConfig({ lang: 'en-US', + title: '666', icon: '/icon.png', themeConfig: { socialLinks: [ @@ -29,13 +30,18 @@ export default defineConfig({ function getTutorialSidebar() { return [ { - text: 'Guide', - items: [{ text: 'Getting Started', link: '/guide/getting-started' }] + text: 'Introduction', + items: [ + { text: 'Getting Started', link: '/guide/getting-started' }, + { text: 'Configure Your Site', link: '/guide/configure-site' } + ] + }, + { + text: 'Concepts', + items: [ + { text: 'SPA vs MPA', link: '/guide/spa-vs-mpa' }, + { text: 'Islands Architecture', link: '/guide/islands-arch' } + ] } - - // { - // text: 'Advance', - // items: [] - // } ]; } diff --git a/docs/guide/configure-site.md b/docs/guide/configure-site.md new file mode 100644 index 00000000..e6640bc5 --- /dev/null +++ b/docs/guide/configure-site.md @@ -0,0 +1,122 @@ +# Configure your Site + +## Create config file + +Without any configuration, the page is pretty minimal, which has no navigation and no sidebar.However, you can configure the site by `.island/config.ts` file and custom your own site. + +For example, in the initial project created by previous guide, you can add the config file and the project structure will be like this: + +```bash +. +├─ docs +│ ├─ .island +│ │ └─ config.ts +│ └─ index.md +└─ package.json +``` + +You can try to add the following config code in `config.ts`: + +```ts +import { defineConfig } from 'islandjs'; + +export default defineConfig({ + title: 'my-site' +}); +``` + +There are some tips for the config file: + +- 1. Island.js support `.js`、`.ts`、`.mjs`、`.cjs` file as config file.However, it is recommended to use TypeScript config because you can use `defineConfig` to get type hint. + +- 2. config file should has a default export, which is a `SiteConfig` object. + +In above example, we set the `title` of the site to `my-site`, then you can run start the dev server by `yarn dev:docs`.You will see the title of the site has been changed to `my-site`.This means you have awake your first site config, wonderful! + +In next section, we will introduce nav and sidebar config, which is very important for a doc site. + +## Nav config + +The nav config is used to config the navigation of the site, which has following structure: + +```ts +import { defineConfig } from 'islandjs'; + +export default defineConfig({ + themeConfig: { + nav: [ + { + text: 'Home', + link: '/', + activeMatch: '^/$|^/' + } + ] + } +}); +``` + +It should be noticed that the `nav` config is under `themeConfig`, and belongs to the default theme of Island.js. + +The `nav` config is an array of `NavItem`, which has following type: + +```ts +interface NavItem { + // The text of the nav item + text: string; + // The link href will be entered when click the nav item + link: '/'; + // The active match rule of the nav item + activeMatch: '^/$|^/'; +} +``` + +The `activeMatch` is used to match the current route, and the nav item will be highlighted when the route matches the `activeMatch` rule. + +## Sidebar config + +The sidebar config is used to config the sidebar of the site, which has following structure: + +```ts +import { defineConfig } from 'islandjs'; + +export default defineConfig({ + themeConfig: { + sidebar: [ + { + text: 'Guide', + items: [ + { + text: 'Getting Started', + link: '/guide/getting-started' + } + ] + } + ] + } +}); +``` + +The `sidebar` config is also under `themeConfig`, and belongs to the default theme of Island.js. + +`sidebar` config has two form: `array` and `object`. + +The `array` config is a list of `SidebarGroup`, which has following type: + +```ts +interface SidebarGroup { + // The text of the sidebar group + text: string; + // The child items of the sidebar group + items: SidebarItem[]; + // Whether the sidebar group is collapsible + collapsible?: boolean; + // The initial state of the sidebar group, which is only valid when `collapsible` is true + collapsed?: boolean; +} +``` + +The `object` config is a map for `SidebarGroup`, which has following type: + +```ts +Record; +``` diff --git a/docs/guide/getting-started.md b/docs/guide/getting-started.md index b6e212d0..170fb675 100644 --- a/docs/guide/getting-started.md +++ b/docs/guide/getting-started.md @@ -2,15 +2,15 @@ ## Why Island.js? -🏝️ Island.js is a static site generator that builds on top of Vite and Mdx. It is designed to be simple, powerful, and performant. It is built to help you focus on writing and deployed with minimum configuration.It has the following features: +🏝️ Island.js is a static site generator that builds on top of Vite, React and Mdx. It is designed to be simple, powerful, and performant. It is built to help you focus on writing and deployed with minimum configuration.It has the following features: - **Fast**: Island is built on top of Vite, which is a modern build tool that aims to provide a faster and leaner development experience. - **Flexible**: It has internal Mdx language support, which is a powerful way to write content. You can write, import and use React components in Markdown file. - **Performant**: It is designed to be [island architecture](https://jasonformat.com/islands-architecture/), which means less javascript bundle, partial hydration and better performance about FCP, TTI. -## Quick Start +Next we will walk you through the steps to create a new Island.js doc site. -### 1. Init project +## 1. Init project First, you can use create a new directory by following command: @@ -48,7 +48,7 @@ And then you can add the following scripts in `package.json`: } ``` -### 2. Start dev server +## 2. Start dev server Serve the documentation site in the local server. @@ -58,7 +58,7 @@ yarn dev Island will start a development server at http://localhost:5173. -### 3. Build for production +## 3. Build for production Build the documentation site for production. @@ -68,7 +68,7 @@ yarn build Island will generate a static site in the `.island/dist` directory. -### 4. Preview locally +## 4. Preview locally Preview the production build locally. diff --git a/docs/guide/islands-arch.md b/docs/guide/islands-arch.md new file mode 100644 index 00000000..ce077083 --- /dev/null +++ b/docs/guide/islands-arch.md @@ -0,0 +1,3 @@ +# Islands architecture + +TODO diff --git a/docs/guide/spa-vs-mpa.md b/docs/guide/spa-vs-mpa.md new file mode 100644 index 00000000..18c00a62 --- /dev/null +++ b/docs/guide/spa-vs-mpa.md @@ -0,0 +1,3 @@ +# SPA vs MPA + +TODO diff --git a/docs/guide/what-is-island-js.md b/docs/guide/what-is-island-js.md new file mode 100644 index 00000000..e69de29b diff --git a/package.json b/package.json index b54ba7a7..ef40b83a 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ "unified": "^10.1.2", "unist-util-visit": "^4.1.1", "unist-util-visit-children": "^2.0.0", - "vite": "3.1", + "vite": "3.0", "vite-plugin-inspect": "^0.7.1" }, "devDependencies": { diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 7c039c36..d1e939f2 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -78,7 +78,7 @@ specifiers: unified: ^10.1.2 unist-util-visit: ^4.1.1 unist-util-visit-children: ^2.0.0 - vite: '3.1' + vite: '3.0' vite-plugin-inspect: ^0.7.1 vitest: ^0.23.1 @@ -90,7 +90,7 @@ dependencies: '@mdx-js/react': 2.1.3_react@18.2.0 '@mdx-js/rollup': 2.1.3_rollup@2.78.1 '@svgr/core': registry.npmmirror.com/@svgr/core/6.3.1 - '@vitejs/plugin-react': registry.npmmirror.com/@vitejs/plugin-react/2.0.1_vite@3.1.2 + '@vitejs/plugin-react': registry.npmmirror.com/@vitejs/plugin-react/2.0.1_vite@3.0.9 acorn: 8.8.0 cac: registry.npmmirror.com/cac/6.7.12 compression: 1.7.4 @@ -124,8 +124,8 @@ dependencies: unified: 10.1.2 unist-util-visit: 4.1.1 unist-util-visit-children: 2.0.0 - vite: 3.1.2_sass@1.54.5 - vite-plugin-inspect: 0.7.1_vite@3.1.2 + vite: 3.0.9_sass@1.54.5 + vite-plugin-inspect: 0.7.1_vite@3.0.9 devDependencies: '@babel/traverse': 7.19.0 @@ -648,6 +648,15 @@ packages: get-tsconfig: 4.2.0 dev: true + /@esbuild/linux-loong64/0.14.54: + resolution: {integrity: sha512-bZBrLAIX1kpWelV0XemxBZllyRmM6vgFQQG2GdNb+r3Fkp0FOh1NJSvekXDs7jq70k4euu1cryLMfU+mTXlEpw==} + engines: {node: '>=12'} + cpu: [loong64] + os: [linux] + requiresBuild: true + dev: false + optional: true + /@esbuild/linux-loong64/0.15.5: resolution: {integrity: sha512-UHkDFCfSGTuXq08oQltXxSZmH1TXyWsL+4QhZDWvvLl6mEJQqk3u7/wq1LjhrrAXYIllaTtRSzUXl4Olkf2J8A==} engines: {node: '>=12'} @@ -662,6 +671,7 @@ packages: cpu: [loong64] os: [linux] requiresBuild: true + dev: true optional: true /@eslint/eslintrc/1.3.1: @@ -2604,6 +2614,15 @@ packages: is-symbol: 1.0.4 dev: true + /esbuild-android-64/0.14.54: + resolution: {integrity: sha512-Tz2++Aqqz0rJ7kYBfz+iqyE3QMycD4vk7LBRyWaAVFgFtQ/O8EJOnVmTOiDWYZ/uYzB4kvP+bqejYdVKzE5lAQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [android] + requiresBuild: true + dev: false + optional: true + /esbuild-android-64/0.15.5: resolution: {integrity: sha512-dYPPkiGNskvZqmIK29OPxolyY3tp+c47+Fsc2WYSOVjEPWNCHNyqhtFqQadcXMJDQt8eN0NMDukbyQgFcHquXg==} engines: {node: '>=12'} @@ -2618,6 +2637,16 @@ packages: cpu: [x64] os: [android] requiresBuild: true + dev: true + optional: true + + /esbuild-android-arm64/0.14.54: + resolution: {integrity: sha512-F9E+/QDi9sSkLaClO8SOV6etqPd+5DgJje1F9lOWoNncDdOBL2YF59IhsWATSt0TLZbYCf3pNlTHvVV5VfHdvg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [android] + requiresBuild: true + dev: false optional: true /esbuild-android-arm64/0.15.5: @@ -2634,6 +2663,16 @@ packages: cpu: [arm64] os: [android] requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-64/0.14.54: + resolution: {integrity: sha512-jtdKWV3nBviOd5v4hOpkVmpxsBy90CGzebpbO9beiqUYVMBtSc0AL9zGftFuBon7PNDcdvNCEuQqw2x0wP9yug==} + engines: {node: '>=12'} + cpu: [x64] + os: [darwin] + requiresBuild: true + dev: false optional: true /esbuild-darwin-64/0.15.5: @@ -2650,6 +2689,16 @@ packages: cpu: [x64] os: [darwin] requiresBuild: true + dev: true + optional: true + + /esbuild-darwin-arm64/0.14.54: + resolution: {integrity: sha512-OPafJHD2oUPyvJMrsCvDGkRrVCar5aVyHfWGQzY1dWnzErjrDuSETxwA2HSsyg2jORLY8yBfzc1MIpUkXlctmw==} + engines: {node: '>=12'} + cpu: [arm64] + os: [darwin] + requiresBuild: true + dev: false optional: true /esbuild-darwin-arm64/0.15.5: @@ -2666,6 +2715,16 @@ packages: cpu: [arm64] os: [darwin] requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-64/0.14.54: + resolution: {integrity: sha512-OKwd4gmwHqOTp4mOGZKe/XUlbDJ4Q9TjX0hMPIDBUWWu/kwhBAudJdBoxnjNf9ocIB6GN6CPowYpR/hRCbSYAg==} + engines: {node: '>=12'} + cpu: [x64] + os: [freebsd] + requiresBuild: true + dev: false optional: true /esbuild-freebsd-64/0.15.5: @@ -2682,6 +2741,16 @@ packages: cpu: [x64] os: [freebsd] requiresBuild: true + dev: true + optional: true + + /esbuild-freebsd-arm64/0.14.54: + resolution: {integrity: sha512-sFwueGr7OvIFiQT6WeG0jRLjkjdqWWSrfbVwZp8iMP+8UHEHRBvlaxL6IuKNDwAozNUmbb8nIMXa7oAOARGs1Q==} + engines: {node: '>=12'} + cpu: [arm64] + os: [freebsd] + requiresBuild: true + dev: false optional: true /esbuild-freebsd-arm64/0.15.5: @@ -2698,6 +2767,16 @@ packages: cpu: [arm64] os: [freebsd] requiresBuild: true + dev: true + optional: true + + /esbuild-linux-32/0.14.54: + resolution: {integrity: sha512-1ZuY+JDI//WmklKlBgJnglpUL1owm2OX+8E1syCD6UAxcMM/XoWd76OHSjl/0MR0LisSAXDqgjT3uJqT67O3qw==} + engines: {node: '>=12'} + cpu: [ia32] + os: [linux] + requiresBuild: true + dev: false optional: true /esbuild-linux-32/0.15.5: @@ -2714,6 +2793,16 @@ packages: cpu: [ia32] os: [linux] requiresBuild: true + dev: true + optional: true + + /esbuild-linux-64/0.14.54: + resolution: {integrity: sha512-EgjAgH5HwTbtNsTqQOXWApBaPVdDn7XcK+/PtJwZLT1UmpLoznPd8c5CxqsH2dQK3j05YsB3L17T8vE7cp4cCg==} + engines: {node: '>=12'} + cpu: [x64] + os: [linux] + requiresBuild: true + dev: false optional: true /esbuild-linux-64/0.15.5: @@ -2730,6 +2819,16 @@ packages: cpu: [x64] os: [linux] requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm/0.14.54: + resolution: {integrity: sha512-qqz/SjemQhVMTnvcLGoLOdFpCYbz4v4fUo+TfsWG+1aOu70/80RV6bgNpR2JCrppV2moUQkww+6bWxXRL9YMGw==} + engines: {node: '>=12'} + cpu: [arm] + os: [linux] + requiresBuild: true + dev: false optional: true /esbuild-linux-arm/0.15.5: @@ -2746,6 +2845,16 @@ packages: cpu: [arm] os: [linux] requiresBuild: true + dev: true + optional: true + + /esbuild-linux-arm64/0.14.54: + resolution: {integrity: sha512-WL71L+0Rwv+Gv/HTmxTEmpv0UgmxYa5ftZILVi2QmZBgX3q7+tDeOQNqGtdXSdsL8TQi1vIaVFHUPDe0O0kdig==} + engines: {node: '>=12'} + cpu: [arm64] + os: [linux] + requiresBuild: true + dev: false optional: true /esbuild-linux-arm64/0.15.5: @@ -2762,6 +2871,16 @@ packages: cpu: [arm64] os: [linux] requiresBuild: true + dev: true + optional: true + + /esbuild-linux-mips64le/0.14.54: + resolution: {integrity: sha512-qTHGQB8D1etd0u1+sB6p0ikLKRVuCWhYQhAHRPkO+OF3I/iSlTKNNS0Lh2Oc0g0UFGguaFZZiPJdJey3AGpAlw==} + engines: {node: '>=12'} + cpu: [mips64el] + os: [linux] + requiresBuild: true + dev: false optional: true /esbuild-linux-mips64le/0.15.5: @@ -2778,6 +2897,16 @@ packages: cpu: [mips64el] os: [linux] requiresBuild: true + dev: true + optional: true + + /esbuild-linux-ppc64le/0.14.54: + resolution: {integrity: sha512-j3OMlzHiqwZBDPRCDFKcx595XVfOfOnv68Ax3U4UKZ3MTYQB5Yz3X1mn5GnodEVYzhtZgxEBidLWeIs8FDSfrQ==} + engines: {node: '>=12'} + cpu: [ppc64] + os: [linux] + requiresBuild: true + dev: false optional: true /esbuild-linux-ppc64le/0.15.5: @@ -2794,6 +2923,16 @@ packages: cpu: [ppc64] os: [linux] requiresBuild: true + dev: true + optional: true + + /esbuild-linux-riscv64/0.14.54: + resolution: {integrity: sha512-y7Vt7Wl9dkOGZjxQZnDAqqn+XOqFD7IMWiewY5SPlNlzMX39ocPQlOaoxvT4FllA5viyV26/QzHtvTjVNOxHZg==} + engines: {node: '>=12'} + cpu: [riscv64] + os: [linux] + requiresBuild: true + dev: false optional: true /esbuild-linux-riscv64/0.15.5: @@ -2810,6 +2949,16 @@ packages: cpu: [riscv64] os: [linux] requiresBuild: true + dev: true + optional: true + + /esbuild-linux-s390x/0.14.54: + resolution: {integrity: sha512-zaHpW9dziAsi7lRcyV4r8dhfG1qBidQWUXweUjnw+lliChJqQr+6XD71K41oEIC3Mx1KStovEmlzm+MkGZHnHA==} + engines: {node: '>=12'} + cpu: [s390x] + os: [linux] + requiresBuild: true + dev: false optional: true /esbuild-linux-s390x/0.15.5: @@ -2826,6 +2975,16 @@ packages: cpu: [s390x] os: [linux] requiresBuild: true + dev: true + optional: true + + /esbuild-netbsd-64/0.14.54: + resolution: {integrity: sha512-PR01lmIMnfJTgeU9VJTDY9ZerDWVFIUzAtJuDHwwceppW7cQWjBBqP48NdeRtoP04/AtO9a7w3viI+PIDr6d+w==} + engines: {node: '>=12'} + cpu: [x64] + os: [netbsd] + requiresBuild: true + dev: false optional: true /esbuild-netbsd-64/0.15.5: @@ -2842,6 +3001,16 @@ packages: cpu: [x64] os: [netbsd] requiresBuild: true + dev: true + optional: true + + /esbuild-openbsd-64/0.14.54: + resolution: {integrity: sha512-Qyk7ikT2o7Wu76UsvvDS5q0amJvmRzDyVlL0qf5VLsLchjCa1+IAvd8kTBgUxD7VBUUVgItLkk609ZHUc1oCaw==} + engines: {node: '>=12'} + cpu: [x64] + os: [openbsd] + requiresBuild: true + dev: false optional: true /esbuild-openbsd-64/0.15.5: @@ -2858,6 +3027,16 @@ packages: cpu: [x64] os: [openbsd] requiresBuild: true + dev: true + optional: true + + /esbuild-sunos-64/0.14.54: + resolution: {integrity: sha512-28GZ24KmMSeKi5ueWzMcco6EBHStL3B6ubM7M51RmPwXQGLe0teBGJocmWhgwccA1GeFXqxzILIxXpHbl9Q/Kw==} + engines: {node: '>=12'} + cpu: [x64] + os: [sunos] + requiresBuild: true + dev: false optional: true /esbuild-sunos-64/0.15.5: @@ -2874,6 +3053,16 @@ packages: cpu: [x64] os: [sunos] requiresBuild: true + dev: true + optional: true + + /esbuild-windows-32/0.14.54: + resolution: {integrity: sha512-T+rdZW19ql9MjS7pixmZYVObd9G7kcaZo+sETqNH4RCkuuYSuv9AGHUVnPoP9hhuE1WM1ZimHz1CIBHBboLU7w==} + engines: {node: '>=12'} + cpu: [ia32] + os: [win32] + requiresBuild: true + dev: false optional: true /esbuild-windows-32/0.15.5: @@ -2890,6 +3079,16 @@ packages: cpu: [ia32] os: [win32] requiresBuild: true + dev: true + optional: true + + /esbuild-windows-64/0.14.54: + resolution: {integrity: sha512-AoHTRBUuYwXtZhjXZbA1pGfTo8cJo3vZIcWGLiUcTNgHpJJMC1rVA44ZereBHMJtotyN71S8Qw0npiCIkW96cQ==} + engines: {node: '>=12'} + cpu: [x64] + os: [win32] + requiresBuild: true + dev: false optional: true /esbuild-windows-64/0.15.5: @@ -2906,6 +3105,16 @@ packages: cpu: [x64] os: [win32] requiresBuild: true + dev: true + optional: true + + /esbuild-windows-arm64/0.14.54: + resolution: {integrity: sha512-M0kuUvXhot1zOISQGXwWn6YtS+Y/1RT9WrVIOywZnJHo3jCDyewAc79aKNQWFCQm+xNHVTq9h8dZKvygoXQQRg==} + engines: {node: '>=12'} + cpu: [arm64] + os: [win32] + requiresBuild: true + dev: false optional: true /esbuild-windows-arm64/0.15.5: @@ -2922,8 +3131,38 @@ packages: cpu: [arm64] os: [win32] requiresBuild: true + dev: true optional: true + /esbuild/0.14.54: + resolution: {integrity: sha512-Cy9llcy8DvET5uznocPyqL3BFRrFXSVqbgpMJ9Wz8oVjZlh/zUSNbPRbov0VX7VxN2JH1Oa0uNxZ7eLRb62pJA==} + engines: {node: '>=12'} + hasBin: true + requiresBuild: true + optionalDependencies: + '@esbuild/linux-loong64': 0.14.54 + esbuild-android-64: 0.14.54 + esbuild-android-arm64: 0.14.54 + esbuild-darwin-64: 0.14.54 + esbuild-darwin-arm64: 0.14.54 + esbuild-freebsd-64: 0.14.54 + esbuild-freebsd-arm64: 0.14.54 + esbuild-linux-32: 0.14.54 + esbuild-linux-64: 0.14.54 + esbuild-linux-arm: 0.14.54 + esbuild-linux-arm64: 0.14.54 + esbuild-linux-mips64le: 0.14.54 + esbuild-linux-ppc64le: 0.14.54 + esbuild-linux-riscv64: 0.14.54 + esbuild-linux-s390x: 0.14.54 + esbuild-netbsd-64: 0.14.54 + esbuild-openbsd-64: 0.14.54 + esbuild-sunos-64: 0.14.54 + esbuild-windows-32: 0.14.54 + esbuild-windows-64: 0.14.54 + esbuild-windows-arm64: 0.14.54 + dev: false + /esbuild/0.15.5: resolution: {integrity: sha512-VSf6S1QVqvxfIsSKb3UKr3VhUCis7wgDbtF4Vd9z84UJr05/Sp2fRKmzC+CSPG/dNAPPJZ0BTBLTT1Fhd6N9Gg==} engines: {node: '>=12'} @@ -2980,6 +3219,7 @@ packages: esbuild-windows-32: 0.15.7 esbuild-windows-64: 0.15.7 esbuild-windows-arm64: 0.15.7 + dev: true /escalade/3.1.1: resolution: {integrity: sha512-k0er2gUkLf8O0zKJiAhmkTnJlTvINGv7ygDNPbeIsX/TJjGJZHuh9B2UxbsaEkmlEo9MfhrSzmhIlhRlI2GXnw==} @@ -6411,6 +6651,14 @@ packages: glob: 7.2.3 dev: true + /rollup/2.77.3: + resolution: {integrity: sha512-/qxNTG7FbmefJWoeeYJFbHehJ2HNWnjkAFRKzWN/45eNBBF/r8lo992CwcJXEzyVxs5FmfId+vTSTQDb+bxA+g==} + engines: {node: '>=10.0.0'} + hasBin: true + optionalDependencies: + fsevents: 2.3.2 + dev: false + /rollup/2.78.1: resolution: {integrity: sha512-VeeCgtGi4P+o9hIg+xz4qQpRl6R401LWEXBmxYKOV4zlF82lyhgh2hTZnheFUbANE8l2A41F458iwj2vEYaXJg==} engines: {node: '>=10.0.0'} @@ -7369,7 +7617,7 @@ packages: vfile-message: 3.1.2 dev: false - /vite-plugin-inspect/0.7.1_vite@3.1.2: + /vite-plugin-inspect/0.7.1_vite@3.0.9: resolution: {integrity: sha512-mkTw5itsI+89WNJ6og0BpEAaV4ticrOGaoj+oWDR61W72H2mfkuw3MaAdpnnq6s6A7tKfM4nPaMtxjlmw3uXYg==} engines: {node: '>=14'} peerDependencies: @@ -7381,11 +7629,39 @@ packages: kolorist: 1.6.0 sirv: 2.0.2 ufo: 0.8.5 - vite: 3.1.2_sass@1.54.5 + vite: 3.0.9_sass@1.54.5 transitivePeerDependencies: - supports-color dev: false + /vite/3.0.9_sass@1.54.5: + resolution: {integrity: sha512-waYABTM+G6DBTCpYAxvevpG50UOlZuynR0ckTK5PawNVt7ebX6X7wNXHaGIO6wYYFXSM7/WcuFuO2QzhBB6aMw==} + engines: {node: ^14.18.0 || >=16.0.0} + hasBin: true + peerDependencies: + less: '*' + sass: '*' + stylus: '*' + terser: ^5.4.0 + peerDependenciesMeta: + less: + optional: true + sass: + optional: true + stylus: + optional: true + terser: + optional: true + dependencies: + esbuild: 0.14.54 + postcss: 8.4.16 + resolve: 1.22.1 + rollup: 2.77.3 + sass: 1.54.5 + optionalDependencies: + fsevents: 2.3.2 + dev: false + /vite/3.1.2_sass@1.54.5: resolution: {integrity: sha512-wTDKPkiVbeT+drTPdkuvjVIC/2vKKUc1w3qNOuwgpyvPCZF6fvdxB5v5WEcCsqaYea0zrwA4+XialJKCHM3oVQ==} engines: {node: ^14.18.0 || >=16.0.0} @@ -7412,6 +7688,7 @@ packages: sass: 1.54.5 optionalDependencies: fsevents: 2.3.2 + dev: true /vitest/0.23.1_sass@1.54.5: resolution: {integrity: sha512-kn9pG+h6VA3yj/xRvwgLKEd33rOlzMqJEg3tl5HSm3WUPlkY1Lr1FK8RN1uIqVKvFxmz6HGU3EQW+xW2kazRkQ==} @@ -7998,7 +8275,7 @@ packages: version: 4.0.0 dev: false - registry.npmmirror.com/@vitejs/plugin-react/2.0.1_vite@3.1.2: + registry.npmmirror.com/@vitejs/plugin-react/2.0.1_vite@3.0.9: resolution: {integrity: sha512-uINzNHmjrbunlFtyVkST6lY1ewSfz/XwLufG0PIqvLGnpk2nOIOa/1CACTDNcKi1/RwaCzJLmsXwm1NsUVV/NA==, registry: https://registry.npm.taobao.org/, tarball: https://registry.npmmirror.com/@vitejs/plugin-react/-/plugin-react-2.0.1.tgz} id: registry.npmmirror.com/@vitejs/plugin-react/2.0.1 name: '@vitejs/plugin-react' @@ -8014,7 +8291,7 @@ packages: '@babel/plugin-transform-react-jsx-source': registry.npmmirror.com/@babel/plugin-transform-react-jsx-source/7.18.6_@babel+core@7.19.0 magic-string: registry.npmmirror.com/magic-string/0.26.2 react-refresh: registry.npmmirror.com/react-refresh/0.14.0 - vite: 3.1.2_sass@1.54.5 + vite: 3.0.9_sass@1.54.5 transitivePeerDependencies: - supports-color dev: false diff --git a/src/node/plugin-island/config.ts b/src/node/plugin-island/config.ts index 9854a24e..d9b3157f 100644 --- a/src/node/plugin-island/config.ts +++ b/src/node/plugin-island/config.ts @@ -16,7 +16,10 @@ import pc from 'picocolors'; const { green } = pc; -export function pluginConfig(config: SiteConfig): Plugin { +export function pluginConfig( + config: SiteConfig, + restartServer?: () => Promise +): Plugin { return { name: 'island:vite-config', enforce: 'pre', @@ -90,6 +93,8 @@ export function pluginConfig(config: SiteConfig): Plugin { `\n${relative(config.root, ctx.file)} changed, restarting server...` ) ); + // `restartServer` always exist in current plugin hook + await restartServer!(); return []; } } diff --git a/src/node/plugin-island/index.ts b/src/node/plugin-island/index.ts index c49b1b5c..6ec6f3f4 100644 --- a/src/node/plugin-island/index.ts +++ b/src/node/plugin-island/index.ts @@ -12,7 +12,7 @@ export function pluginIsland( ): Plugin[] { return [ pluginSiteData(config), - pluginConfig(config), + pluginConfig(config, restartServer), pluginIndexHtml(config), pluginIslandTransform(config, isServer) ]; diff --git a/src/node/plugin.ts b/src/node/plugin.ts index ce392eeb..b851a040 100644 --- a/src/node/plugin.ts +++ b/src/node/plugin.ts @@ -15,7 +15,7 @@ export async function createIslandPlugins( restartServer?: () => Promise ): Promise { return [ - pluginInspect({}), + // pluginInspect({}), // For island internal use pluginIsland(config, isServer, restartServer), diff --git a/src/runtime/app.tsx b/src/runtime/app.tsx index 116b2fc1..b334e91f 100644 --- a/src/runtime/app.tsx +++ b/src/runtime/app.tsx @@ -3,7 +3,7 @@ import { routes } from 'virtual:routes'; import { matchRoutes, useLocation } from 'react-router-dom'; import siteData from 'island:site-data'; import { Route } from '../node/plugin-routes'; -import { omit } from './utils'; +import { cleanUrl, omit } from './utils'; import { PageData } from '../shared/types'; import { HelmetProvider } from 'react-helmet-async'; import { useContext, useLayoutEffect } from 'react'; @@ -14,9 +14,10 @@ export async function waitForApp(path: string): Promise { if (matched) { // Preload route component const mod = await (matched[0].route as Route).preload(); + const pagePath = cleanUrl((matched[0].route as Route).filePath); return { siteData, - pagePath: (matched[0].route as Route).filePath, + pagePath, ...omit(mod, ['default']) } as PageData; } else { diff --git a/src/runtime/utils.ts b/src/runtime/utils.ts index cfb35679..f90a33cb 100644 --- a/src/runtime/utils.ts +++ b/src/runtime/utils.ts @@ -7,3 +7,9 @@ export const omit = (obj: Record, keys: string[]) => { } return ret; }; + +export const queryRE = /\?.*$/s; +export const hashRE = /#.*$/s; + +export const cleanUrl = (url: string): string => + url.replace(hashRE, '').replace(queryRE, ''); diff --git a/src/theme-default/components/Aside/index.tsx b/src/theme-default/components/Aside/index.tsx index 13990075..6e9a625d 100644 --- a/src/theme-default/components/Aside/index.tsx +++ b/src/theme-default/components/Aside/index.tsx @@ -22,11 +22,11 @@ export function Aside( // Then we listen the event and pull the latest page module so we can get and render the new headers. if (import.meta.env.DEV) { import.meta.hot?.on('md(x)-changed', () => { - import( - /* @vite-ignore */ `${props.pagePath}?import&t=${Date.now()}` - ).then((mod) => { - setHeaders(mod.toc); - }); + import(/* @vite-ignore */ `${props.pagePath}?t=${Date.now()}`).then( + (mod) => { + setHeaders(mod.toc); + } + ); }); } }, [props.pagePath]); diff --git a/src/theme-default/components/Siderbar/index.tsx b/src/theme-default/components/Siderbar/index.tsx index 6c4b5994..d8a1b4e5 100644 --- a/src/theme-default/components/Siderbar/index.tsx +++ b/src/theme-default/components/Siderbar/index.tsx @@ -24,7 +24,7 @@ export function SideBar() { if ('items' in item) { children = item.items.map((child) => renderGroupItem(child, depth + 1)); } - const isActive = item.text.includes('CLI'); + const isActive = location.pathname.startsWith(normalizeHref(item.link)); return (
diff --git a/tsup.config.ts b/tsup.config.ts index f4904d5e..fa94ad24 100644 --- a/tsup.config.ts +++ b/tsup.config.ts @@ -15,7 +15,6 @@ export default defineConfig([ sourcemap: true, splitting: false, keepNames: true, - clean: true, minify: process.env.NODE_ENV === 'production', skipNodeModulesBundle: true }, @@ -24,7 +23,6 @@ export default defineConfig([ lazyWithPreload: 'src/runtime/lazyWithPreload.tsx' }, format: 'esm', - clean: true, dts: false, minify: false }