利用Windows內(nèi)置Linux子系統(tǒng)搭建Hexo靜態(tài)博客

之前博客是在Windows上搭建的,后來Windows 10內(nèi)置了linux子系統(tǒng),我就想能不能在這個子系統(tǒng)里搭建一個靜態(tài)博客,因為這樣就無需安裝nodejs和git了。中途遇到了很多問題,直到今天才終于成功。下面記錄一下過程。

啟用linux子系統(tǒng)

首先在設(shè)置里啟用開發(fā)者模式,然后啟用或關(guān)閉Windows功能里勾選“適用于Linux的Windows子系統(tǒng)”,重啟后在命令提示符里輸入“bash”后回車,確認(rèn)后就開始下載子系統(tǒng)了。下載結(jié)束后,在開始菜單里會出現(xiàn)一個Ubuntu的圖標(biāo),打開以后就是Linux子系統(tǒng)了。

安裝必備環(huán)境

我們知道,Hexo的運行環(huán)境是nodejs,所以我們要先在子系統(tǒng)里安裝nodejs。這里有一個坑,那就是我直接使用“sudo apt install nodejs”安裝以后,在使用npm時總是報錯,說什么權(quán)限不夠,網(wǎng)上找了很多辦法,都沒有解決。直到今天,我嘗試著用nvm安裝了最新的nodejs,這個問題才得以解決。

使用nvm安裝最新nodejs

  1. 安裝nvm之前執(zhí)行以下命令:
sudo apt-get update
sudo apt-get install build-essential libssl-dev
  1. nvm執(zhí)行腳本(最新版請去官網(wǎng)查看):
curl -o- https://raw.githubusercontent.com/creationix/nvm/v0.33.4/install.sh | bash
  1. 更新環(huán)境變量:
source ~/.profile
  1. 列出所有nodejs版本:
nvm ls-remote
  1. 安裝最新版本:
nvm install 8.5.0

安裝git

sudo apt install git

開始搭建Hexo

  1. 安裝hexo框架
npm install -g hexo-cli
  1. 進入你用來存放博客的文件夾,執(zhí)行:
hexo init
npm install
  1. 把博客同步到Github Page上還需要兩個插件:
npm install hexo -server --save
npm install hexo-deployer-git --save
  1. 我的_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
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • 作者:李旺成 時間:2016年4月27日 一、技術(shù)選型 常見個人博客搭建方案 搭建個人博客通常有如下選擇: Wor...
    diygreen閱讀 26,641評論 26 310
  • 用了一段時間的hexo,本著“授人以魚,不如授人以漁”的理念,決定整理一篇hexo使用教程,分享大家。 hexo是...
    王藝謀712閱讀 6,509評論 0 3
  • 第一章 安裝Git工具 下載GitHub for Windows,直接點擊安裝,安裝完成后,可以看到“Git Sh...
    不圓的石頭閱讀 12,158評論 5 63
  • 表妹今年要參加高考,而且她是藝術(shù)類考生。姑姑和姑父都非常緊張,壓力很大。姑姑和姑父都是做金融行業(yè)的,家里住別墅,表...
    最喜不過淡雅閱讀 133評論 0 0
  • 我想做個溫暖你的人 清晨叫你起床 睡前語音晚安 天冷為你添衣 雨天為你撐傘 下班為你做頓好飯 我想做個溫暖你的人 ...
    Y小姐_閱讀 495評論 1 3

友情鏈接更多精彩內(nèi)容