Rspress provides several ways for you to customize the content of your pages, including:
In some scenarios, you may need to add some custom global components to the page. The framework provides a config item globalUIComponents
to achieve this function.
Add the following config in rspress.config.ts
:
Each item of globalUIComponents
can be a string, representing the file path of the component; or it can be an array, the first item is the file path of the component, and the second item is the props object of the component, such as:
When you register global components, the framework will automatically render these React components in the theme without manually importing and using them.
Through global components, you can complete many custom functions, such as:
In this way, the content of the component will be rendered in the theme page, such as adding BackToTop button.
In the meanwhile, you can also use the global component to register some side effects, such as:
This way, side effects of components are executed in the theme page. For example, some of the following scenarios require side effects:
In some scenarios, you may need to add some global styles on top of the theme UI. The framework provides a configuration item globalStyles
to achieve this function.
Add the following configuration in rspress.config.ts
:
Then you can add the following code:
In this way, the framework will automatically collect all global styles and merge them into the final style file.
Here are some commonly used global styles:
If you want to know more about the internal global styles, you can check vars.css
In order to get Tailwind CSS working with Rspress, you can use the following steps:
postcss.config.js
file containing tailwindcss
plugin:tailwind.config.js
file and make sure all the content files are included via content
:For most up to date configuration, please refer to the official Tailwind CSS documentation.
Rspress provides a pageType configuration for you to customize the layout structure of the page.
Rspress's convention-based routing supports two types of routes, one is document routing, that is, pages written with md(x) files, and the other is component routing, that is, pages written with .jsx/.tsx
files.
For the former, you can add the pageType
field in the frontmatter to specify the layout structure of the page, such as:
For the latter, you can add the following export to specify pageType
:
pageType can be configured as the following values:
home
: Home page, including the layout content of the top navigation bar and home page.doc
: Doc page, including top navigation bar, left sidebar, body content, and outline bar on the right.custom
: Custom page, including top navigation bar and custom content.blank
: Also belongs to custom page, but does not include Top Navigation Bar
.404
: Not found page.In addition to the pageType
page layout level configuration, Rspress also provides more fine-grained switches. You can configure other fields in the frontmatter. These fields and their meanings are as follows:
navbar
: Whether to display the top navigation bar. When you want to hide the top navigation bar, you can set it to false
.sidebar
: Whether to display the sidebar. When you want to hide the sidebar, you can set it to false
.outline
: Whether to display the outline column. When you want to hide the outline column, you can set it to false
.footer
: Whether to display the footer. When you want to hide the footer, you can set it to false
.Example:
In addition, you can use URL parameters to control the layout structure of the page at runtime, such as:
With URL parameters, you can quickly adjust the layout structure of the page without modifying the source code. These parameters specifically include:
navbar
: Whether to display the navigation bar. When you want to hide the top navigation bar, you can set it to 0
.sidebar
: Whether to display the sidebar. When you want to hide the sidebar, you can set it to 0
.outline
: Whether to display the outline column. When you want to hide the outline column, you can set it to 0
.footer
: Whether to display the footer. When you want to hide the footer, you can set it to 0
.globalUIComponents
: Whether to display the global components. When you want to hide the global components, you can set it to 0
.In rspress.config.ts
, you can custom HTML's metadata (aka head tag) for all pages. We explain it with more details in basic config - head within the api section.
Within frontmatter, you can also customize your page's metadata tag for SEO optimization.
For example, if you want to add <meta name="description" content="This is description">
in your <head>
tag, you can use frontmatter like so:
Read more details on how to customize open graph images (og:image) and open graph title (og:title) can be seen here in frontmatter config.