Hexo关联github

接上一篇: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

  • 1
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值