Hexo已經看膩了,來試試VuePress搭建我的博客

VuePress

先簡單介紹一下VuePress,這是尤大在2018年4月份發佈的一個新輪子。html

一個基於 Vue SSR 的靜態站生成器,原本的目的是爽爽的寫文檔,可是我發現用來擼一我的博客也很是不錯。vue

這是VuePress的官方文檔 這是VuePress的中文文檔webpack

上手搭建

你能夠跟着文檔上的例子本身玩一玩,不過因爲VuePress的文檔也是用VuePress來實現的,因此我取巧直接拿VuePress倉庫中的docs目錄拿來玩耍。git

  1. 首先安裝VuePress到全局
npm install -g vuepress
複製代碼
  1. 而後把VuePress倉庫克隆到你的電腦
git clone git@github.com:docschina/vuepress.git
複製代碼
  1. 在docs文件中執行(請確保你的 Node.js 版本 >= 8)
cd vuepress
cd docs
vuepress dev
複製代碼

當你看到這一行就說明已經成功了:github

VuePress dev server listening at http://localhost:8080/
複製代碼

下面咱們打開http://localhost:8080/ 發現真的打開了vuepress文檔: web

下面的工做就是數據的替換了,但咱們應該先看一下docs的目錄結構:npm

├─.vuepress
│  ├─components
│  └─public
│      └─icons
│   └─config.js // 配置文件
├─config // Vuepress文檔的配置參考內容
├─default-theme-config // Vuepress文檔的默認主題配置內容
├─guide // Vuepress文檔的指南內容
└─zh // 中文文檔目錄
    ├─config
    ├─default-theme-config
    └─guide
└─README.md // 首頁配置文件
複製代碼

文檔分紅了兩部分,中文文檔在/zh/目錄下,英文文檔在根目錄下。bash

其實目錄裏面的東西都挺好看懂的,首先guide 、default-theme-config、config 這三個目錄中的都是Vuepress文檔的主要內容,從中文文檔裏也能夠看到只有這三個目錄被替換了。markdown

首頁配置

默認主題提供了一個主頁佈局,要使用它,須要在你的根目錄 README.md 的 YAML front matter 中指定 home:true,並加上一些其餘的元數據。ide

咱們先看看根目錄下的README,md:

home: true // 是否使用Vuepress默認主題
heroImage: /hero.png // 首頁的圖片
actionText: Get Started →  // 按鈕的文字
actionLink: /guide/ // 按鈕跳轉的目錄
features: // 首頁三個特性
- title: Simplicity First
  details: Minimal setup with markdown-centered project structure helps you focus on writing.
- title: Vue-Powered
  details: Enjoy the dev experience of Vue + webpack, use Vue components in markdown, and develop custom themes with Vue.
- title: Performant
  details: VuePress generates pre-rendered static HTML for each page, and runs as an SPA once a page is loaded.
footer: MIT Licensed | Copyright © 2018-present Evan You // 頁尾
複製代碼

實在看不懂,官網有比我更詳細的配置說明。

導航配置

導航配置文件在.vuepress/config.js

在導航配置文件中nav是控制導航欄連接的,你能夠把它改爲本身的博客目錄。

nav: [
    {
        text: 'Guide',
        link: '/guide/',
    },
    {
        text: 'Config Reference',
        link: '/config/'
    },
    {
        text: 'Default Theme Config',
        link: '/default-theme-config/'
    }
]
複製代碼

剩下的默認主題配置官方文檔都有很詳細的文檔說明這裏就不在囉嗦了。

更改默認主題色

你能夠在.vuepress/目錄下建立一個override.styl文件。 vuepress提供四個可更改的顏色:

$accentColor = #3eaf7c // 主題色
$textColor = #2c3e50 // 文字顏色
$borderColor = #eaecef // 邊框顏色
$codeBgColor = #282c34 // 代碼背景顏色
複製代碼

我把它改爲了這樣:

側邊欄的實現

因爲評論區裏問的人較多,因此在這裏更新一下,其實我就算在這裏寫的再詳細也不如你們去看官方文檔。 側邊欄的配置也在.vuepress/config.js中:

sidebar: [
  {
    title: 'JavaScript', // 側邊欄名稱
    collapsable: true, // 可摺疊
    children: [
      '/blog/JavaScript/學會了ES6,就不會寫出那樣的代碼', // 你的md文件地址
    ]
  },
  {
    title: 'CSS', 
    collapsable: true,
    children: [
      '/blog/CSS/搞懂Z-index的全部細節',
    ]
  },
  {
    title: 'HTTP',
    collapsable: true,
    children: [
      '/blog/HTTP/認識HTTP-Cookie和Session篇',
    ]
  },
]
複製代碼

對應的文檔結構:

├─blog // docs目錄下新建一個博客目錄
│  ├─CSS
│  ├─HTTP
│  └─JavaScript
複製代碼

個人博客:brownhu

部署

在配置好你博客以後,命令行執行:

Vuepress build
複製代碼

當你看到這一行就說明成功了:

Success! Generated static files in vuepress.
複製代碼

將打包好的vuepress目錄上傳到你的github倉庫,和github page配合,就能夠配置好你的博客網站了。

相關文章
相關標籤/搜索