提交 40ca73cf 编写于 作者: U ULIVZ 提交者: Evan You

feat: support adding custom page class in front matter (#85)

ref #84
上级 54251ec1
......@@ -232,6 +232,24 @@ $borderColor = #eaecef
$codeBgColor = #282c34
```
## Custom Page Class
Sometimes, you may need to add a unique class for a specific page so that you can target content on that page only in custom CSS. You can add a class to the theme container div with `pageClass` in `YAML front matter`:
``` yaml
---
pageClass: custom-page-class
---
```
Then you can write CSS targeting that page only:
``` css
.theme-container.custom-page-class {
/* page-specific rules */
}
```
## Custom Layout for Specific Pages
By default the content of each `*.md` file is rendered in a `<div class="page">` container, along with the sidebar, auto-generated edit links and prev/next links. If you wish to use a completely custom component in place of the page (while only keeping the navbar), you can again specify the component to use using `YAML front matter`:
......
<template>
<div class="theme-container"
:class="{
'no-navbar': !shouldShowNavbar,
'sidebar-open': isSidebarOpen,
'no-sidebar': !shouldShowSidebar
}"
:class="pageClasses"
@touchstart="onTouchStart"
@touchend="onTouchEnd">
<Navbar v-if="shouldShowNavbar" @toggle-sidebar="toggleSidebar"/>
......@@ -63,6 +59,17 @@ export default {
this.$route,
this.$site
)
},
pageClasses() {
const userPageClass = this.$page.frontmatter.pageClass
return [
{
'no-navbar': !this.shouldShowNavbar,
'sidebar-open': this.isSidebarOpen,
'no-sidebar': !this.shouldShowSidebar,
},
userPageClass
]
}
},
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册