By Git Pages + Hexo build your own blog

First, the application and configure Github Pages

step1 create a git repository on github

With github account login https://github.com/, no github account as you apply for a github account. After login, click "New repository" new one called username.github.io (username is your github username) as I was: xiejava1018.github.io, if the library name will be reported and the existence of the library name already exists error .
New Library

step2 bind your own domain name (if not their own domain name may not be tied)

Just apply for access to the git repository, click on Settings
Settings
if the library name is not username.github.io (username is your github username) here can be modified to username.github.io
Modify the library name
drag can be seen below information GitHub Pages, if not bind their own domain name can actually access your site through https://username.github.io/.
Site address
If you have to apply your own domain name, the domain name can be resolved to your GithubPages username.github.io as I was xiejava1018.github.io
Resolve a custom domain name
after just enter resolved at GitHub Pages custom domain name Custom domain in the domain name can be seen save your site is published to your domain name, such as the https://xiejavablog.ishareread.com/
Binding a custom domain name
this time you can use your own domain name to access the site GitHub pages, but now nothing, only a blank page . This requires that we help Hexo this static site generation tools afterlife of the content of our site.

Second, the installation site and generate Hexo

Installation Hexo and build a site can refer to the official documentation https://hexo.io/zh-cn/docs/

1, pre-installation preparation

安装 Hexo 相当简单,只需要先安装下列应用程序即可:
Node.js (Node.js 版本需不低于 8.10,建议使用 Node.js 10.0 及以上版本)
Git

2、安装Hexo

所有必备的应用程序安装完成后,即可使用 npm 安装 Hexo。

$ npm install -g hexo-cli

安装完了以后可以通过hexo version 查看相应的版本
Version Information

3、生成站点

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

$ hexo init <folder>
$ cd <folder>
$ npm install

新建完成后,指定文件夹的目录如下:
table of Contents
其中_config.yml 文件是网站的配置文件
package.json 是应用程序的信息
scaffolds
模版文件夹。当新建文章时,Hexo 会根据 scaffold 来建立文件。
Hexo的模板是指在新建的文章文件中默认填充的内容。例如,如果您修改scaffold/post.md中的Front-matter内容,那么每次新建一篇文章时都会包含这个修改。
source
资源文件夹是存放用户资源的地方。除 _posts 文件夹之外,开头命名为 _ (下划线)的文件 / 文件夹和隐藏的文件将会被忽略。Markdown 和 HTML 文件会被解析并放到 public 文件夹,而其他文件会被拷贝过去。
themes
主题 文件夹。Hexo 会根据主题来生成静态页面。

4、安装主题

Hexo提供了很多主题,我用的是hexo-theme-next主题,大家可以直接克隆我的主题https://github.com/xiejava1018/hexo-theme-next.git 这里修复了一些bug如乱码问题等。
cd 切换到站点目录下

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

也可以用其他git客户端工具将主题拉取到themes目录下
修改_config.yml文件的theme改为

theme : hexo-theme-next

5、写作

可以执行下列命令来创建一篇新文章或者新的页面。

$ hexo new [layout] <title>

可以在命令中指定文章的布局(layout),默认为 post,可以通过修改 _config.yml 中的 default_layout 参数来指定默认布局。
如执行:

hexo new 2020-02-11-2020-02-11-看完全套149本《书虫》是种什么样的体验

执行该命令后就会在响应的站点目录的source_posts下生成2020-02-11-看完全套149本《书虫》是种什么样的体验.md文件。
file
用任何喜欢的编辑器编辑这个.md文件即可,排版是支持MarkDown的。

6、生成和发布

编辑好需要发表的内容后。执行

$ hexo generate

就会生成相应的静态文件。改命令也可以简写成

$ hexo g

执行

$ hexo server

启动服务器。默认情况下,访问网址为: http://localhost:4000/ 就可以通过该地址访问本地的站点。
在本地检查没有问题以后就可以发布到Github Pages上通过互联网上访问了。
首先在配置_config.yml文件配置需要发布的地址。这个地址就是你在github上申请的Github Pages库的git地址
Published address configuration
然后就可以通过命令

$ hexo deploy

进行发布了。发布以后就可以通过https://xiejava1018.github.io 或者自定义的域名 https://xiejavablog.ishareread.com 来访问了。需要注意的是,每次重新发布以后,需要重新设置域名绑定才能正确访问,否则会报404的错误。

欢迎大家访问我的BLOG https://xiejavablog.ishareread.com/

Published 58 original articles · won praise 31 · Views 460,000 +

Guess you like

Origin blog.csdn.net/fullbug/article/details/104279254