145. hexo搭建博客

配置环境

安装 Hexo

接下来就需要安装 Hexo 了,这是一个博客框架,Hexo 官方还提供了一个命令行工具,用于快速创建项目、页面、编译、部署 Hexo 博客,所以在这之前我们需要先安装 Hexo 的命令行工具。 命令如下:

1
$ npm install -g hexo-cli

信息提前说明

配置文件说明

在 Hexo 中有两份主要的配置文件,其名称都是 _config.yml。 其中,一份位于*站点根目录下,主要包含 Hexo 本身的配置;另一份位于主题目录*下,这份配置由主题作者提供,主要用于配置主题相关的选项。

为了描述方便,在以下说明中,将前者称为 站点配置文件, 后者称为 主题配置文件

初始化 hexo

  1. 创建文件夹

    1
    $ mkdir io_github_qeuroal
  2. 初始化

    1
    2
    $ hexo init
    $ mkdir ~/Desktop/hexo && ls -al > ~/Desktop/hexo/hexo_init.info
  3. 将 Hexo 编译生成 HTML 代码

    1
    $ hexo generate
  4. 本地运行

    1
    $ hexo server
  5. 站点配置文件

    • 修改根目录下的 _config.yml 文件,找到 Site 区域,这里面可以配置站点标题 title、副标题 subtitle 等内容、关键字 keywords 等内容.

      例:

      1
      2
      3
      4
      5
      6
      # Site
      title: NightTeam
      subtitle: 一个专注技术的组织
      description: 涉猎的主要编程语言为 Python、Rust、C++、Go,领域涵盖爬虫、深度学习、服务研发和对象存储等。
      keywords: "Python, Rust, C++, Go, 爬虫, 深度学习, 服务研发, 对象存储"
      author: NightTeam
    • language 的字段设置为 zh-CN

配置主题

Pure 主题

使用 pure, 教程见这里的 《Hexo搭建个人博客并部署到Github》和《Hexo博客主题pure使用说明》

下载主题

  1. 下载

    1
    $ git clone https://github.com/cofess/hexo-theme-pure.git themes/pure
  2. 启用主题

    修改 站点配置文件

    1
    theme: pure

更新主题 (可选, 暂未使用过)

1
2
$ cd themes/pure
$ git pull

主题配置

导航菜单

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# 导航菜单
menu:
Home: .
Archives: archives # 归档
Categories: categories # 分类
Tags: tags # 标签
Repository: repository # github repositories
Books: books # 书单
Links: links # 友链
About: about # 关于

# 导航菜单图标(font awesome)
menu_icons:
enable: true # 是否启用菜单图标
home: fa-dashboard
archives: fa-delicious
categories: fa-folder
tags: fa-tags
repository: fa-code
books: fa-leanpub
links: fa-gg
about: fa-coffee

主题配置

1
2
3
4
5
6
7
8
9
10
11
# config
config:
skin: theme-black # 主题颜色 theme-blue theme-green theme-purple
layout: main-center # 布局方式 main-left main-center main-right
toc: true # 是否开启文章章节目录导航
menu_highlight: false # 是否开启当前菜单高亮显示
thumbnail: false # enable posts thumbnail, options: true, false
excerpt_link: Read More
#New
isNewTabLinks: true #是否链接打开新标签页
autoUnfold: true # 默认展开文章目录

页面显示

1
2
3
4
5
6
7
8
9
# Pagination
pagination:
number: false
prev:
alwayShow: true
next:
alwayShow: true
midSize: 2 # 当前页码左右到省略号显示的页码数,默认2,表现为 1 ... 4 5 6 7 8 ... 10
showContent: false # 页面文章小于2篇时显示文章内容

大图显示

1
2
# Fancybox
fancybox: false

捐赠

直接更改照片文件即可

修改为自己的名字

  • cofess<your name>

修改 example.com

全局搜索 example.com 将其替换成网站网址 Qeuroal.top

个人链接

1
2
3
4
5
6
links:
Github: https://github.com/Qeuroal
Blog: http://blog.Qeuroal.com
微博: http://weibo.com/Qeuroal
# 花瓣: http://huaban.com/Qeuroal
# Behance: https://www.behance.net/Qeuroal

个人标签

1
2
3
# My Personal Labels
labels:
- 后端

搜索 (未处理)

主题内置三种站内搜索方式:insight、swiftype、baidu

