title: 0.Hexo+GetHub搭建博客系统 date: 2020-03-21 19:10:47 categories:
3.系统运维3.hexo相关1.hexo美化配置环境
系统:win10+Node.js+Git
博客系统:Hexo+next
书写系统:Typora+PicGo+腾讯云Cos
Node.js:https://nodejs.org/en/download/
Git:https://git-scm.com/downloads
这两款软件属于傻瓜式安装,注意修改安装地址即可,在此不做过多叙述
Win+R打开运行窗口输入cmd,执行命令下载hexo系统:
npm install hexo-cli -g切换到准备放博客的目录,创建博客:
hexo init //hexo初始化 hexo g //hexo更新本地缓存 hexo s //hexo本地预览在本地浏览器输入http://localhost:4000/
Github官网:www.github.com,自行注册账号
注册完账号后右上角有一个加号,点开新建一个仓库
设置仓库名为账号名.github.io
点击Create repository完成创建
SSH秘钥默认储存在账户的主目录下的~/.ssh目录
如:C:\Users\kinght.ssh\
查看是否包含id_rsa和id_rsa.pub(或者是id_dsa和id_dsa.pub之类成对的文件),有.pub后缀的文件就是公钥,另一个文件则是密钥。如果有这两个文件,则跳过1.2;如果没有这两个文件,甚至.ssh目录也没有,则需要用ssh-keygen来创建
ssh-keygen -t rsa -C "邮箱"连续几个回车之后就会如图所示,在.ssh文件夹中出现了两个文件
回到github官网,找到自己的头像进入settings
SSH and GPG keys -> SSH keys -> New SSH key
回到本地的ssh文件,用记事本打开id_rsa.pub文件,复制里面内容填写到密钥框里
Title随意填,把id_rsa.pub文件,复制里面内容填写到Key框里,点击Add SSH key保存
为了使用github的免费静态空间,我们需要把Hexo生成的静态页面上传到github供我们访问,在这之前,需要使用hexo-deployer-git插件
npm install hexo-deployer-git --savehexo的主配置文件为hexo根目录下_config文件
编辑打开这个文件,在文件最后找到Deplyment代码修改为
# Deployment ## Docs: https://hexo.io/docs/deployment.html deploy: - type: git repository: git@github.com:kinghtxg/kinghtxg.github.io.git branch: master将repository那一栏修改为自己仓库的ssh传输地址
在项目仓库切换到Settings
鼠标滚轮下翻,修改Pages为master branch如图(这里在创建空间命名时有点小问题,如果直接为kinghtxg.github.io则访问域名直接为kinghtxg.github.io)
访问测试
同样修改_config文件,我在我做了修改处的后面打上了备注,按需修改
# Hexo Configuration ## Docs: https://hexo.io/docs/configuration.html ## Source: https://github.com/hexojs/hexo/ # Site title: Kinght's blog #博客名 subtitle: 记录一些杂七杂八的笔记 #小标题 description: '' keywords: author: Kinght #作者 language: zh-Hans #中文 timezone: Asia/Shanghai #时区上海 # URL ## If your site is put in a subdirectory, set url as 'http://yoursite.com/child' and root as '/child/' url: http://yoursite.com #网址 root: / permalink: archives/:title.html #修改链接格式 permalink_defaults: pretty_urls: trailing_index: true # Set to false to remove trailing 'index.html' from permalinks trailing_html: true # Set to false to remove trailing '.html' from permalinkscmd窗口进行配置文件更新
hexo clean //清除文件 hexo g //更新缓存 hexo d //上传稍等几分钟(github page更新需要时间)