接上一篇:https://blog.csdn.net/weixin_44897792/article/details/90796152
首先保证之前的环境已经搭建好,输入localhost:4000能够访问;
一、生成SSH秘钥:
ls ~/. ssh/ #检查本机已存在的ssh密钥
1、-C后面跟上GitHub的用户名邮箱,这样公钥才会被GitHub认可;
此时可以看到.ssh目录下有一个公钥和一个私钥:
2、查看公钥内容,将内容加到GitHub的sshkey中:
less ~/.ssh/id_github.pub
登陆GitHub在设置中找到SSH and GPG keys添加公钥:
测试是否成功:
ssh -T git@github.com # 注意邮箱地址不用改
如果提示:Are you sure you want to continue connecting (yes/no)?
输入yes
返回:Hi jfxuan! You’ve successfully authenticated, but GitHub does not provide shell access.
看到这个信息说明SSH已配置成功!
二、创建博客项目:
新建:
项目名称为 用户名.github.io ,假如我的Github用户名是jfxuan.github.io,则创建的项目名为 jfxuan.github.io ,选择public公开:
三、登陆GitHub:
四、配置hexo:
编辑 _config.yml文件
这里面都是一些全局配置,每个参数的意思都比较简单明了;
需要特别注意的地方是,冒号后面必须有一个空格,否则可能会出问题;
# Deployment
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo: git@github.com:jfxuan/jfxuan.github.io.git
branch: master
repo就是GitHub上面创建的博客项目;
repo后面填写的一定要和GitHub存储库上面的相吻合:
编译,上传静态代码:
# 编译
hexo generate //可以简写 hexo g
# 在主机的hexo目录下 执行以下命令将自动更新到Github
hexo d //可以简写 hexo d
如果hexo d出现报错:“ERROR Deployer not found: git”
npm install --save hexo-deployer-git
此时再次执行hexo d
浏览器访问:
博客的网站就是:jfxuan.github.io
默认主题不太好看,可以去官方找些好看的:
hexo主题网址https://hexo.io/themes/
下面举例替换一个主题:
首先进入到themes目录下,下之后可以把名字改一下;
[root@10-23-230-201 themes]# pwd
/home/jf_blog/themes
[root@10-23-230-201 themes]# git clone https://github.com/litten/hexo-theme-yilia.git
Cloning into 'hexo-theme-yilia'...
remote: Enumerating objects: 2037, done.
remote: Total 2037 (delta 0), reused 0 (delta 0), pack-reused 2037
Receiving objects: 100% (2037/2037), 10.52 MiB | 3.55 MiB/s, done.
Resolving deltas: 100% (1092/1092), done.
[root@10-23-230-201 themes]# ll
total 8
drwxr-xr-x 7 root root 4096 Jun 5 18:06 hexo-theme-yilia
drwxr-xr-x 6 root root 4096 Jun 5 15:18 landscape
[root@10-23-230-201 themes]# mv hexo-theme-yilia/ yilia
修改_config.yml中的theme: landscape改为theme: yilia,然后重新执行hexo g来重新生成;
如果出现一些莫名其妙的问题,可以先执行hexo clean来清理一下public的内容,然后再来重新生成和发布;
在上传代码到github之前,先把之前的代码备份,因为从hexo提交代码时会把你以前的所有代码都删掉;
[root@10-23-230-201 jf_blog]# pwd
/home/jf_blog
[root@10-23-230-201 jf_blog]# ls
_config.yml db.json node_modules package.json package-lock.json public scaffolds source themes
[root@10-23-230-201 jf_blog]# vi _config.yml
[root@10-23-230-201 jf_blog]# hexo clean
INFO Deleted database.
INFO Deleted public folder.
[root@10-23-230-201 jf_blog]# hexo g
[root@10-23-230-201 jf_blog]# hexo d
浏览器再次访问:
常用的hexo命令:
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成静态页面至public目录
hexo server #开启预览访问端口(默认端口4000,'ctrl + c'关闭server)
hexo deploy #部署到GitHub
hexo help # 查看帮助
hexo version #查看Hexo的版本
缩写:
hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy
组合命令:
hexo s -g #生成并本地预览
hexo d -g #生成并上传
_config.yml配置文件大致介绍:
# Hexo Configuration
## Docs: https://hexo.io/docs/configuration.html
## Source: https://github.com/hexojs/hexo/
# Site 站点信息设置
title: #站名
subtitle: #副标题
description: #站描述
author: #作者
language: zh-CN #语言
timezone:
# URL 链接设置
## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/'
url: http://www.lookk.cn
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: true
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: 5
pagination_dir: page
# Extensions 扩展
## Plugins: https://hexo.io/plugins/
## Themes: https://hexo.io/themes/
theme: yilia
# Deployment 这里设置了Git
## Docs: https://hexo.io/docs/deployment.html
deploy:
type: git
repo:
branch: master
参考:
https://www.cnblogs.com/liuxianan/p/build-blog-website-by-hexo-github.html