Skip to content

Commit 40ca73c

Browse files
ulivzyyx990803
authored andcommittedApr 16, 2018
feat: support adding custom page class in front matter (#85)
ref #84
1 parent 54251ec commit 40ca73c

File tree

2 files changed

+30
-5
lines changed

2 files changed

+30
-5
lines changed
 

‎docs/default-theme-config/README.md

+18
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,24 @@ $borderColor = #eaecef
232232
$codeBgColor = #282c34
233233
```
234234

235+
## Custom Page Class
236+
237+
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`:
238+
239+
``` yaml
240+
---
241+
pageClass: custom-page-class
242+
---
243+
```
244+
245+
Then you can write CSS targeting that page only:
246+
247+
``` css
248+
.theme-container.custom-page-class {
249+
/* page-specific rules */
250+
}
251+
```
252+
235253
## Custom Layout for Specific Pages
236254

237255
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`:

‎lib/default-theme/Layout.vue

+12-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
<template>
22
<div class="theme-container"
3-
:class="{
4-
'no-navbar': !shouldShowNavbar,
5-
'sidebar-open': isSidebarOpen,
6-
'no-sidebar': !shouldShowSidebar
7-
}"
3+
:class="pageClasses"
84
@touchstart="onTouchStart"
95
@touchend="onTouchEnd">
106
<Navbar v-if="shouldShowNavbar" @toggle-sidebar="toggleSidebar"/>
@@ -63,6 +59,17 @@ export default {
6359
this.$route,
6460
this.$site
6561
)
62+
},
63+
pageClasses() {
64+
const userPageClass = this.$page.frontmatter.pageClass
65+
return [
66+
{
67+
'no-navbar': !this.shouldShowNavbar,
68+
'sidebar-open': this.isSidebarOpen,
69+
'no-sidebar': !this.shouldShowSidebar,
70+
},
71+
userPageClass
72+
]
6673
}
6774
},
6875

0 commit comments

Comments
 (0)
Please sign in to comment.