Hexo + GitHub Pagesphp
E:\Blog\themes\next
中)
E:\Blog\themes\next\languages
中)
红框中应为中文关于
而非英文bout
html
黄框译文node
键是菜单项名称,区分大小写。语言文件中找到该菜单译文则加载译文;无则用键名。
复制代码
绿框中bout与about不对应致使语言文件中找不到该菜单译文,从而显示键名bout
而非关于
。 git
改绿框中bout为about github
<!--more-->
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
Hexo评论页官方推荐disqus,无奈被墙。这里用第三方实现,对比:npm
安装
E:\Blog\themes\next
中)中找到以下片断:
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
注释掉便可 json
npm install --save hexo-tag-aplayer
装插件aplayer(音频)Plugins
npm install hexo-tag-dplayer --save
装插件dplayer(视频)Plugins
{% aplayerlist %}
{
"narrow": false, //(可选)播放器袖珍风格
"autoplay": true, //(可选)自动播放,移动端浏览器暂不支持此功能
"mode": "random", //(可选)曲目循环类型,有'random'(随机),'single'(单曲),'circulation'(循环),'order'(列表),默认'circulation'
"showlrc": 3, //(可选)歌词显示配置项,可选项一、二、3
"mutex": true, //(可选)该选项开启时,同页有其它aplayer播放则该播放器暂停
"theme": "#e6d0b2", //(可选)播放器风格色彩设置,默#b7daff
"preload": "metadata", //(可选)音乐文件预载入模式,可选项'none'、'metadata'、'auto',默'auto'
"listmaxheight": "513px", //(可选)该播放列表最大长度
"music": [
{
"title": "Sometimes When We Touch",
"author": "Oliveia",
"url": "https://molier-1256056152.cos.ap-guangzhou.myqcloud.com/SometimesWhenWeTouch.mp3",
"pic": "https://y.gtimg.cn/music/photo_new/T002R300x300M000003LIDEL0NQInJ.jpg?max_age=2592000",
"lrc": "https://歌词.lrc"
}
]
}
{% endaplayerlist %}
复制代码
pic即歌曲显示图片连接。建议歌词lrc用URL形式,txt格式编辑易出问题。歌曲下载后上传七牛云可在七牛云生成外链,七牛云有免费存储空间。但七牛云歌曲外链不支持https致配有ssl证书的掉绿锁,对该问题可弃七牛云,改腾讯云。浏览器
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
谷歌浏览器或Safari提示网站不被信任,点继续才可展现博客且地址栏显红色×。在此改博客协议为Https。缓存
因GitHub Pages不支持上传证书,故这里主介绍在国外CDN服务提供商Cloudflare基础上,经过CDN配置反向代理。 安全
Cloudflare提供DNS解析服务且速度很快,阿里云半小时解析生效在此瞬间生效。它提供免费https服务(非应用SSL证书)。实现模式即用户到CDN服务器链接为https,而CDN服务器到Github Pages服务器链接为http,即在CDN服务器处加反向代理。
官网注册后添域名(购买)
点DNS进解析界面
红框中开启云朵,否接下来没法正确配置
复制代码
上述骤操做完虽https且无红叉,但不显绿色小锁而是叹号。缘由为当前页有非https连接致使,如图片图床或评论插件不支持https,更换支持https图床或评论插件便可。
E:\Blog\themes\next
中)
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
hexo new page categories
新建categories页
分类
并设页面类型categories
,主题自动为该页显示全部分类title: 分类
date: 2018-03-14 18:21:16
type: "categories"
复制代码
启用多说或Disqus评论,默认页面也会带评论。关闭则添字段comments并设false title: 分类 date: 2018-03-14 18:21:16 type: "categories" comments: false
E:\Blog\themes\next
中),开启menu中categories: /categories/ || th
:menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
复制代码
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
hexo new page tags
新建tags页
标签
并设页面类型tags
,主题自动为该页显示全部分类title: 标签
date: 2018-03-16 10:32:43
type: "tags"
复制代码
启用多说或Disqus评论,默认页面也会带评论。关闭则添字段comments并设false title: 标签 date: 2018-03-14 18:21:16 type: "tags" comments: false
E:\Blog\themes\next
中),开启menu中tags: /tags/ || tags
:menu:
home: / || home
about: /about/ || user
tags: /tags/ || tags
categories: /categories/ || th
archives: /archives/ || archive
#schedule: /schedule/ || calendar
#sitemap: /sitemap.xml || sitemap
#commonweal: /404/ || heartbeat
复制代码
hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
Hexo流程即git工做流程,不论GitHub仍是BitBucket都遵循GitFlow。GitFlow即多终端多人协同工做解决方案,故用它实现多终端同步。
.
├── .deploy #需部署的文件
├── node_modules #Hexo插件
├── public #生成的静态网页文件
├── scaffolds #模板
├── source #博客正文和其它源文件,40四、favicon、CNAME都应放这里
| ├── _drafts #草稿
| └── _posts #文章
├── themes #主题
├── _config.yml #全局配置文件
└── package.json
复制代码
hexo g
source文件夹存放文章、tag、归档等信息,即博客内容。终端执行hexo g
时被source中文件按某种规则方式渲染成静态页面文件放到public中:
hexo d
将public中文件push到git仓库hexo clean
同gitflow无关,清理缓存。运行前首先删除public文件,而后执行hexo g
从新渲染进public,以后hexo d
进行部署。这样即避免以前内容对咱们形成影响。hexo s
生成的本地服务器进程中止,不便边写边预览。/.deploy_git
,/public
,一个一行
/.deploy_git
/public
复制代码
git init
初始化本地仓库
git remote add origin git@github.com:xxx/xxx.github.io.git
git add .
添加全部本地文件到git
.
(不包含.gitignore
声明文件)git commit -m "更新说明"
git提交
git branch hexo
新建分支hexo
git checkout hexo
切换分支为hexo
git push origin hexo
推送到远程仓库hexo分支
假设B电脑无源文件
git clone -b git@github.com:xxx/xxx.github.io.git hexo
克隆hexo分支到本地npm install
安装依赖,再也不初始化(hexo init
)git init
git remote add origin git@github.com:xxx/xxx.github.io.git
git fetch --all
git reset --hard origin/master
git init
初始化本地仓库
git pull git@github.com:xxx/xxx.github.io.git hexo
拉取远程仓库hexo分支
hexo new post “xxx”
建立博客git add source
添加source文件夹到本地git(仅source文件夹变更)
git commit -m "多终端同步更新博客"
)
git push origin hexo
推送到远程仓库hexo分支
hexo g -d
或hexo g
->hexo d -g
->hexo s
或hexo clean
->hexo g
->hexo d -g
->hexo s
部署Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git pull git@github.com:snpmyn/snpmyn.github.io.git hexo
From github.com:snpmyn/snpmyn.github.io
* branch hexo -> FETCH_HEAD
Already up to date.
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git add source
warning: LF will be replaced by CRLF in source/_posts/博客搭建.md.
The file will have its original line endings in your working directory.
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git commit -m "fifth"
[hexo 305cf46] fifth
1 file changed, 34 insertions(+)
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git push origin hexo
Username for 'https://github.com': snpmyn
muyang541527remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/snpmyn/snpmyn.github.io.git/'
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ muyang541527
bash: muyang541527: command not found
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ git push origin hexo
Username for 'https://github.com': snpmyn
Counting objects: 5, done.
Delta compression using up to 4 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 1.02 KiB | 1.02 MiB/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Resolving deltas: 100% (2/2), completed with 2 local objects.
To https://github.com/snpmyn/snpmyn.github.io.git
da365d3..305cf46 hexo -> hexo
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ hexo clean
INFO Deleted database.
INFO Deleted public folder.
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$ hexo g -d
INFO Start processing
WARN ===============================================================
WARN ========================= ATTENTION! ==========================
WARN ===============================================================
WARN NexT repository is moving here: https://github.com/theme-next
WARN ===============================================================
WARN It's rebase to v6.0.0 and future maintenance will resume there WARN =============================================================== INFO Files loaded in 5.59 s INFO Generated: CNAME INFO Generated: index.html INFO Generated: categories/index.html INFO Generated: archives/index.html INFO Generated: images/cc-by-nc.svg INFO Generated: images/quote-l.svg INFO Generated: archives/2018/03/index.html INFO Generated: images/cc-by-sa.svg INFO Generated: archives/2018/index.html INFO Generated: categories/工具/index.html warning: LF will be replaced by CRLF in 2018/03/06/博客搭建/index.html. The file will have its original line endings in your working directory. [master d519607] Site updated: 2018-03-16 09:47:01 2 files changed, 11 insertions(+), 7 deletions(-) Branch 'master' set up to track remote branch 'master' from 'git@github.com:snpmyn/snpmyn.github.io.git'. To github.com:snpmyn/snpmyn.github.io.git cb58169..d519607 HEAD -> master INFO Deploy done: git Administrator@LKKJ0004 MINGW64 /e/Blog (hexo) $ hexo s INFO Start processing WARN =============================================================== WARN ========================= ATTENTION! ========================== WARN =============================================================== WARN NexT repository is moving here: https://github.com/theme-next WARN =============================================================== WARN It's rebase to v6.0.0 and future maintenance will resume there
WARN ===============================================================
INFO Hexo is running at http://localhost:4000/. Press Ctrl+C to stop.
INFO Bye!
Administrator@LKKJ0004 MINGW64 /e/Blog (hexo)
$
复制代码
SEO(Search Engine Optimization)译为搜索引擎优化,即利用搜索引擎搜索规则提升目前网站在有关搜索引擎内天然排名。常见如网站结构调整、网站内容建设、网站代码优化及站外优化。
搜索引擎输入site:<域名>
,以下则代表网站没被百度收录。
layout:false
,便可不被hexo编译。(验证文件txt格式不须要)用npm自动生成sitemap(站点地图)后提交sitemap到百度和其它搜索引擎。
npm install hexo-generator-sitemap --save
npm install hexo-generator-baidu-sitemap --save
复制代码
E:\Blog
中)改url为站点地址
E:\Blog
中)添以下代码# 自动生成sitemap
sitemap:
path: sitemap.xml
baidusitemap:
path: baidusitemap.xml
复制代码
hexo g
执行构建,正常状况E:\Blog\public
下多出两文件
通常主动提交比手动提交效果好,从效率上讲:
主动推送>自动推送>sitemap
复制代码
npm install hexo-baidu-url-submit --save
安装插件
E:\Blog
中)新增字段baidu_url_submit
E:\Blog
中)加入新deploye
hexo g -d
或hexo g
->hexo d -g
或hexo clean
->hexo g
->hexo d -g
提交并推送E:\Blog\public
中生成baidu_urls
文件
网站全部权验证
添加域名不对照
网站全部权验证
重复操做,添加网站改www.muyang.site
为muyang.site
。主题配置文件 _config.yml(E:\Blog\themes\next
中)设baidu_push为true:
<script>
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https') {
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else {
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>
复制代码
提交sitemap文件到百度
两天后登陆百度站长平台,提示以下
一周后搜索引擎输入site:<域名>
或域名
,以下代表网站已经被百度收录。