1
2
3
4
5
# Search
search:
insight: true # you need to install `hexo-generator-json-content` before using Insight Search
swiftype: # enter swiftype install key here
baidu: false # you need to disable other search engines to use Baidu search

文章启用目录索引

1
2
3
4
5
6
title: 文章标题
categories:
- 文章分类
tags:
- 文章标签
toc: true # 是否启用内容索引

分享

支持weibo,qq,qzone,wechat,tencent,douban,diandian,facebook,twitter,google,linkedin

1
2
3
4
5
6
# Share
# weibo,qq,qzone,wechat,tencent,douban,diandian,facebook,twitter,google,linkedin
share:
enable: true # 是否启用分享
sites: weibo,qq,wechat,facebook,twitter # PC端显示的分享图标
mobile_sites: weibo,qq,qzone # 移动端显示的分享图标

分类, 标签, 仓库, about等菜单的配置

/theme/pure/_source 下的所有文件复制到 /source

友情链接

复制theme/pure/_source/ 目录下links文件夹到blog path/source/ 目录下

在 hexo 目录下的 source 文件夹内创建一个名为 _data(禁止改名)的文件夹。

然后在文件内创建一个名为 links.yml 的文件,在其中添加相关数据即可。

单个友情链接的格式为:

1
2
3
4
Name:
link: http://example.com
avatar: http://example.com/avatar.png
desc: "这是一个描述"

添加多个友情链接,我们只需要根据上面的格式重复填写即可。

数学公式

Hexo默认使用 “hexo-renderer-marked” 引擎渲染网页,该引擎会把一些特殊的 markdown 符号转换为相应的 html 标签

解决方案

解决方案有很多,可以网上搜下,为了节省大家的时间,这里只提供亲身测试过的方法。

更换 Hexo 的 markdown 渲染引擎,hexo-renderer-markdown-it-plus 引擎替换默认的渲染引擎 hexo-renderer-marked 即可。

安装hexo-renderer-markdown-it-plus插件
1
2
npm un hexo-renderer-marked --save
npm i hexo-renderer-markdown-it-plus --save
配置

安装插件后,如果未正常渲染LaTeX数学公式,在博客配置文件_config.yml中添加

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
markdown_it_plus:
highlight: true
html: true
xhtmlOut: true
breaks: true
langPrefix:
linkify: true
typographer:
quotes: “”‘’
plugins:
- plugin:
name: markdown-it-katex
enable: true
- plugin:
name: markdown-it-mark
enable: false
文章启用mathjax
1
2
title: Hello World
mathjax: true

文章简介内容不全显式

1
showContent: false # 页面文章小于2篇时显示文章内容

删除部分文件

  • themes/pure/_config.yml.example
  • themes/pure/README.cn.md
  • themes/pure/README.md

