|
| 1 | +# Adding, Moving, or Renaming Docs |
| 2 | + |
| 3 | +Docusaurus generates sidebars based on a JSON file named `sidebars.js`. When you add a new doc, you need to add an entry to `sidebars.js`. Otherwise, the page won't appear in the list of sidebar topics. When you move or re-title a doc, you need to update `sidebars.js` to reflect the change to the doc's location or title. If you alter a docs file's path, by moving the file or editing the file's name, you'll also need to add a redirect to the new path in `docusaurus.config.js`. |
| 4 | + |
| 5 | +> **Note:** Avoid adding filenames that contain periods before the file extension (example: `rke2-self-assessment-guide-with-cis-v1.23-k8s-v1.25.md`). If necessary, use dashes instead of periods (`rke2-self-assessment-guide-with-cis-v1-23-k8s-v1-25.md`). |
| 6 | +
|
| 7 | +## Sidebars |
| 8 | + |
| 9 | +The `sidebars.js` file for the latest version of Rancher is located in the top level of the repo. Versioned docs each have their own versioned sidebar, found within `/versioned_sidebars` in the top level of the repo. |
| 10 | + |
| 11 | +The schema for `sidebars.js` looks like this: |
| 12 | + |
| 13 | +```JS |
| 14 | +sidebar: [ |
| 15 | + "toplevel", |
| 16 | + { |
| 17 | + type: "category", |
| 18 | + label: "Second Level", |
| 19 | + items: [ |
| 20 | + "second-level/overview", |
| 21 | + { |
| 22 | + type: "category", |
| 23 | + label: "Topic One", |
| 24 | + link: { |
| 25 | + type: "doc", |
| 26 | + id: "pages-for-subheaders/index-page-for-topic-one" |
| 27 | + } |
| 28 | + items: [ |
| 29 | + "second-level/topic-one/page-a", |
| 30 | + "second-level/topic-one/page-b", |
| 31 | + ] |
| 32 | + } |
| 33 | + ] |
| 34 | + } |
| 35 | +] |
| 36 | +``` |
| 37 | + |
| 38 | +Paths for docs files are listed within an `items` array. Their position within the file is similar to how they'll be organized within the published sidebar. |
| 39 | + |
| 40 | +If the doc is as an index page for a topic with numerous subtopic pages, its entry in `sidebars.js` should have extra metadata, such as `category`, `link`, and `label`. |
| 41 | + |
| 42 | +### Moving Index Pages |
| 43 | + |
| 44 | +Some entries in the published sidebar are clickable dropdown menus. When a reader clicks them, they reveal a list of subtopics. These dropdown menu entries are indicated by `type: category` in the sidebar file. When you select the entry on the published docs site, the menu opens and you will navigate to the page indicated in `link.id`. |
| 45 | + |
| 46 | +Docusaurus uses the `label` field to generate the text that appears on the dropdown menu in the sidebar. When you rename these index pages, you also need to update their `label` in the sidebar file. |
| 47 | + |
| 48 | +### Redirecting Pages |
| 49 | + |
| 50 | +When you move a page, update redirects in the `@docusaurus/plugin-client-redirects` field within the `docusaurus.config.js` file. This file is located in the top level of the repo. |
| 51 | + |
| 52 | +The schema for docs redirects looks like this: |
| 53 | + |
| 54 | +```JS |
| 55 | + { |
| 56 | + to: '/faq/general-faq', |
| 57 | + from: '/faq' |
| 58 | + } |
| 59 | + { |
| 60 | + to: '/v2.6/faq/general-faq', |
| 61 | + from: '/v2.6/faq' |
| 62 | + }, |
| 63 | +``` |
| 64 | + |
| 65 | +Docusaurus redirects don't accept wildcards, so each path must be exact. This means that you must add individual redirects for each version of a doc. |
| 66 | + |
| 67 | +Docusaurus also can't redirect pages whose filenames contain a period before the extension. You'll need to manually update any docset links to those pages. |
0 commit comments