[Turn] Teach you how to build a github technical blog

http://www.jianshu.com/p/701b1095da11

suitable for the crowd

  • People who like to blog
  • Have a certain programming foundation
  • person who loves tossing
  • Proficient in using version control Git
  • Learn about using Github
  • Familiar with basic MarkDown syntax

Environmental preparation

Install Git

Download  msysgit  and execute to complete the installation.

Install Node.js

Installing Node.js in Windows environment is   very simple, just download the installation file and execute it to complete the installation.

install hexo

It can be installed using the npm command. (Right click anywhere and select Git bash)

npm install -g hexo

问题

  • npm ERR! registry error parsing json error

You may need to set up an npm proxy and execute the command

npm config set registry http://registry.cnpmjs.org
  • hexo:command not found
    Delete the npm directory you just installed, and re-execute the command npm install -g hexo to install hexo,

Create the hexo folder

After the installation is complete, in your favorite folder (such as H:\hexo), execute the following command (click the right mouse button in H:\hexo, select Git bash), Hexo will automatically create the website in the target folder. of all files.

hexo init

Install dependencies

npm install

View locally

Now that we have set up a local hexo blog, execute the following command (in H:\hexo), then go to the browser and enter localhost:4000 to see.

hexo generate
hexo server

Well, so far, the local blog has been set up, but it is only local, and others can't see it. Next, we are going to deploy to Github.

问题

  • Executing the hexo server prompts that the instruction cannot be found
    . Solution:
    After Hexo 3.0, the server is separated out, and the server needs to be installed. The installation command is as follows:
    npm install hexo -server --save
    Install this server and try again, the problem is solved

github create blog

Create a page repository

The name of this repository needs to correspond to your account, in the format: yourname.github.io
Enter the basic information, and then click Create Repository.


2

3


注意
Naming rules: your github account.github.io, I was hacked here. It was written by jekell before, but now it is replaced by hexo, so I created another repository.

Generate SSH keys

ssh-keygen -t rsa -C "your email address", press 3 Enter, the password is empty.

Under C:\Users\Administrator.ssh, get two files id_rsa and id_rsa.pub.

Add SSH keys on GitHub

Open id_rsa.pub and copy the full text. https://github.com/settings/ssh  , Add SSH key, paste it in.

hexo use

Directory Structure

.
├── .deploy #Files that need to be deployed
├── node_modules #Hexo plugin
├── public #Generated static web page file
├── scaffolds
#Template ├── source #Blog text and other source files, 404, favicon, CNAMEs should be placed here
| ├── _drafts #drafts
| └── _posts #articles├──
themes #
theme├── _config.yml #global configuration file
└── package.json

Global configuration_config.yml

# Hexo Configuration
## Docs: http://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site #站点信息
title:  #标题
subtitle:  #副标题
description:  #站点描述,给搜索引擎看的
author:  #作者
email:  #电子邮箱
language: zh-CN #语言
# URL #链接格式
url:  #网址
root: / #根目录
permalink: :year/:month/:day/:title/ #文章的链接格式
tag_dir: tags #标签目录
archive_dir: archives #存档目录
category_dir: categories #分类目录
code_dir: downloads/code
permalink_defaults:
# Directory #目录
source_dir: source #源文件目录
public_dir: public #生成的网页文件目录
# Writing #写作
new_post_name: :title.md #新文章标题
default_layout: post #默认的模板,包括 post、page、photo、draft(文章、页面、照片、草稿)
titlecase: false #标题转换成大写
external_link: true #在新选项卡中打开连接
filename_case: 0
render_drafts: false
post_asset_folder: false
relative_link: false
highlight: #语法高亮
  enable: true #是否启用
  line_number: true #显示行号
  tab_replace:
# Category & Tag #分类和标签
default_category: uncategorized #默认分类
category_map:
tag_map:
# Archives
2: 开启分页
1: 禁用分页
0: 全部禁用
archive: 2
category: 2
tag: 2
# Server #本地服务器
port: 4000 #端口号
server_ip: localhost #IP 地址
logger: false
logger_format: dev
# Date / Time format #日期时间格式
date_format: YYYY-MM-DD #参考http://momentjs.com/docs/#/displaying/format/
time_format: H:mm:ss
# Pagination #分页
per_page: 10 #每页文章数,设置成 0 禁用分页
pagination_dir: page
# Disqus #Disqus评论,替换为多说
disqus_shortname:
# Extensions #拓展插件
theme: landscape-plus #主题
exclude_generator:
plugins: #插件,例如生成 RSS 和站点地图的
- hexo-generator-feed
- hexo-generator-sitemap
# Deployment #部署,将 lmintlcx 改成用户名
deploy:
  type: git
  repo: 刚刚github创库地址.git
  branch: master

注意

  • The configuration file has a space after the colon ":"
  • repo: 刚刚github创库地址.git

hexo命令行使用

常用命令:

hexo help #查看帮助
hexo init #初始化一个目录
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成网页,可以在 public 目录查看整个网站的文件
hexo server #本地预览,'Ctrl+C'关闭
hexo deploy #部署.deploy目录
hexo clean #清除缓存,**强烈建议每次执行命令前先清理缓存,每次部署前先删除 .deploy 文件夹**

简写:

hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy

编辑文章

新建文章

hexo new "标题"

在 _posts 目录下会生成文件标题.md

title: Hello World
date: 2015-07-30 07:56:29 #发表日期,一般不改动
categories: hexo #文章文类
tags: [hexo,github] #文章标签,多于一项时用这种格式
---
正文,使用Markdown语法书写

编辑完后保存,hexo server 预览

hexo部署

执行下列指令即可完成部署。

hexo generate
hexo deploy

以下提示说明部署成功

[info] Deploy done: git

点击 Github 上项目的 Settings,GitHub Pages,提示Your site is published at http://wuxiaolong.me (这是我买的域名)

图床

1.墙裂推荐七牛云储存,注册地址

2.七牛云储存提供10G的免费空间,以及每月10G的流量.存放个人博客图片最好不过了

3.七牛云储存还有各种图形处理功能、缩略图、视频存放速度也给力(非打广告)。

具体使用见使用七牛作为github博客的图床

域名

将独立域名与GitHub Pages的空间绑定

方法一:在站点source目录下面,新建一个名为CNAME的文本文件,里面写入你要绑定的域名,比如wuxiaolong.me
方法二:在Repository的根目录下面,新建一个名为CNAME的文本文件,里面写入你要绑定的域名,比如wuxiaolong.me

DNS设置

DNSpod,快,免费,稳定。
注册DNSpod,添加域名,如下图设置。


其中A的两条记录指向的ip地址是github Pages的提供的ip
如何知道你的github上项目的IP,如下:

去Godaddy修改DNS地址

更改godaddy的Nameservers为DNSpod的NameServers。

总结

之前用的jekell写的,手把手教你建github技术博客by jekyll,也是折腾了几天才做成自己满意的,昨天决定换成hexo,也是花了一天半时间,为了追求更好,必须折腾!

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326419449&siteId=291194637