前言
HELLO WORLD!
總結下
一直以来都没咋好好写过东西,学了蛮多东西,但是不总结感觉会忘记….
主题:基于Hexo与GitHub的个人博客搭建
一.基本工具
1.github账号。
2.安装node.js,npm。
3.安装git for windows。
二.github配置
1.创建github仓库
登录github,创建一个自己的用户名.github.io
的仓库。这个仓库名一定要是这要,后面网站访问地址就是https://你的用户名.github.io了。
2.配置SSH Key
1 | $ cd ~/. ssh #检查本机已存在的ssh密钥 |
如果提示:No such file or directory 说明需要配置一下。
1 | ssh-keygen -t rsa -C "邮件地址" |
然后连续3次回车,最终会生成一个文件在用户目录下,打开用户目录,找到.ssh\id_rsa.pub
文件,记事本打开并复制里面的内容,打开你的github主页,进入个人设置 -> SSH and GPG keys -> New SSH key
将刚复制的内容粘贴到key里,title随意起名。
2.1测试是否成功
1 | $ ssh -T git@github.com # 注意就这个地址不用改 |
如果提示Are you sure you want to continue connecting (yes/no)?
,输入yes,然后会看到
看到这个信息说明SSH已配置成功!
1 | //配置git账号,有小乌龟的话在小乌龟里可以配置 |
三.Hexo配置
1.hexo简介
Hexo是一个简单、快速、强大的基于 Github Pages 的博客发布工具,支持Markdown格式,有众多优秀插件和主题。
官网: http://hexo.io
github: https://github.com/hexojs/hexo
2.原理
我们将文件都存在github的某个仓库上,本地修改了文章,图片等等,hexo会将这些md文件都放在本地,每次写完文章后调用写好的命令来批量完成相关页面的生成,然后再将有改动的页面提交到github。
3.安装hexo
1 | npm install hexo -g #安装hexo |
在电脑任意一个位置创建一个目录用于存放代码位置,如D:\WorkSpace\hexo
1 | cd /f/Workspaces/hexo/ |
再启动hexo
1 | hexo g # 生成html文件 |
执行以上命令之后,hexo就会在public文件夹生成相关html文件,这些文件将来都是要提交到github去的。
hexo s
是开启本地预览服务,打开浏览器访问 http://localhost:4000 即可看到内容。
4.修改主题
先给出官方主题,再推荐一个主题:hexo-theme-yilia。
首先下载这个主题:
1 | cd /f/Workspaces/hexo/ |
再修改_config.yml
中的theme: landscape
改为theme: yilia
,然后重新执行hexo s -g
来重新生成和预览。
四.上传github
配置_config.yml
中有关deploy的部分:
正确写法:
1 | deploy: |
注意:首单词冒号后面有空格。
还要安装一个插件:
npm install hexo-deployer-git --save
用于辅助hexo -d命令
到此就可以使用hexo -d
提交到github了。
注意:其它命令不确定,部署这个命令一定要在git bash里,否则会提示Permission denied (publickey).
打开你的git bash
,输入hexo d
就会将本次有改动的代码全部提交,没有改动的不会。
这时你就可以通过默认的 用户名.github.io
来访问了。
五.写博客
定位到hexo根目录,运行命令:
hexo new 'my-first-blog'
即可在posts文件夹下生成相关md文件,我们打开这个md文件书写就可以了。
title: postName #文章页面上的显示名称,一般是中文
date: 2013-12-02 15:30:16 #文章生成时间,一般不改,当然也可以任意修改
categories: 默认分类 #分类
tags: [tag1,tag2,tag3] #文章标签,可空,多标签请用格式,注意:后面有个空格description: 附加一段文章摘要,字数最好在140字以内,会出现在meta的description里面
补充hexo命令
:
1 | hexo的常见命令: |
六.参考文章
https://www.cnblogs.com/liuxianan/p/build-blog-website-by-hexo-github.html
七.重装系统后
npm i
npm install -g hexo
这时就可以正常
hexo s
预览了,hexo g
生成了。但是
hexo d
提交会出错The file will have its original line endings in your working directory
缓存问题
进入
D:\WorkSpace\hexo\.deploy_git
执行git rm -r --cached .
清楚缓存。// 提交时转换为LF,检出时转换为CRLF git config --global core.autocrlf true // 提交时转换为LF,检出时不转换 git config --global core.autocrlf input // 提交检出均不转换 git config --global core.autocrlf false
The authenticity of host 'github.com (13.250.177.223)' can't be established. RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8. Are you sure you want to continue connecting (yes/no/[fingerprint])? yes Warning: Permanently added 'github.com,13.250.177.223' (RSA) to the list of known hosts. Connection reset by 13.250.177.223 port 22 fatal: Could not read from remote repository.1
2
-
Please make sure you have the correct access rights
and the repository exists.1
2
3
4
5
6
7
8
9
- 错误原因,本地SSH与远端不一致。
- 查看本地有没有,有则把这个ssh添加到github上。没有则通过`ssh-keygen -t rsa -C "邮件地址"`生成。
- 本地仓库与远程仓库建立连接命令
`git remote add orgin git@github.com:xxx`
-$ hexo d
(node:6384) Warning: Accessing non-existent property ‘lineno’ of module exports inside circular dependency
(Usenode --trace-warnings ...
to show where the warning was created)
(node:6384) Warning: Accessing non-existent property ‘column’ of module exports inside circular dependency
(node:6384) Warning: Accessing non-existent property ‘filename’ of module exports inside circular dependency
(node:6384) Warning: Accessing non-existent property ‘lineno’ of module exports inside circular dependency
(node:6384) Warning: Accessing non-existent property ‘column’ of module exports inside circular dependency
(node:6384) Warning: Accessing non-existent property ‘filename’ of module exports inside circular dependency
INFO Deploying: git
INFO Clearing .deploy_git folder…
INFO Copying files from public folder…
FATAL Something’s wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
TypeError [ERR_INVALID_ARG_TYPE]: The “mode” argument must be integer. Received an instance of Objectat copyFile (fs.js:1972:10) at tryCatcher
参考链接:https://zhuanlan.zhihu.com/p/136552969
//敏感内容前加上这个 Hello {{ sensitive }} l/敏感内容被包装在中间 //敏感内容后加上这个1
2
3
4
5
6
7
8
9
10
11
12
错误原因:node版本太高,切换成低版本的node来安装Hexo就可以了。
解决办法:目前是node14,使用nvm多装了一个node12来提交
- 报错一
> FATAL Something's wrong. Maybe you can find the solution here: https://hexo.io/docs/troubleshooting.html
> Nunjucks Error: [Line 344, Column 63] unexpected token: }}
转义内容 Hexo使用Nunjucks渲染帖子(较早的版本使用Swig,它们具有相似的语法)。用{ { } }或{ % % }包装的内容将被解析,并可能导致问题。您可以使用原始标签插件包装敏感内容。
找到正文里面{ {、} }、{ %、% }这样的语句,作如下修改:参考链接:https://blog.csdn.net/weixin_45333934/article/details/108274320