之前博客是在Windows上搭建的,后來(lái)Windows 10內(nèi)置了linux子系統(tǒng)膝擂,我就想能不能在這個(gè)子系統(tǒng)里搭建一個(gè)靜態(tài)博客讶泰,因?yàn)檫@樣就無(wú)需安裝nodejs和git了毅待。中途遇到了很多問(wèn)題馒闷,直到今天才終于成功酪捡。下面記錄一下過(guò)程。
啟用linux子系統(tǒng)
首先在設(shè)置里啟用開(kāi)發(fā)者模式纳账,然后啟用或關(guān)閉Windows功能里勾選“適用于Linux的Windows子系統(tǒng)”逛薇,重啟后在命令提示符里輸入“bash”后回車(chē),確認(rèn)后就開(kāi)始下載子系統(tǒng)了疏虫。下載結(jié)束后永罚,在開(kāi)始菜單里會(huì)出現(xiàn)一個(gè)Ubuntu的圖標(biāo),打開(kāi)以后就是Linux子系統(tǒng)了卧秘。
安裝必備環(huán)境
我們知道呢袱,Hexo的運(yùn)行環(huán)境是nodejs,所以我們要先在子系統(tǒng)里安裝nodejs翅敌。這里有一個(gè)坑产捞,那就是我直接使用“sudo apt install nodejs”安裝以后,在使用npm時(shí)總是報(bào)錯(cuò)哼御,說(shuō)什么權(quán)限不夠,網(wǎng)上找了很多辦法焊唬,都沒(méi)有解決恋昼。直到今天,我嘗試著用nvm安裝了最新的nodejs赶促,這個(gè)問(wèn)題才得以解決液肌。
使用nvm安裝最新nodejs
- 安裝nvm之前執(zhí)行以下命令:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
- nvm執(zhí)行腳本(最新版請(qǐng)去官網(wǎng)查看):
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
- 更新環(huán)境變量:
source ~/.profile
- 列出所有nodejs版本:
nvm ls-remote
- 安裝最新版本:
nvm install 8.5.0
安裝git
sudo apt install git
開(kāi)始搭建Hexo
- 安裝hexo框架
npm install -g hexo-cli
- 進(jìn)入你用來(lái)存放博客的文件夾,執(zhí)行:
hexo init
npm install
- 把博客同步到Github Page上還需要兩個(gè)插件:
npm install hexo -server --save
npm install hexo-deployer-git --save
- 我的_config.yml:
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site
title: yuanwenjun's blog
subtitle: It's wonderful life!
description:
author: yuanwenjun
language: zh-CN
timezone:
# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://yuanwenjun.github.io
root: /
permalink: :year/:month/:day/:title/
permalink_defaults:
# Directory
source_dir: source
public_dir: public
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
i18n_dir: :lang
skip_render:
# Writing
new_post_name: :title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
external_link: true # Open external links in new tab
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
future: true
highlight:
enable: true
line_number: true
auto_detect: false
tab_replace:
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
path: ''
per_page: 10
order_by: -date
# Category & Tag
default_category: uncategorized
category_map:
tag_map:
# Date / Time format
## Hexo uses Moment.js to parse and display date
## You can customize the date format as defined in
## http://momentjs.com/docs/#/displaying/format/
date_format: YYYY-MM-DD
time_format: HH:mm:ss
# Pagination
## Set per_page to 0 to disable pagination
per_page: 8
pagination_dir: page
# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
plugin:
- hexo-generator-feed
- hexo-generator-sitemap
- hexo-generator-baidu-sitemap
#Feed Atom
feed:
type: atom
path: atom.xml
limit: 20
theme: Hacker
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo:
github: git@github.com:yuanwenjun/yuanwenjun.github.io.git
coding: git@git.coding.net:ablog/ablog.git
branch: master