hexo搭建

hexo搭建

安装环境

  • nodejs,git安装
    此处不举例,自行百度

  • hexo-cli安装

    npm install -g hexo-cli

特定文件夹初始化hexo

$hexo init 或者npm install hexo --save

1
2
3
4
5
6
7
8
9
10
11
12
13
14
>># 安装插件
>>npm install hexo-generator-index --save
>>npm install hexo-generator-archive --save
>>npm install hexo-generator-category --save
>>npm install hexo-generator-tag --save
>>npm install hexo-server --save
>>npm install hexo-deployer-git --save
>>npm install hexo-deployer-heroku --save
>>npm install hexo-deployer-rsync --save
>>npm install hexo-deployer-openshift --save
>>npm install hexo-renderer-marked --save
>>npm install hexo-renderer-stylus --save
>>npm install hexo-generator-feed --save
>>npm install hexo-generator-sitemap --save

Git配置多个SSH-Key

  • 当有多个git账号时,比如:

    a. 一个gitee,用于公司内部的工作开发;

    b. 一个github,用于自己进行一些开发活动;

  • 解决方法

    1. 生成一个公司用的SSH-Key

      $ ssh-keygen -t rsa -C '174499700@qq.com' -f ~/.ssh/gitee_id_rsa

    2. 生成一个github用的SSH-Key

      ssh-keygen -t rsa -C 'benguahao@foxmail.com' -f ~/.ssh/github_id_rsa

    3. 在 ~/.ssh 目录下新建一个config文件,添加如下内容(其中Host和HostName填写git服务器的域名,IdentityFile指定私钥的路径)

      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      # gitee
      Host gitee.com
      HostName gitee.com
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/gitee_id_rsa
      # github
      Host github.com
      HostName github.com
      PreferredAuthentications publickey
      IdentityFile ~/.ssh/github_id_rsa

如果源的网速不好

可以更换淘宝源:npm install -g cnpm --registry=https://registry.npm.taobao.org

把npm命令替换使用cnpm命令

修改配置文件

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

# Site 站点信息设置
title: 心雨纷扬的博客 #站名
subtitle: 一个简单的博客 #副标题
description: #站描述
author: Xyfy #作者
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://www.52dzd.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:

# 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:

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

# Extensions 扩展
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: landscape

# Deployment 这里设置了Git获
#这里一定要注意不要写错了,否则部署到Github上会出问题
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:xyfy/xyfy.github.io.git
branch: master
message: '站点更新:{{now("YYYY-MM-DD HH/mm/ss")}}'

发布部署

1
2
3
4
# 编译
hexo generate
# 在主机的hexo目录下 执行以下命令将自动更新到Github
hexo d

修改主题和配置配置文件

  • 安装主题NexT

    ps: 我们现在在目录hexo下

    git clone https://github.com/next-theme/hexo-theme-next themes/next

    并在目录hexo下的_config.yml中找到 theme: 修改后面的参数,默认是 landscape

    theme: next

  • 克隆慢问题解决

    修改/etc/hosts文件 ,加入两行

    1
    2
    151.101.72.249 http://global-ssl.fastly.Net
    192.30.253.112 http://github.com

参考文档

  • https://www.jianshu.com/p/0823e387c019
  • https://gitee.com/help/articles/4229