Github和Coding同步部署hexo说明(搭建篇)

  自从看到了hexo这个能在github上部署blog的东西就喜欢的一塌糊涂,各种上谷歌,百度找资料,花了7-8天时间搞了起来,天天写blog的日子真的蛮好了,每天不写的什么就仿佛缺了点什么似的痒痒的不行。在这里分享一下这么多多天碰到的一些坎和一些翻过坎之后的经验。话不多说,先上些环境参数:

  • hexo版本
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
$ hexo -v
hexo: 3.6.0
hexo-cli: 1.1.0
os: Linux 4.15.6-1-ARCH linux x64
http_parser: 2.8.0
node: 9.7.1
v8: 6.2.414.46-node.20
uv: 1.19.2
zlib: 1.2.11
ares: 1.13.0
modules: 59
nghttp2: 1.29.0
napi: 2
openssl: 1.0.2n
icu: 60.2
unicode: 10.0
cldr: 32.0.1
tz: 2017c
  • 使用的NexT版本 NexT on github

    1
    2
    # Theme version
    version: 6.0.4
  • 安装的npm module,使用flickr的原因是图都上传在flickr上,不想用国内的图床。

    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
    $ cat package.json 
    {
    "name": "hexo-site",
    "version": "0.0.0",
    "private": true,
    "hexo": {
    "version": "3.6.0"
    },
    "dependencies": {
    "gulp": "^3.9.1",
    "gulp-htmlclean": "^2.7.20",
    "gulp-htmlmin": "^4.0.0",
    "gulp-minify-css": "^1.2.4",
    "hexo": "^3.6.0",
    "hexo-deployer-git": "^0.3.1",
    "hexo-filter-github-emojis": "^1.4.4",
    "hexo-footnotes": "^1.0.2",
    "hexo-generator-archive": "^0.1.4",
    "hexo-generator-category": "^0.1.3",
    "hexo-generator-feed": "^1.2.2",
    "hexo-generator-index-pin-top": "^0.2.2",
    "hexo-generator-json-content": "^3.0.1",
    "hexo-generator-searchdb": "^1.0.8",
    "hexo-generator-sitemap": "^1.2.0",
    "hexo-generator-tag": "^0.2.0",
    "hexo-renderer-ejs": "^0.3.0",
    "hexo-renderer-marked": "^0.3.0",
    "hexo-renderer-stylus": "^0.3.1",
    "hexo-server": "^0.2.0",
    "hexo-tag-aplayer": "^2.0.7",
    "hexo-tag-dplayer": "^0.3.1",
    "hexo-tag-flickr-extended": "0.0.3",
    "hexo-wordcount": "^3.0.2"
    }
    }
  • 同时上传至github和coding,修改文件blog主目录下的配置文件

    1
    2
    3
    4
    5
    6
    7
    8
     # Deployment
    # Docs: https://hexo.io/docs/deployment.html
    deploy:
    type: git
    repo:
    github: git@github.com:YOURNAME/YOURRES.github.io.git
    coding: git@git.coding.net:YOURNAME/YOURRES.git
    branch: master
  • 修改和NexT theme的config.yml和layout中的footer.swig,加入coding的链接然后审核一下就可以去掉自定义页面中会出现的跳转页面。

    1
    2
    3
    4
    5
    6
    # 修改footer.swig的最后定义custom_text的地方,去掉原有的注释。
    {% if theme.footer.custom_text %}
    <div class="footer-custom">
    {{ theme.footer.custom_text }}{#
    }</div>
    {% endif %}
  • 针对主题配置文件的修改网络上现存的都是直接修改footer.swig,我试过只修改这个配置文件对新版本的theme没用,后来看主题配置文件的时候看到了人家已经写好了这么一行,把注释去掉特别方便。

    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
    #修改NexT主题目录下的配置文件,打开custom text的选项。
    #我这边只关闭了powerd和theme版本的说明,嫌麻烦。。。。
    $ vim themes/next/_config.yml
    footer:
    # Specify the date when the site was setup.
    # If not defined, current year will be used.
    since: 2018

    # Icon between year and copyright info.
    icon: chess-knight

    # If not defined, will be used `author` from Hexo main config.
    copyright:
    # -------------------------------------------------------------
    # Hexo link (Powered by Hexo).
    powered: false

    theme:
    # Theme & scheme info link (Theme - NexT.scheme).
    enable: false
    # Version info of NexT after scheme info (vX.X.X).
    version: false
    # -------------------------------------------------------------
    # Any custom text can be defined here.
    custom_text: Hosted by <a target="_blank" rel="external nofollow" href="https://pages.coding.me"><b>Coding Pages</b></a>

目前hexo+NexT的搭建就算完成了,基本的配置google,baidu一下会有很多,搭建的细节就不多说了。接下来的SEO搜索引擎优化和https请参考我的另外一篇文档Github和Coding同步部署hexo说明(Seo篇) ,另外新版本的theme配lean会报错,目前还没找到什么好办法。

linky-fan wechat
一吃一大碗的天字第n号
感谢您对我的支持
0%