VuePress のテーマをカスタマイズする

簡単にデフォルトテーマをコピーしてカスタマイズできるようになっている。また、カスタムテーマとして npm パッケージを公開して使うこともできる。

デフォルトテーマをコピーする

vuepress eject {target_dir}
1

WARNING

docs/.vuepress/theme を使う場合、今後 VuePress をアップデートした際に新しいデフォルトテーマが適用されないため、各自で対応が必要となる。

スタイル上書きを移植する

例えば、アクセントカラーの変更を行っていた場合。

docs/.vuepress/override.styl

$accentColor = #CC6666
1

docs/.vuepress/config.styl


 





// colors
$accentColor = #CC6666
$textColor = #2c3e50
$borderColor = #eaecef
$codeBgColor = #282c34
$arrowBgColor = #ccc
1
2
3
4
5
6

カスタムテーマを変更する

トップページの画像にリンクをつける

ボタンが小さくて押しにくいので画像もリンクにする。

docs/.vuepress/theme/Home.vue




 

 























 












 
 
 
 






<template>
  <div class="home">
    <div class="hero">
      <a v-if="data.heroImage && data.actionLink" :href="link">
      <img v-if="data.heroImage" :src="$withBase(data.heroImage)" alt="hero">
      </a>
      <h1>{{ data.heroText || $title || 'Hello' }}</h1>
      <p class="description">
        {{ data.tagline || $description || 'Welcome to your VuePress site' }}
      </p>
      <p class="action" v-if="data.actionText && data.actionLink">
        <NavLink class="action-button" :item="actionLink"/>
      </p>
    </div>
    <div class="features" v-if="data.features && data.features.length">
      <div class="feature" v-for="feature in data.features">
        <h2>{{ feature.title }}</h2>
        <p>{{ feature.details }}</p>
      </div>
    </div>
    <Content custom/>
    <div class="footer" v-if="data.footer">
      {{ data.footer }}
    </div>
  </div>
</template>

<script>
import NavLink from './NavLink.vue'
import { ensureExt } from './util'

export default {
  components: { NavLink },
  computed: {
    data() {
      return this.$page.frontmatter
    },
    actionLink() {
      return {
        link: this.data.actionLink,
        text: this.data.actionText
      }
    },
    link() {
      return ensureExt(this.data.actionLink)
    }
  }
}
</script>

:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
Last Updated: 2018/6/26 21:52:27