(单机上面搭建Hexo就不再多说,配置好git、nodejs、hexo就能使用啦!具体百度一下就行…)
思路:在github的博客项目仓库中新建一个分支。原master分支用来存放生成的静态网页,新的分支用来存放Hexo生成的网站原始文件
多系统Hexo同步
linux ubuntu
下配置环境
1 | sudo apt-get install nodejs # 安装nodejs |
在github仓库中新建分支
点击branch
,输入新分支名(这里我用的名称是source
),点击创建
将新建的source
分支设为默认分支
在该仓库中,点击Setting
->Branches
->Default branch
,将默认分支设为source
,并保存
在本地克隆仓库,并上传源文件
- 首先,在命令行输入
git branch
查看当前是否是新建分支source
- 克隆仓库项目
git clone https://github.com/xxxx/xxx.git
- 进入克隆文件夹,将
.git
以外的全部文件删除 - 将除
.deploy_git,node_modules,public
以外的全部源文件拷贝到该系统的此克隆目录下 - 修改
.gitignore
,如果没有该文件,可以新建一个,内容为:
1 | .DS_Store |
- push 源文件
1 | git add . |
- 部署博客
1 | hexo clean && hexo g && hexo d |
- 同步源文件
1 | git fetch |
- 然后就可以新建博客,推送分支了
常用命令
1 | # hexo 安装配置 |
Hexo 编写博客
Hexo 编写博客 (一)新建博客并同步到github
1 | hexo new "博客名" # 会在/source/_posts/ 目录下新建md文件,编辑即可修改 |
Hexo 编写博客 (二)如何在博客中插入图片
打开主题配置文件
themes/next/_config.yml
1
2
3
4
5
6
7# 找到avatar 字段
先去除avatar前的注释符#
url可以是任意的,相对于该配置文件source/的相对路径或者绝对路径或者是网络上的路径
# 特别注意:
图像放在/themes/next/source/images中
url:/image/xxx.png 即可
Hexo 编写博客 (三)博客添加标签、类别等属性
生成属性链接页面
1
2
3
4
5
6
7
8
9# 标签属性
hexo new page tags
vim /source/tags/index.md
# 在文件中添加 type: tags
# 类别属性
hexo new page categories
vim /source/categories/index.md
# 在文件中添加 type: categories修改主题配置文件
在
theme/
中打开配置文件_config.yml
, 找到menu
参数,将tags和categories的注释去掉即可添加相应链接
Hexo 编写博客 (四)访问次数统计
打开
/theme/next/_config.yml
配置文件1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16#找到 busuanzi,将enable 设为true
busuanzi_count:
enable: true
total_visitors: true
total_visitors_icon: fa fa-user
total_views: true
total_views_icon: fa fa-eye
post_views: true
post_views_icon: fa fa-eye
# 找到footer 在底下添加counter,并设为true
footer:
# Specify the date when the site was setup. If not defined, current year will be used.
since: 2020
counter: true
...打开
themes/next/layout/_partials/footer.swig
1
2
3
4# 在最后添加以下代码
{%- if theme.footer.counter %}
<script async src="//dn-lbstatics.qbox.me/busuanzi/2.3/busuanzi.pure.mini.js"></script>
{%- endif %}Hexo 编写博客 (五)添加博客结束标记
打开
themes/next/layout/_macro/passage-end-tag.swig
(没有就新建)1
2
3
4{%- if theme.passage_end_tag.enabled %}
<div style="text-align:center;color: #ccc;font-size:14px;">
------ 本文结束<i class="fa fa-paw"></i>感谢您的阅读 ------</div>
{%- endif %}打开
themes/next/layout/_macro/post.swig
1
2
3
4
5
6
7
8
9
10
11# 在post-body之后 post-footer之前添加下面代码
#{#####################}
#{### END POST BODY ###}
#{#####################}
# 上述是文件 位置,下面是添加的代码
{%- if not is_index %}
<div>
{%- include 'passage-end-tag.swig' %}
</div>
{%- endif %}打开
themes/next/_config.yml
1
2
3# 末尾添加
passage_end_tag:
enabled: true
Hexo 编写博客 (六)hexo无法正常显示latex语法
参考链接
安装插件
1
npm install hexo-math –save
解决语义冲突
修改
node_modules\kramed\lib\rules\inline.js
1
2
3
4
5
6第11行
//escape: /^\\([\\`*{}\[\]()#$+\-.!_>])/,
escape: /^\\([`*\[\]()#$+\-.!_>])/,
第20行
// em: /^\b_((?:__|[\s\S])+?)_\b|^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,
em: /^\*((?:\*\*|[\s\S])+?)\*(?!\*)/,更改配置文件
打开主题文件夹中的
_config.yml
对应位置改为:1
2
3
4
5
6# MathJax Support
mathjax:
enable: true
per_page: true
#cdn: //cdn.bootcss.com/mathjax/2.7.1/latest.js?config=TeX-AMS-MML_HTMLorMML
cdn: //cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.1/MathJax.js?config=TeX-AMS-MML_HTMLorMML
写博客
需要加上
mathjax:true
1
2
3
4
5
6---
title: index.html
date: 2018-2-8 21:01:30
tags:
mathjax: true
--
Hexo 编写博客 (七)hexo无法正常显示本地插图
修改总配置文件_config.yml
post_asset_folder: true
安装插件,在命令窗口输入
npm install https://github.com/CodeFalling/hexo-asset-image -- save
在markdown编辑时引入图片
注:每篇博客所需的图片都放在其同名文件夹下
Hexo 编写博客 (八)hexo提交搜索引擎(百度+谷歌)
参考链接