关闭订阅

  •  # rss
     # rss: /atom.xml
     
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11

    - ```yml
    social:
    links:
    github: https://github.com/Qeuroal
    weibo: http://weibo.com/Qeuroal
    twitter: https://twitter.com/Qeuroal
    # facebook: /
    # dribbble: /
    behance: https://www.behance.net/Qeuroal
    # rss: atom.xml

更改头像

1
2
3
profile:
# avatar: images/avatar.jpg
avatar: images/avatar.png

更改个人简介

文件: /source/about/index.md

安装插件

hexo-deployer-git (must, common)

安装
1
$ npm install hexo-deployer-git --save
站点配置(根目录) config.yml

_config.yml

1
2
3
4
5
6
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: {git repo ssh address}
branch: master

hexo-generator-feed (normal, 但不推荐订阅)

Github:https://github.com/hexojs/hexo-generator-feed

简介

RSS的生成插件,你可以在配置显示你站点的RSS,文件路径\atom.xml。

安装:
1
$ npm install hexo-generator-feed --save
配置:

在博客配置文件_config.yml中添加

1
2
3
4
5
6
feed:
type: atom
path: atom.xml
limit: 20
hub:
content:
  • type - Feed type. (atom/rss2)
  • path - Feed path. (Default: atom.xml/rss2.xml)
  • limit - Maximum number of posts in the feed (Use 0 or false to show all posts)
  • hub - URL of the PubSubHubbub hubs (Leave it empty if you don’t use it)
  • content - (optional) set to ‘true’ to include the contents of the entire post in the feed.

hexo-generator-json-content (must)

Github

https://github.com/alexbruno/hexo-generator-json-content

简介

用于生成静态站点数据,提供搜索功能的数据源。

安装
1
$ npm install hexo-generator-json-content --save
配置

在博客配置文件_config.yml中添加

1
2
3
4
5
6
7
jsonContent:
ignore:
- path/to/a/page
- url/to/one/post
- an-entire-category
- specific.file
- .ext # a file extension

在github上用hexo搭建了自己的博客,用typora写完一篇博文,满怀欣喜地deploy之后发现图片加载失败…真的很吐血。去网上一搜索,嗯,好像不少人都遇到了这个问题,解决方法看似一大堆实则无效或过时不匹配,绝大多数资料都是安装hexo-asset-image的插件,亲测对于markdown图片路径没有用啊!比出现问题更折磨人的是遇上一堆错误的解决方法…

我想要寻找在本地和网页上都能显示的办法,终于发现了一款插件hexo-image-link,是将markdown图片路径转换为asset_img语法,使得图片能够同时显示在typora和hexo上。

1
{% asset_img "local-image.png" "image file label" %} -> {% asset_img label local-image.png %}
具体步骤
  • 修改_config.yml中的post_asset_folder: true

  • 安装hexo-image-link

    1
    $ npm install hexo-image-link --save
  • 修改 站点配置文件post_asset_folder: true

  • 如果 npm下载比较慢的话,尝试 cnpm下载

  • 安装

    1
    2
    $ npm install -g cnpm --registry=https://registry.npm.taobao.org
    $ cnpm install hexo-image-link --save
  • 修改md文件中的图片路径

hexo-autonofollow (bad)

Github:https://github.com/liuzc/hexo-autonofollow

简介:自动为站外链接添加nofollow属性

安装:

1
$ npm install hexo-autonofollow --save

配置:

在博客配置文件_config.yml中添加

1
2
3
4
5
nofollow:
enable: true
exclude:
- exclude1.com
- exclude2.com
  • enable - 是否启用
  • exclude - 排除域名

配置主题无意义的组件

豆瓣书单 (关闭, 毫无意义)

复制theme/pure/_source/ 目录下books文件夹到blog path/source/ 目录下

1
2
3
4
5
# douban 豆瓣书单
douban:
user: *** # 豆瓣用户名
start: 0 # 从哪一条记录开始
count: 100 # 获取豆瓣书单数据条数
评论 (关闭, 鸡肋)
1
2
comment:
type: # 启用哪种评论系统, 不填即关闭

Next 主题

下载主题

  1. 最新版本:

    Download the Latest Master Branch

  2. 稳定版本

    Download the Latest Release Version

  3. 指定版本

    Download the Specific Release Version

    In rare cases useful, but not recommended.
    You must define version. Let’s take v8.0.0 as an example. Replace it with any version from tags list.

  4. git 下载

    1
    2
    $ cd io_github_qeuroal
    $ git clone https://github.com/next-theme/hexo-theme-next themes/next

教程: Installation

主题配置

修改 theme/next/_config.yml

主题配置文件

1
2
3
4
5
#Schemes
#scheme: Muse
#scheme: Mist
scheme: Pisces
#scheme: Gemini
  1. 将 about、tags、categories 前的 #号去掉,示例如下:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    menu:
    home: / || fa fa-home
    about: /about/ || fa fa-user
    tags: /tags/ || fa fa-tags
    categories: /categories/ || fa fa-th
    archives: /archives/ || fa fa-archive
    #schedule: /schedule/ || fa fa-calendar
    #sitemap: /sitemap.xml || fa fa-sitemap
    #commonweal: /404/ || fa fa-heartbeat
  2. 新建相关页面

    在博客根目录下执行下列命令

    1
    2
    3
    4
    $ hexo new page "about"
    $ hexo new page "tags"
    $ hexo new page "categories"
    $ hexo new page 404
  3. 修改生成页面的配置

    1
    2
    3
    4
    source/about/index.md
    source/tags/index.md
    source/categories/index.md
    source/404/index.md
  4. 404 相关

    front-matter 中添加 permalink: /404,表示指定该页面固定链接为 http://“主页”/404.html

    1
    2
    3
    4
    5
    6
    7
    ---
    title: 404 Not Found:该页无法显示
    toc: false
    comments: false
    permalink: /404
    ---
    <script type="text/javascript" src="//www.qq.com/404/search_children.js" charset="utf-8" homePageUrl="<%- config.url %>" homePageName="回到我的主页"></script>

设置左上角或右上角 github 图标

主题配置文件,启用 github-banner 如下:

1
2
3
4
github_banner:
enable: true
permalink: https://https://github.com/Qeuroal
title: Follow me on GitHub

设置侧栏阅读进度百分比

编辑站点配置文件,修改 back2top 部分如下

1
2
3
4
copyback2top:
enable: true
sidebar: true
scrollpercent: true

设置网页底部信息

查看主题配置文件,修改 footer 配置如下:

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
footer:
# Specify the year when the site was setup. If not defined, current year will be used.
#since: 2021

# Icon between year and copyright info.
icon:
# Icon name in Font Awesome. See: https://fontawesome.com/icons
name: fa fa-heart
# If you want to animate the icon, set it to true.
animated: false
# Change the color of icon, using Hex Code.
color: "#ff0000"

# If not defined, `author` from Hexo `_config.yml` will be used.
# Set to `false` to disable the copyright statement.
copyright:

# Powered by Hexo & NexT
powered: true

# Beian ICP and gongan information for Chinese users. See: https://beian.miit.gov.cn, http://www.beian.gov.cn
beian:
enable: false
icp:
# The digit in the num of gongan beian.
gongan_id:
# The full num of gongan beian.
gongan_num:
# The icon for gongan beian. See: http://www.beian.gov.cn/portal/download
gongan_icon_url:

图片懒加载设置

在主题配置文件中启用 lazyload

1
copylazyload: true

设置代码块复制和代码高亮

在主题配置文件中修改 codeblock

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
codeblock:
# Code Highlight theme
# All available themes: https://theme-next.js.org/highlight/
theme:
light: atom-one-dark
dark: stackoverflow-dark
prism:
light: prism
dark: prism-dark
# Add copy button on codeblock
copy_button:
enable: true
# Available values: default | flat | mac
style:
# Fold code block
fold:
enable: false
height: 500

修改文章底部标签样式

在主题配置文件中修改

1
copytag_icon: true

网站icon

1
2
3
4
5
6
favicon:
small: /images/favicon.png
medium: /images/favicon.png
apple_touch_icon: /images/avatar.jpg
safari_pinned_tab: /images/avatar.jpg
#android_manifest: /manifest.json

侧边栏头像

1
2
3
4
5
6
7
8
# Sidebar Avatar
avatar:
# Replace the default image and set the url here.
url: /images/avatar.png
# If true, the avatar will be displayed in circle.
rounded: true
# If true, the avatar will be rotated with the cursor.
rotated: true

侧边栏社交链接

修改主题配置文件

1
2
3
4
5
6
7
8
9
10
social:
GitHub: https://github.com/Qeuroal || fab fa-github
#E-Mail: mailto:yourname@gmail.com || fa fa-envelope
#Weibo: https://weibo.com/yourname || fab fa-weibo
#Twitter: https://twitter.com/yourname || fab fa-twitter
#FB Page: https://www.facebook.com/yourname || fab fa-facebook
#StackOverflow: https://stackoverflow.com/yourname || fab fa-stack-overflow
#YouTube: https://youtube.com/yourname || fab fa-youtube
#Instagram: https://instagram.com/yourname || fab fa-instagram
#Skype: skype:yourname?call|chat || fab fa-skype

在文章底部增加版权信息

编辑 主题配置文件,修改如下配置:

1
2
3
4
5
6
7
8
9
10
creative_commons:
# Available values: by | by-nc | by-nc-nd | by-nc-sa | by-nd | by-sa | cc-zero
license: by-nc-sa
# Available values: big | small
size: small
sidebar: false
post: true
# You can set a language value if you prefer a translated version of CC license, e.g. deed.zh
# CC licenses are available in 39 languages, you can find the specific and correct abbreviation you need on https://creativecommons.org
language:

开启缓存

1
2
3
# Allow to cache content generation. Introduced in NexT v6.0.0.
cache:
enable: true

压缩

1
2
# Remove unnecessary files after hexo generate.
minify: true

侧边栏显示分类条数

1
2
# Posts / Categories / Tags in sidebar.
site_state: true

友链

1
2
3
4
5
6
7
8
9
10
# Blog rolls 友链
links_settings:
icon: fa fa-link # 设置icon
title: 友情链接 # 设置标题
# Available values: block | inline
layout: block # css样式,是一行一条,还是自动换行

links:
友链1: http://yoursite.com
#... 依次追加即可

文章toc

1
2
3
4
5
6
toc:
enable: true # 是否开启
number: true # 自动显示文章编号
wrap: false # 溢出是否换行
expand_all: true # 展开所有还是手风琴
max_depth: 4 # 显示最大深度

顶部元信息

1
2
3
4
5
6
7
post_meta:
item_text: true # 使用中文显示
created_at: true
updated_at:
enable: true
another_day: true
categories: true

首页摘要

1
2
excerpt_description: false  # 关闭自动提取
read_more_btn: trues # 显示阅读全文
  1. 手动控制

    使用<!--more-->控制

  2. 使用 front-matter 中添加 descriptionexcerpt 字段

    1
    2
    3
    4
    ---
    description: your excerpt
    excerpt: your excerpt
    ---

安装插件

hexo-deployer-git (must, common)

  1. 安装

    1
    $ npm install hexo-deployer-git --save
  2. 站点配置(根目录) config.yml

    _config.yml

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: {git repo ssh address}
    branch: master

在github上用hexo搭建了自己的博客,用typora写完一篇博文,满怀欣喜地deploy之后发现图片加载失败…真的很吐血。去网上一搜索,嗯,好像不少人都遇到了这个问题,解决方法看似一大堆实则无效或过时不匹配,绝大多数资料都是安装hexo-asset-image的插件,亲测对于markdown图片路径没有用啊!比出现问题更折磨人的是遇上一堆错误的解决方法…

我想要寻找在本地和网页上都能显示的办法,终于发现了一款插件hexo-image-link,是将markdown图片路径转换为asset_img语法,使得图片能够同时显示在typora和hexo上。

1
{% asset_img "local-image.png" "image file label" %} -> {% asset_img label local-image.png %}
具体步骤
  • 修改_config.yml中的post_asset_folder: true

  • 安装hexo-image-link

    1
    $ npm install hexo-image-link --save
  • 修改 站点配置文件post_asset_folder: true

注:

  • 如果 npm下载比较慢的话,尝试 cnpm下载

  • 安装

    1
    2
    $ npm install -g cnpm --registry=https://registry.npm.taobao.org
    $ cnpm install hexo-image-link --save
  • 修改md文件中的图片路径

hexo-generator-searchdb

  1. 安装 exo-generator-searchdb 这个插件

    1
    $ npm install hexo-generator-searchdb --save
  2. 配置 主题配置文件: _config.yml

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    # Local Search
    # Dependencies: https://github.com/next-theme/hexo-generator-searchdb
    local_search:
    enable: true
    # If auto, trigger search by changing input.
    # If manual, trigger search by pressing enter key or search button.
    trigger: auto
    # Show top n results per article, show all results by setting to -1
    top_n_per_article: 1
    # Unescape html strings to the readable one.
    unescape: false
    # Preload the search data when the page loads.
    preload: false

部署

  1. 配置站点配置文件 _config.yml

    1
    2
    3
    4
    5
    6
    # Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo: {git repo ssh address}
    branch: master
  2. 部署

    1
    $ hexo deploy

自定义域名

添加 CNAME 文件

/source 文件夹下添加 CNAME 文件, 如下所示:

hexo 常用命令

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

git

删除远程仓库里的某个文件/文件夹

在git中可以用git rm命令删除文件(删除远程仓库文件)

1
2
3
4
5
6
git clone 仓库地址
git add .
step1: git rm 文件 //本地中该文件会被删除
step2: git rm -r 文件夹 //删除文件夹
step3: git commit -m '删除某个文件'
step4: git push (origin master)

上面的方法会把对应的本地文件也删除掉,如果不想把本地文件删除,只把缓存区中的对应部分删除,则加上 --cached

1
2
git rm --cached 文件 //本地中该文件不会被删除
git rm -r --cached 文件夹 //删除文件夹

git add . 后面执行上面的命令,再推送到 github 远程仓库上的时候,仓库里面对应的文件/文件夹就会被删除

1
2
3
4
5
6
git clone 仓库地址
git add .
step1: git rm --cached 文件 //本地中该文件不会被删除
step2: git rm -r --cached 文件夹 //删除文件夹
step3: git commit -m '删除某个文件'
step4: git push (origin master)

git commit后,如何撤销commit

修改了本地的代码,然后使用:

1
2
git add file
git commit -m '修改原因'

复制

执行commit后,还没执行push时,想要撤销这次的commit,该怎么办?

解决方案: 使用命令:

1
git reset --soft HEAD^

复制

这样就成功撤销了commit,如果想要连着add也撤销的话,–soft改为–hard(删除工作空间的改动代码)。

1
2
HEAD^ 表示上一个版本,即上一次的commit,也可以写成HEAD~1
如果进行两次的commit,想要都撤回,可以使用HEAD~2

复制

1
2
--soft
不删除工作空间的改动代码 ,撤销commit,不撤销git add file

复制

1
2
--hard
删除工作空间的改动代码,撤销commit且撤销add

复制

另外一点,如果commit注释写错了,先要改一下注释,有其他方法也能实现,如:

1
2
git commit --amend
这时候会进入vim编辑器,修改完成你要的注释后保存即可。

撤销 git add . 并保留修改的方法

执行完 git add .

文件退出暂存区,但是修改保留:

1
git reset --mixed

撤销所有的已经 add 的文件:

1
git reset HEAD .

撤销某个文件或文件夹:

1
git reset HEAD  -filename

另外:可以用 git status Git 会告诉你可以通过那个命令来执行操作。

补充

可以用 git status Git 会告诉你可以通过那个命令来执行操作。

push 失败

case 1

OpenSSL SSL_read: Connection was reset, errno 10054的话就把代理关了

删除未跟踪文件

1
2
# 删除 untracked files
git clean -f
1
2
# 连 untracked 的目录也一起删掉
git clean -fd
1
2
# 连 gitignore 的untrack 文件/目录也一起删掉 (慎用,一般这个是用来删掉编译出来的 .o之类的文件用的)
git clean -xfd
1
2
3
4
# 在用上述 git clean 前,墙裂建议加上 -n 参数来先看看会删掉哪些文件,防止重要文件被误删
git clean -nxfd
git clean -nf
git clean -nfd

多终端同步

新建私有仓库

1
2
3
4
5
6
7
echo "# Readme" >> README.md
git init
git add README.md
git commit -m "first commit"
git branch -M master
git remote add origin <your https repo address>
git push -u origin master

文件夹说明

文件夹 说明 是否需要上传github
node_modules hexo需要的模块,就是一些基础的npm安装模块,比如一些美化插件,在执行npm install的时候会重新生成 不需要
themes 主题文件 ==需要==
public hexo g命令执行后生成的静态页面文件 不需要
packages.json 记录了hexo需要的包的信息,之后换电脑了npm根据这个信息来安装hexo环境 ==需要==
_config.yml 全局配置文件,这个不用多说了吧 ==需要==
.gitignore hexo生成的默认的.gitignore模块 ==需要==
scaffolds 文章的模板 ==需要==
.deploy_git hexo g自动生成的 不需要

.gitignore内容

1
2
3
4
5
6
7
.DS_Store
Thumbs.db
db.json
*.log
node_modules/
public/
.deploy*/

删除.git文件

删除所有主题的 .git 文件,如:rm -rf ./theme/pure/.git

查找 .git 文件

在==根目录==下执行以下命令

1
find . -name ".git*"

上传

1
2
3
git add .
git commit -m "<yout commit statement>"
git push

新电脑上的操作

  1. 下载

    1
    git clone <your repo>
  2. 安装依赖

    1
    npm install

    npm install其实就是读取了 packages.json 里面的信息,自动安装依赖,有的小伙伴可能只执行npm install就行了,不过按照上面的三步是最稳妥的

  3. 仓库更新

    为了保证同步,推荐先合并更新再进行博客的编写

    • pull (不推荐)

      1
      git pull
    • fetch

      1
      2
      git fetch --all    #将远程git仓库上最新的内容拉取到本地,将本地库所关联的远程库更新至最新
      git reset --hard origin/master #强制将本地内容指向刚刚同步git云端内容

      reset 对所拉取的文件不做任何处理,此处不用 pull 是因为本地尚有许多文件,使用 pull 会有一些版本冲突,解决起来也麻烦,而本地的文件都是初始化生成的文件,较拉取的库里面的文件而言基本无用,所以直接丢弃。

  4. 部署

    1
    2
    hexo clean && hexo g && hexo s
    hexo d

更新脚本

1

QAs

Error: Cannot find module ‘hexo-util’

  • 方法1

    1. rm -rf node_modules
    2. npm install hexo-util
  • 方法2

    For those who also encounter this issue, please check your NPM version.

    • > 3: Still not work. Please remove node_modules directory and reinstall using npm install.
    • < 3: Please add hexo-util explicitly via npm install –save-dev hexo-util to you site package deps.

    reference: https://github.com/iissnan/hexo-theme-next/issues/1490