Lichord

学习笔记

0%

hexo+github Page搭建博客与配置

前提:安装了Node.js,Git,注册github账号,并且创建了一个{githubname}.github.io的仓库

安装与配置Hexo

  • 打开命令行输入 npm install -g hexo-cli
  • 本地新建空文件夹(文件夹名字可以随意取)
  • 目录切换到新建文件夹下
  • 初始化hexo init ./
  • 安装依赖 npm install
  • hexo generator
  • hexo s --debug
  • 在浏览器输入 http://localhost:4000 进入自己的博客
    hexo.png

配置自己喜欢的主题

hexo部署到Github

  • 修改{githubname}.github.io目录下的配置文件_config.yml

    1
    2
    3
    4
    5
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: https://github.com/your_githubName/your_githubName.github.io.git
  • 通过下面的命名进行博客静态页面的生成,以及部署到远端Github Pages

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    # 安装部署插件
    $ npm install hexo-deployer-git --save
    #删除静态文件,即 public 文件
    $ hexo clean
    #生成静态文件,即 public 文件
    $ hexo generate
    #部署到远程站点
    $ hexo deploy
    #也可以使用组合命令(替代上面2条命令):生成静态命令并部署到远程站点
    $ hexo deploy -g
  • 设置不渲染 README.md

    1
    2
    3
    # 在source目录下新建README.md
    #修改_config.yml文件,设置不渲染的文件
    skip_render: README.md

常用hexo命令

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #部署到GitHub
hexo help # 查看帮助
hexo version #查看Hexo的版本

# 缩写
hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy

# 组合
hexo s -g #生成并本地预览
hexo d -g #生成并上传

_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
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site
title: Banana
subtitle:
description:
keywords:
author: Lixian
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: http://yoursite.com
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: README.md

# 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: true
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: 10
pagination_dir: page

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: Pacman

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: https://github.com/lichord/lichord.github.io.git
  • 冒号后面必须有一个空格,否则可能会出问题。

md文件开头写法

1
2
3
4
5
6
7
8
9
10
---
title: hexo+github Page搭建博客与配置
date: 2019-07-12 10:14:23
tags:
- hexo
- tag2
categories:
- github page
- category2
---

参考&更多: