Skip to content

Commit

Permalink
feat: support adding custom page class in front matter (#85)
Browse files Browse the repository at this point in the history
ref #84
  • Loading branch information
ulivz authored and yyx990803 committed Apr 16, 2018
1 parent 54251ec commit 40ca73c
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 5 deletions.
18 changes: 18 additions & 0 deletions docs/default-theme-config/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`:
Expand Down
17 changes: 12 additions & 5 deletions lib/default-theme/Layout.vue
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
<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"/>
Expand Down Expand Up @@ -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
]
}
},
Expand Down

0 comments on commit 40ca73c

Please sign in to comment.