Github Page + Hexo 搭建静态博客傻瓜式教程

2017-11-12 14:28:34 +08:00
 cnscorpions

本文面向对象

  • 前端小白
  • windows 用户
  • 懒癌晚期患者

准备工作:

  1. 一个Github 账户
  2. 安装[Git]( https://pan.baidu.com/s/1dFKYu5r,'windows 国内镜像')
  3. 安装Node.js

Step by Step


### Step 1, 创建一个 Github page


  1. Repo name 的填写格式为 Github 名 + github.io。举个栗子,我的 repo name 为 cnscorpions.github.io
  2. Description 可以写static blog/blog,反正你随意就好
  3. 点击创建 repo

Step 2, Hexo 安装以配置 (假设你已经安装好 Git 和 Node.js )

  • 打开 Git bash 命令行
  • 安装 NPM ---> Taobao NPM 镜像 (因为网络环境不好,你懂的) $ npm install -g cnpm --registry=https://registry.npm.taobao.org
  • 安装 Hexo $ cnpm install -g hexo-cli
  • 创建 blog 根目录 $ hexo init blog
  • 生成静态文件 $ hexo g
  • 安装 Hexo-server 模块 $ cnpm install hexo-server --save
  • 运行本地服务器 (一定要在 blog 根目录下运行) $ hexo s
  • 打开http://localhost:4000/已经可以看到一篇内置的 blog 了

Step 3, 安装 Hexo 主题 ( Git 在线安装 VS 本地安装)

  • Git 安装
$ hexo clean
$ git clone https://github.com/iissnan/hexo-theme-next
  • 修改配置文件 _config.yml/theme ---> next
  • 更新主题
$ hexo c 
$ hexo g   
$ hexo s

Step 4, 安装 SSH

  • 安装 hexo-deployer-git 模块 $ cnpm install hexo-deployer-git --save
  • 修改配置文件
deploy:
  type: git
  repo: https://github.com/cnscorpions/cnscorpions.github.io.git
  branch: master
  • 检查电脑中是否存在 SSH key $ ls -al ~/.ssh
  • 创建新的 SSH key
$ ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
Enter a file in which to save the key (/c/Users/you/.ssh/id_rsa):[Press enter] ---> 不要移动文件位置
Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]
  • 复制 id_rsa.pug
  • 复制到 Github SSH key
  • 搞定 $ hexo g ---> $ hexo d ----> OVER

PS: 暂时先这样了,欢迎拍砖!

2551 次点击
所在节点    Hexo
9 条回复
CreSim
2017-11-12 14:35:48 +08:00
搭博客容易,写博客难。
gobomb
2017-11-12 15:24:50 +08:00
我搭过的博客比写过的多😂
nieyujiang
2017-11-12 17:02:33 +08:00
@gobomb #2 握爪.我好像也是这样.🌚
Remember
2017-11-12 17:51:25 +08:00
换 hugo 吧, hexo 半死亡状态,而且 npm 各种被墙.
billion
2017-11-12 19:24:13 +08:00
这种被人写烂了的教程发到 V 站真没有意思。不如换 Hugo
cnscorpions
2017-11-14 12:39:01 +08:00
@CreSim 是的,坚持写喽
cnscorpions
2017-11-14 12:40:23 +08:00
@ gobomb 呵呵,hexo + github page 写技术,再弄个 wordpress 应该够了吧
cnscorpions
2017-11-14 12:41:33 +08:00
@Remember 我有选择恐惧症啊,不过 npm 可以用淘宝的镜像 taobao.org
cnscorpions
2017-11-14 12:42:20 +08:00
@billion 抱歉了,老铁,我是菜鸟,一步一步来喽

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/405712

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX