|
| 1 | +# Configure your Site |
| 2 | + |
| 3 | +## Create config file |
| 4 | + |
| 5 | +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. |
| 6 | + |
| 7 | +For example, in the initial project created by previous guide, you can add the config file and the project structure will be like this: |
| 8 | + |
| 9 | +```bash |
| 10 | +. |
| 11 | +├─ docs |
| 12 | +│ ├─ .island |
| 13 | +│ │ └─ config.ts |
| 14 | +│ └─ index.md |
| 15 | +└─ package.json |
| 16 | +``` |
| 17 | + |
| 18 | +You can try to add the following config code in `config.ts`: |
| 19 | + |
| 20 | +```ts |
| 21 | +import { defineConfig } from 'islandjs'; |
| 22 | + |
| 23 | +export default defineConfig({ |
| 24 | + title: 'my-site' |
| 25 | +}); |
| 26 | +``` |
| 27 | + |
| 28 | +There are some tips for the config file: |
| 29 | + |
| 30 | +- 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. |
| 31 | + |
| 32 | +- 2. config file should has a default export, which is a `SiteConfig` object. |
| 33 | + |
| 34 | +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! |
| 35 | + |
| 36 | +In next section, we will introduce nav and sidebar config, which is very important for a doc site. |
| 37 | + |
| 38 | +## Nav config |
| 39 | + |
| 40 | +The nav config is used to config the navigation of the site, which has following structure: |
| 41 | + |
| 42 | +```ts |
| 43 | +import { defineConfig } from 'islandjs'; |
| 44 | + |
| 45 | +export default defineConfig({ |
| 46 | + themeConfig: { |
| 47 | + nav: [ |
| 48 | + { |
| 49 | + text: 'Home', |
| 50 | + link: '/', |
| 51 | + activeMatch: '^/$|^/' |
| 52 | + } |
| 53 | + ] |
| 54 | + } |
| 55 | +}); |
| 56 | +``` |
| 57 | + |
| 58 | +It should be noticed that the `nav` config is under `themeConfig`, and belongs to the default theme of Island.js. |
| 59 | + |
| 60 | +The `nav` config is an array of `NavItem`, which has following type: |
| 61 | + |
| 62 | +```ts |
| 63 | +interface NavItem { |
| 64 | + // The text of the nav item |
| 65 | + text: string; |
| 66 | + // The link href will be entered when click the nav item |
| 67 | + link: '/'; |
| 68 | + // The active match rule of the nav item |
| 69 | + activeMatch: '^/$|^/'; |
| 70 | +} |
| 71 | +``` |
| 72 | + |
| 73 | +The `activeMatch` is used to match the current route, and the nav item will be highlighted when the route matches the `activeMatch` rule. |
| 74 | + |
| 75 | +## Sidebar config |
| 76 | + |
| 77 | +The sidebar config is used to config the sidebar of the site, which has following structure: |
| 78 | + |
| 79 | +```ts |
| 80 | +import { defineConfig } from 'islandjs'; |
| 81 | + |
| 82 | +export default defineConfig({ |
| 83 | + themeConfig: { |
| 84 | + sidebar: [ |
| 85 | + { |
| 86 | + text: 'Guide', |
| 87 | + items: [ |
| 88 | + { |
| 89 | + text: 'Getting Started', |
| 90 | + link: '/guide/getting-started' |
| 91 | + } |
| 92 | + ] |
| 93 | + } |
| 94 | + ] |
| 95 | + } |
| 96 | +}); |
| 97 | +``` |
| 98 | + |
| 99 | +The `sidebar` config is also under `themeConfig`, and belongs to the default theme of Island.js. |
| 100 | + |
| 101 | +`sidebar` config has two form: `array` and `object`. |
| 102 | + |
| 103 | +The `array` config is a list of `SidebarGroup`, which has following type: |
| 104 | + |
| 105 | +```ts |
| 106 | +interface SidebarGroup { |
| 107 | + // The text of the sidebar group |
| 108 | + text: string; |
| 109 | + // The child items of the sidebar group |
| 110 | + items: SidebarItem[]; |
| 111 | + // Whether the sidebar group is collapsible |
| 112 | + collapsible?: boolean; |
| 113 | + // The initial state of the sidebar group, which is only valid when `collapsible` is true |
| 114 | + collapsed?: boolean; |
| 115 | +} |
| 116 | +``` |
| 117 | + |
| 118 | +The `object` config is a map for `SidebarGroup`, which has following type: |
| 119 | + |
| 120 | +```ts |
| 121 | +Record<string, SidebarGroup>; |
| 122 | +``` |
0 commit comments