Hexo创建个人博客

Hexo安装、配置,在github上部署,yelee主题配置

安装nodejs和npm

1
2
sudo apt-get install nodejs
sudo apt-get install npm

安装hexo

创建文件夹

1
2
mkdir Hexo  
cd Hexo

安装Hexo

1
sudo npm install -g hexo

初始化

1
hexo init

此步骤会在hexo文件夹下生成默认的网站模板文件。

清除之前生成的静态模板文件:

1
hexo clean

生成新的静态模板文件:

1
hexo generate(hexo g)

启动hexo的本地服务器:

1
hexo server(hexo s)

github配置

1.新建一个仓库

1
github名.github.io

(名称必须与github名一致)
在该仓库Settings下GitHub Pageszhong设置Custom domain为自己的域名(和hexo中CNAME设置一样)
在source目录下创建文件CNAME
写入自己的域名

2.修改_config.yml文件
deploy:
type: git
repository: https://github.com/githubID/仓库名.github.io.git
branch: master

3.部署

1
hexo deploy(hexo d)

安装 Hexo Admin插件

1
npm install --save hexo-admin

打开本地管理界面
http://localhost:4000/admin

新建博客

1.创建文章
hexo根目录命令行输入hexo new <模板> <文章名>新建文章

参数功能路径
post新建文章/source/_posts/
draft新建草稿/source/_drafts/
page新建页面(标签、分类等)/source/

通常情况下使用hexo new post name
会在source/_posts下生成一个name.md的文件。

添加图片

配置_config_yml里面的post_asset_folder:false这个选项设置为true。
安装hexo-asset-image,运行hexo n "xxxx"来生成md博文时,/source/_posts文件夹内除了xxxx.md文件还有一个同名的文件夹,把图片放入该文件夹。
问题直接运行npm install hexo-asset-image save安装的插件有问题,图片不能正确显示,生成的html中图片路径不对(显示 /.top//name.png),使用如下即可。

1
npm install https://github.com/7ym0n/hexo-asset-image --save

插入图片,在md中加入

1
![xxx](blogName/imageName.png)

需要配置_config.yml中的url,本地配置为localhost,远程配置为对应的域名
参考

问题

安装hexo错误:(nodejs版本太低,不能用apt直接升级)

解决
1.产看node版本,没安装的请先安装;

1
$  node -v

2.清楚node缓存;

1
$  sudo npm cache clean -f

3.安装node版本管理工具’n’;

1
$  sudo npm install n -g

4.使用版本管理工具安装指定node或者升级到最新node版本;

1
$  sudo n stable  (安装node最新版本)

参考

hexo d(ERROR Deployer not found: git)

解决

1
npm install --save hexo-deployer-git

hexo输入数学公式不显示

  1. 在开始部分插入如下代码

    1
    2
    3
    <script type="text/javascript" async
    src="https://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-MML-AM_CHTML">
    </script>
  2. 在网页中插入所需数学公式的特定格式(或者见yelee):
    (插入1后)

    1
    2
    3
    4
    5
    <script type="text/x-mathjax-config">
    MathJax.Hub.Config({
    tex2jax: {inlineMath: [['$','$'], ['\\(','\\)']]}
    });
    </script>

参考

有序列表显示问题“- A空格”

  • A boy
  • A- boy
    如上显示正常显示,前面应该有一个圆点,第一行A空格前面没有圆点。暂时解决只能在A后直接加字符

yelee

1.在 themes下

1
git clone https://github.com/MOxFIVE/hexo-theme-yelee.git themes/yelee

2.修改_config.yml

1
theme: yelee

3.支持数学公式
修改 themes/yelee/_config.yml

1
mathjax: true

4.不喜欢yelee的标题风格
修改 themes/yelee/_config.yml

1
heading_stytle:2  //改为github风格

5.社交图标设置
themes/yelee/source/css/_partial/customise/social-icon.styl

参考
yelee配置中文说明
yelee github
博客搭建

Contents
  1. 1. 安装nodejs和npm
  2. 2. 安装hexo
  3. 3. github配置
  4. 4. 安装 Hexo Admin插件
  5. 5. 新建博客
  6. 6. 添加图片
  7. 7. 问题
    1. 7.1. 安装hexo错误:(nodejs版本太低,不能用apt直接升级)
    2. 7.2. hexo d(ERROR Deployer not found: git)
    3. 7.3. hexo输入数学公式不显示
    4. 7.4. 有序列表显示问题“- A空格”
  8. 8. yelee
|