陈川点滴

Hexo + Github Pages 搭建博客

动手搭建Hexo + Github Pages 的静态资源博客。基于Mac OS系统。

搭建环境

安装Node.jsGit 环境

具体的安装前提可以参考文档

安装Hexo

执行命令

1
$ npm install -g hexo-cli ##-g 全局安装

全局安装

  1. 将安装包放在 /usr/local 下
  2. 可以直接在命令行里使用
    1
    $ hexo -v

查看是否安装成功执行

建站

启动Hexo服务

安装 Hexo 完成后,请执行下列命令,Hexo 将会在指定文件夹中新建所需要的文件。

1
2
3
$ hexo init <folder> ##hexo需要安装的目录
$ cd <folder>
$ npm install

至此为止Hexo的搭建大功告成。下面开始运行Hexo。

1
2
$ hexo generte
$ hexo server

直接访问localhost:4000 ,可以看到Hexo已经运行起来。

个性化

  1. 设置theme
    本人选择的Next主题 ,选用主题的Scheme是Mist,整洁有序的单栏外观,顺便说一下修改Next的Schems文件在themes/next/_config.yml下。
    1
    2
    3
    #scheme: Muse
    scheme: Mist
    #scheme: Pisces

我这边是直接在github下载的Next的主题 ,然后在Hexo目录下的themes下解压。

  1. 修改默认选项
    Hexo的默认选项在项目根目录下的_config_yml下。具体的修改可以参看我自己的配置文件。
    #Hexo Configuration
    ## Docs: https://hexo.io/docs/configuration.html
    ## Source: https://github.com/hexojs/hexo/# Site
    title: 陈川点滴             ##网站标题
    subtitle: 人、技术、成长     ##网站副标题
    description: 立即行动       ##网站描述
    author: 陈川               ##您的名字
    ##头像地址
    avatar: https://avatars2.githubusercontent.com/u/7081564?v=3&s=460
    ##语言,这里选择简体中文
    language: zh-Hans
    timezone:
    ##社交
    social:
      GitHub: https://github.com/truechuan# URL
    ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
    url: http://truechuan.github.io
    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: 10
    pagination_dir: page# Extensions
    ## Plugins: https://hexo.io/plugins/
    ## Themes: https://hexo.io/themes/
    theme: next      ##配置多说,参考 http://duoshuo.com/
    duoshuo_shortname: truechuan
    duoshuo_share: true
    duoshuo_hotartical: true# Search
    search:
    path: search.xml
    field: post
    format: html
    limit: 10000# Deployment
    ## Docs: https://hexo.io/docs/deployment.html
    deploy:     ##配置githubdeploy
      type: git #部署工具的类型
      repository: git@github.com:truechuan/truechuan.github.com.git #SSH链接
      branch: master #分支
    

安装插件

  1. 安装多说 ,社交评论插件。具体配置参看前面我的_config_yml。
  2. 安装站内搜索工具Local Search
  3. 不蒜子统计 。这里特别注意,是取themes下的_config.yml下修改配置文件。
  4. 创建标签云
  5. 未完待续…

创建第一篇博客

所有的博客内容都存在source目录。
执行命令

1
$ hexo new [layout] <title>

GitHub Pages

在source目录下找到对应的md文件进行编写。具体的MarkDown的语法

创建github仓库

仓库名称以全局的_config.yml配置的repository选项保持一致。

发布上传

在全局的_config.yml配置deploy选项,执行命令

1
2
3
4
5
$ hexo deploy
###出现如下报错
ERROR Deployer not found: git
###解决上述报错可以使用以下代码,反之则跳过
$npm install hexo-deployer-git --save

继续执行,还是出现问题

ERROR: Repository not found.
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

解决这个问题是github的密钥导致的。执行

1
#ssh-keygen -t rsa -b 4096 -C "xxx@xxx.com"

然后将id_rsa.pub的内容上传到github的SSH keys,参看路径 Settings->SSH and GPG keys
我这里使用的是IDEA将整个项目源码上传,本人建议,以防万一。

陈川 wechat
欢迎您扫一扫上面的微信公众号,订阅我的博客!

热评文章