程序员Android知识Android Other

基于github和hexo搭建博客----github配置

2017-08-12  本文已影响55人  柨柨

注册账号

https://github.com/

image.png
输入账号、邮箱、密码,然后点击注册按钮.然后去验证下邮箱

创建页面仓库

这个仓库的名字需要和你的账号对应,格式: yourname.github.io

image.png image.png
创建之后在浏览器中输入yourname.github.io,比如我的https://songlma.github.io image.png

备注:只有你仓库名称安装对应格式才可以直接通过 yourname.github.io访问,当然如果你打算用自己的域名绑定github的话,这个仓库名称就随便了,后面会讲到怎么绑定个人域名。

接下来就要把本地的hexo与github关联起来。

生成SSH文件
github是通过配置ssh来验证身份的。至于什么是ssh,不知道的大家自行百度吧。
先检验电脑中是否有ssh:

 ls -al ~/.ssh

如果有文件id_rsa.pub或id_dsa.pub,将SSH key添加到Github中。没有的就先生成

执行如下命令生成public/private rsa key pair,注意将your_email@example.com换成你自己注册Github的邮箱地址。

ssh-keygen -t rsa -C "your_email@example.com"

按 3 个回车,密码为空。

ssh文件地址:
windows: C:\Users\Administrator.ssh 下,得到两个文件 id_rsa 和 id_rsa.pub。

关于配置多个ssh文件请参考同一个Mac,配置多个SSH Key
mac:Find前往文件夹~/.ssh/id_rsa.pub
在 GitHub 上添加 SSH 密钥
打开id_rsa.pub文件,里面的信息即为SSH key,将这些信息复制到Github的Add SSH key页面即可。

Hexo配置

目录结构

├── .deploy       #需要部署的文件
├── node_modules  #Hexo插件
├── public        #生成的静态网页文件
├── scaffolds     #模板
├── source        #博客正文和其他源文件,404、favicon、CNAME 都应该放在这里
|   ├── _drafts   #草稿
|   └── _posts    #文章
├── themes        #主题
├── _config.yml   #全局配置文件
└── package.json

全局配置 _config.yml

# Hexo Configuration
# Docs: http://hexo.io/docs/configuration.html
# Source: https://github.com/hexojs/hexo/
# Site #站点信息
title:  #标题
subtitle:  #副标题
description:  #站点描述,给搜索引擎看的
author:  #作者
email:  #电子邮箱
language: zh-CN #语言

.......

theme: landscape-plus #主题
exclude_generator:
plugins: #插件,例如生成 RSS 和站点地图的
- hexo-generator-feed
- hexo-generator-sitemap
# Deployment #部署,将 lmintlcx 改成用户名
deploy:
  type: git
  repo: 刚刚github创库地址.git
  branch: master

注意:
配置文件的冒号“:”后面有一个空格
repo: 刚刚 GitHub 创库地址.git
type:值为git。


image.png
deploy:
   type: git
  repo: https://github.com/songlma/songlma.github.io.git
  branch: master

hexo命令行使用

hexo help #查看帮助
hexo init #初始化一个目录
hexo new "postName" #新建文章
hexo new page "pageName" #新建页面
hexo generate #生成网页,可以在 public 目录查看整个网站的文件
hexo server #本地预览,'Ctrl+C'关闭
hexo deploy #部署.deploy目录
hexo clean #清除缓存,**强烈建议每次执行命令前先清理缓存,每次部署前先删除 .deploy 文件夹**

简写

hexo n == hexo new
hexo g == hexo generate
hexo s == hexo server
hexo d == hexo deploy

hexo部署

执行下列指令即可完成部署。

hexo generate
hexo deploy

hexo deploy 问题:Deployer not found: git

npm install hexo-deployer-git --save

再重新 hexo deploy ,以下提示说明部署成功:

[info] Deploy done: git

代码就已经传到github上了

image.png

点击settings:往下拉到github pages

image.png

点击链接,就到了你的博客了,基础的搭建完成了。
接下来记录绑定个人域名,以及修改theme。

上一篇下一篇

猜你喜欢

热点阅读