美文网首页
使用Hexo在githu上搭建博客

使用Hexo在githu上搭建博客

作者: FanChengSheng | 来源:发表于2016-11-17 10:12 被阅读127次

Hexo是一款基于Node.js的静态博客框架。可以方便的生成静态网页托管在github上.
由于 Hexo 是基于 Node ,安装前要先安装 Node,这个网上文章很多介绍。
本文详细介绍如何使用Hexo在github上搭建博客。

Hexo 的安装

  1. 安装Hexo,要用全局安装,加-g参数
    D:\github>npm install hexo-cli -g
    安装hexo发布到github的指令
    D:\github>npm install hexo-deployer-git -S
  2. 创建一个blog的目录并把Hexo的源代码下载到blog目录
    D:\github>hexo init blog
  3. 进入下载的hexo目录
    D:\github>cd blog
  4. 安装依赖运行包
    D:\github\blog>npm install
  5. 启动hexo本地程序
    D:\github\blog>hexo server
  6. 启动浏览器进入查看:http://127.0.0.1:4000

Hexo 的全局配置

修改全局配置时,注意缩进,同时注意冒号后面要有一个空格。
在根目录 _config.yml 中修改

# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/

# Site 站点配置
title: 溪水博客 # 网站标题
subtitle: 日积月累 # 网站副标题
description: 整理消化日常的工作技术文档和代码 # 网站描述
author: FanChengSheng # 你的名字
language: zh-CN # 网站使用的语言
timezone: Asia/Shanghai # 网站时区

# URL 
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://www.xishui.red #网址,搜索时会在搜索引擎中显示
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 # Include code 文件夹
i18n_dir: :lang # 国际化文件夹
skip_render: # 跳过指定文件的渲染,您可使用 glob 来配置路径

# 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 # 把文件名称转换为 (1) 小写或 (2) 大写
render_drafts: false # 显示草稿
post_asset_folder: false # 是否启动资源文件夹
relative_link: false # 把链接改为与根目录的相对位址
future: true
highlight: # 代码块的设置
  enable: true
  line_number: true
  auto_detect: false
  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 #每页显示的文章量 (0 = 关闭分页功能)
pagination_dir: page #分页目录

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: jacman #当前主题名称

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy: #部署到github
  type: git
  repo: https://github.com/fanchengsheng/blog.git
  branch: master

Hexo 的主题配置

主题的配置文件在 /themes/主题文件夹/_config.yml ,一般包括导航配置(menu),内容配置(content),评论插件,图片效果(fancybox)和边栏(sidebar)。
主题的文件目录必须在 themes 目录下。
Hexo提高了大量的主题,可以在全局配置文件中更改主题:

# Extensions
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: jacman #当前主题名称

Hexo 的基本使用方法

  1. 写文章通过 new 命令新建一篇文章
hexo new [layout] <title>

其中layout是可选参数,默认值为 post 。
如果没有设置 layout 的话,默认使用 _config.yml 中的 default_layout 参数代替。如果标题包含空格的话,需用引号括起来。
这个在全局配置里面如下:

# Writing 写作配置
new_post_name: :title.md # File name of new posts
default_layout: post # 默认布局

Hexo提供的layout在 scaffolds 目录下,也可以在此目录下自建layout文件。
scaffolds\post 内容如下,添加了一个分类

---
title: {{ title }}
date: {{ date }}
tags:
categories:
---

新建的文件则会保存到 source/_post 目录下。
source/_post/使用Hexo在githu上搭建博客.md
然后启动服务器(hexo s),便能看到刚刚发表的文章
发表的文章会全部显示,如果文章很长,就只要显示文章的摘要就行了。在需要显示摘要的地方添加如下代码即可:

以上是摘要
<!--more-->
以下是余下全文
  1. 在部署之前,需要通过命令把所有的文章都做静态化处理,就是生成对应的html, javascript, css,使得所有的文章都是由静态文件组成的
    hexo generate
    在本地目录下,会生成一个public的目录,里面包括了所有静态化的文件。
  2. 生成静态文件之后,如果要发布到github,还需要配置 deploy 指令。在全局的配置文件中找到 deploy
    hexo deploy
    如果部署的是个人页,新建的仓库必须的 your-user-name.github.io 。
    请参考https://github.com/fanchengsheng/fanchengsheng.github.io.git
  3. 域名配置如下:

命令总结

Hexo常用命令:
启动hexo本地程序
hexo s == hexo server
创建新的博客文章
hexo n == hexo new "Hello World"
生成静态网站
hexo g == hexo generate
把程序发布到github上面
hexo d == hexo deploy

相关网址

hexo地址:https://hexo.io/
github: https://github.com/fanchengsheng/fanchengsheng.github.io.git
访问地址: https://fanchengsheng.github.io/
域名映射地址:http://www.xishui.red/
使用的主题: https://github.com/wuchong/jacman.git

相关文章

  • 使用Hexo在githu上搭建博客

    Hexo是一款基于Node.js的静态博客框架。可以方便的生成静态网页托管在github上.由于 Hexo 是基于...

  • 在Coding上搭建Hexo博客

    title: 在Coding上搭建Hexo博客 tags: hexo 参考文章 使用hexo搭建博客Pacman主...

  • 我的博客开通了

    我的博客blossom,欢迎大家来玩...留言互换link 本博客使用hexo搭建,主题使用Cho搭建于githu...

  • 使用Hexo搭建博客

    使用 Hexo 在 coding上搭建博客 要使用Hexo搭建博客,一定先在电脑上安装 node (建议使用 No...

  • hexo和github搭建个人博客

    hexo和github搭建个人博客 参照博客 本地搭建 工具hexo 和 git Node.js 申请githu...

  • HEXO 趟坑笔记

    我的blog 如何使用Hexo在github上搭建静态博客 如何使用Hexo在github上搭建静态博客 感冒两天...

  • hexo ERROR Deployer not found: g

    利用 Hexo & Github 搭建静态博客时出现ERROR Deployer not found: githu...

  • 使用hexo 搭建github博客

    使用hexo 搭建github博客 目的: 通过hexo 在github上 搭建一个个人技术博客的网站 我之前已...

  • 使用 hexo 搭建个人博客 02

    在我的上一篇文章《使用 hexo 搭建个人博客 01》中,介绍了使用 hexo 搭建博客的基本知识。本篇将主要介绍...

  • 编写发布博客

    【详细】 →→→ →→→【Hexo搭建独立博客全纪录】(三)使用Hexo搭建博客 1.新建文章 hexo会帮我们在...

网友评论

      本文标题:使用Hexo在githu上搭建博客

      本文链接:https://www.haomeiwen.com/subject/pzrdpttx.html