第4节-git、github、hexo搭建博客

Hexo搭建GitHub博客

先来看一下我搭建的博客:https://chenxingxing6.github.io/


你们会发现我这个域名是github的,那这个怎么弄呢?

拿我的来讲:https://chenxingxing6.github.io/

1.github用户名:chenxingxing6

2.建立一个博客项目,项目名字为:chenxingxing6.github.io


然后进入我们的项目,点击右上角的setting



怎么用hexo主题快速搭建博客呢?

前提条件:搭建好了git环境,hexo

sudo npm install -g hexo


终端cd到一个你选定的目录(比如创建一个blog文件,$cd blog),执行hexo init命令:

$ hexo init

在blog目录下,执行如下命令,安装npm:

$ npm install

执行如下命令,开启hexo服务器:

$ hexo s

此时,浏览器中打开网址http://localhost:4000


本地的blog文件夹下内容为:

1
2
3
4
5
6
7
_config.yml   
db.json
node_modules
package.json
scaffolds
source
themes

1.修改配置文件

$ vim _config.yml

打开后往下滑到最后,修改成下边的样子:

1
2
3
4
deploy:
     type: git
     repository: https: //github.com/MuYunyun/MuYunyun.github.io.git
     branch: master

2.hexo g生成静态页面命令:

$ hexo generate        或者:hexo g


3.再执行配置命令: hexo d

若你未关联Github,则执行hexo deploy命令时终端会提示你输入Github的用户名和密码,即

1
2
Username  for  'https://github.com' :
Password  for  'https://github.com' :

为避免每次输入Github用户名和密码的麻烦:

1.1.检查SSH keys是否存在Github

执行如下命令,检查SSH keys是否存在。如果有文件id_rsa.pubid_dsa.pub,则直接进入步骤1.3将SSH key添加到Github中,否则进入下一步生成SSH key。

$ ls -al ~/.ssh

1.2.生成新的ssh key

执行如下命令生成public/private rsa key pair,注意将your_email@example.com换成你自己注册Github的邮箱地址。

$ ssh-keygen -t rsa -C "your_email@example.com"

默认会在相应路径下(~/.ssh/id_rsa.pub)生成id_rsaid_rsa.pub两个文件。

1.3.将ssh key添加到Github中

Find前往文件夹~/.ssh/id_rsa.pub打开id_rsa.pub文件,里面的信息即为SSH key,将这些信息复制到Github的Add SSH key页面即可。

进入Github --> Settings --> SSH keys --> add SSH key:

Title里任意添一个标题,将复制的内容粘贴到Key里,点击下方Add key绿色按钮即可。


安装theme

你可以到Hexo官网主题页去搜寻自己喜欢的theme。这里以hexo-theme-next为例

终端cd到 blog 目录下执行如下命令:

$ git clone https://github.com/iissnan/hexo-theme-next themes/next

将_config.yml theme的名称landspace修改为next

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

# Site
title: 陈星星的博客
subtitle: 相信就能看见,有梦想就有蓝天
description: 相信就能看见,有梦想就有蓝天
author: 解不开的星杰
language:
timezone:

# URL
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: https://chenxingxing.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: false
  tab_replace:
  
# Home page setting
# path: Root path for your blogs index page. (default = '')
# per_page: Posts displayed per page. (0 = disable pagination)
# order_by: Posts order. (Order by date descending by default)
index_generator:
  path: ''
  per_page: 10
  order_by: -date
  
# 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: yilia************

# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
  type: git
  repository: https://github.com/chenxiningxing6.github.io.git
  branch: master

jsonContent:
 meta: false
 pages: false
 posts:
    title: true
    date: true
    path: true
    text: false
    raw: false
    content: false
    slug: false
    updated: false
    comments: false
    link: false
    permalink: false
    excerpt: false
    categories: false
    tags: true


绑定个人域名:

1.Github端

/blog/themes/landscape/source目录下新建文件名为:CNAME文件,注意没有后缀名!直接将自己的域名如:muyunyun.cn写入。

2.域名解析

如果将域名指向一个域名,实现与被指向域名相同的访问效果,需要增加CNAME记录。登录万网,在你购买的域名后边点击:解析 --> 添加解析

记录类型:CNAME

 主机记录:将域名解析为example.com(不带www),填写@或者不填写

记录值:MuYunyun.github.io. (不要忘记最后的.

github pages虽然免费,但毕竟是国外的服务器,国内访问可以稍微缓慢,如果可以的话,可去买一个支持Node.js的国内云空间即可。

========================================================

                                                          前方高能

========================================================

执行hexo命令

  • hexo clean (清空资源文件,可选操作)
  • hexo g(重新生成资源文件)
  • hexo server(本地发布文章)
  • 本地发布后查看效果:http://localhost:4000/
  • hexo deploy(发布文章到github.io)
  • 输入github账号,密码
  • 查看远程效果

1.hexo写文章

hexo new "postName"

名为postName.md的文件会建在目录/blog/source/_posts下。

文章编辑完成后,终端cd到blog文件夹下,执行如下命令来发布: 

hexo generate             //生成静态页面
hexo deploy            //将文章部署到Github
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值