這是使用 Hexo 的初體驗系列

Hexo

Hexo是基於Node.js的網誌框架,也就是本網誌的系統!
目前版本2.8.0
這是一位台灣的大大所寫的

特點

官網首頁寫的

A fast, simple & powerful blog framework, powered by Node.js.

  • Blazing Fast
  • Markdown Support
  • One-Command Deployment
  • Various Plugins

安裝

體驗

  1. 安裝hexo

    1
    npm install -g hexo
  2. 在當前目錄建一個網誌資料夾

    1
    hexo init blog && cd blog
  3. 移動到資料夾裡

    1
    cd blog
  4. 安裝

    1
    npm install
  5. 生成檔案在public資料夾

    1
    hexo generate
  6. 在本機架伺服器(可預覽網站,網址是 http://localhost:4000)

    1
    2
    hexo server
    hexo server -p 5000 <!-- 切換特定 port -->
  7. 清空快取

    1
    hexo clean

上架到Github Pages

  1. 創建一個repository
    repository name為”任意名稱”

  2. 修改網誌資料夾裡的_config.yml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    url: http://你的帳號.github.io/
    root: /你的repository名稱/

    ...

    deploy:
    type: git
    repo: repository的位置
    branch: 分支名稱
  3. 上傳到Github
    輸入命令(可能需要輸入github帳密)

    1
    hexo deploy

設定參考

這是我目前 _config.yml 的設定

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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html

# Site
title: Pink Blog
subtitle:
description:
author: pinkpika
email: tim801217@gmail.com
language: zh-TW

# URL
url: http://pinkpika.github.io/pinkblog/
root: /pinkblog/
permalink: :year/:month/:day/:title/
tag_dir: tags
archive_dir: archives
category_dir: categories
code_dir: downloads/code
permalink_defaults:

# Directory
source_dir: source
public_dir: public

# Writing
new_post_name: :year:month:day-:title.md # File name of new posts
default_layout: post
titlecase: false # Transform title into titlecase
filename_case: 0
render_drafts: false
post_asset_folder: true
relative_link: false
highlight:
enable: true
line_number: true
tab_replace:

# Category & Tag
default_category: uncategorized
category_map:
tag_map:

# Archives
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
## archive: 2
## category: 2
## tag: 2

# Archives
## 2: Enable pagination
## 1: Disable pagination
## 0: Fully Disable
archive: 1
category: 1
tag: 1

index_generator:
per_page: 10
archive_generator:
per_page: 30
tag_generator:
per_page: 30
category_generator:
per_page: 30

# Server
## Hexo uses Connect as a server
## You can customize the logger format as defined in
## http://www.senchalabs.org/connect/logger.html
port: 4000
server_ip: localhost
logger: false
logger_format: dev

# 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: MMM D YYYY
time_format: H:mm:ss

# Pagination
## Set per_page to 0 to disable pagination
per_page: 5
pagination_dir: page

# Disqus
disqus_shortname:

# Extensions
## Plugins: https://github.com/hexojs/hexo/wiki/Plugins
## Themes: https://hexo.io/themes/
theme: landscape
exclude_generator:

# Deployment
deploy:
type: git
repo: git@github.com:pinkpika/pinkblog.git
branch: main