Hello VuePress

Static Site Generator には色々あるが、VuePress が気になったので試した。ブログ向けの機能はまだ足りていないが、 覚えることが少なくて日本語の公式ドキュメントが充実 している。

Getting Started

基本的には設定ファイルと Markdown ファイルを置くだけ。サブディレクトリにある.mdあるいは.htmlがルーティングされる。尚、README.mdindex.htmlに変換される。

yarn global add vuepress
echo '# Hello VuePress' > README.md
vuepress dev
vuepress build
1
2
3
4

docs フォルダ

既存プロジェクトにドキュメントとして追加する場合、フォルダを指定できる。

package.json



 
 



{
  "scripts": {
    "docs:dev": "vuepress dev docs",
    "docs:build": "vuepress build docs"
  }
}
1
2
3
4
5
6

ホームページ用のプロジェクトならindex.htmlのソースはREADME.mdよりindex.mdの方が直感的でわかりやすい。

echo '# Hello VuePress' > docs/index.md
yarn docs:dev
yarn docs:build
1
2
3

.gitignore

GitHub の Node 用テンプレートをベースにして以下を追加する。

.gitignore

# vuepressのビルド先
docs/.vuepress/dist

# VSCodeの設定
.vscode
1
2
3
4
5

VuePress の設定変更

アクセントカラー

docs/.vuepress/override.styl

$accentColor = #CC6666
1

言語・タイトル・説明

docs/.vuepress/config.js


 
 
 
 
 
 
 


module.exports = {
  locales: {
    '/': {
      lang: 'ja',
      title: '奈良のシカ',
      description: '鹿せんべいはおやつ、主食は芝です'
    }
  }
}
1
2
3
4
5
6
7
8
9

WARNING

html lang はデフォルトでen_USが設定される。

ナビゲーション・サイドバー

docs/.vuepress/config.js


 
 
 
 
 


module.exports = {
  themeConfig: {
    nav: [{ text: 'アーカイブ', link: '/archive' }],
    sidebarDepth: 2,
    sidebar: 'auto'
  }
}
1
2
3
4
5
6
7

Last Updated

docs/.vuepress/config.js



 



module.exports = {
  themeConfig: {
    lastUpdated: 'Last Updated'
  }
}
1
2
3
4
5

WARNING

git commit の日時を反映するので、git リポジトリが必要。

行番号・自動リンク

docs/.vuepress/config.js


 
 
 
 


module.exports = {
  markdown: {
    lineNumbers: true,
    linkify: true
  }
}
1
2
3
4
5
6

Prev / Next リンク

front matter に書く。

---
prev: ./some-other-page
next: false
---
1
2
3
4
Last Updated: 2018/6/26 21:52:27