先来看一下我搭建的博客: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.pub
或id_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_rsa
和id_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