

再次折腾hexo
source link: https://www.bmqy.net/2649.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

再一次开始折腾hexo
了,为了省下高昂的服务器费用,为了利用上永久的虚拟主机。
只不过可惜的是虚拟主机不能支持https,所以无奈使用了COS
。
还有一点就是用markdown
写文章感觉确实不错,再加上github action
加持,hexo
用起来感觉也是相当不错的.
而且服务器的话WordPress
还要考虑一堆的性能优化问题,静态博客就完全不用担心了。
下面简单记录下hexo
的部署配置问题。
Hexo配置
固定ID推荐使用hexo-abbrlink2
- Add plugin to Hexo:
npm install hexo-abbrlink2 --save
- Modify permalink in
config.yml
file:permalink: posts/:abbrlink/
- optional settings:
abbrlink:
start: 1000 # the first id, default 0
# Directory
source_dir: source
在引用图片时通过路径/images/image.jpg
,引入图片资源
Next配置
创建标签云
默认无标签页,打开链接会404
创建标签页:
hexo new page tags
---
date: 2021-08-04 13:22:27
type: "tags"
---
创建分类页
默认无分类页,打开链接会404
创建分类页:
hexo new page categories
---
date: 2021-08-04 13:22:33
type: "categories"
---
自定义样式
```
custom_file_path:
#head: source/_data/head.njk
#header: source/_data/header.njk
#sidebar: source/_data/sidebar.njk
#postMeta: source/_data/post-meta.njk
#postBodyEnd: source/_data/post-body-end.njk
#footer: source/_data/footer.njk
#bodyEnd: source/_data/body-end.njk
#variable: source/_data/variables.styl
#mixin: source/_data/mixins.styl
style: source/_data/styles.styl
添加备案号
footer:
# Beian ICP and gongan information for Chinese users. See: https://beian.miit.gov.cn, http://www.beian.gov.cn
beian:
enable: true
icp: xxxxxx
自动化部署
- Installation
npm install hexo-deployer-cos --save
- Options
You can configure in _config.yml as follows:deploy:
type: cos
secretId: yourSecretId
secretKey: yourSecretKey
bucket: yourBucket
region: yourRegionFor projects that use pipelines, you may not want to expose COS properties in the project file, so we support getting them through environment variables.
COS_SECRET_ID=yourSecretId
COS_SECRET_KEY=yourSecretKey
COS_BUCKET=yourBucket
COS_REGION=yourRegionEnvironment variables have lower priority than _config.xml configuration
FTPSync
- Install hexo-deployer-ftpsync.
npm install hexo-deployer-ftpsync --save
- Edit settings.
deploy:
type: ftpsync
host: <host>
user: <user>
pass: <password>
remote: [remote]
port: [port]
ignore: [ignore]
connections: [connections]
verbose: [true|false]
文章更新时间设置:
updated_option
updated_option 控制了当 Front Matter 中没有指定 updated 时,updated 如何取值:
mtime: 使用文件的最后修改时间。这是从 Hexo 3.0.0 开始的默认行为。
date: 使用 date 作为 updated 的值。可被用于 Git 工作流之中,因为使用 Git 管理站点时,文件的最后修改日期常常会发生改变
empty: 直接删除 updated。使用这一选项可能会导致大部分主题和插件无法正常工作。
use_date_for_updated 选项已经被废弃,将会在下个重大版本发布时去除。请改为使用 updated_option: ‘date’。
CDN缓存刷新
该方案参考自:https://segmentfault.com/a/1190000039707833
腾讯云官方给我们提供了一个解决方案,可以在COS存储桶的函数计算->CDN缓存刷新函数中配置一个函数,参考截图:
但这个方案存在一个问题,由于我们的静态网站有默认索引页面index.html,而官方提供的这个函数只会刷新对应的文件的URL,而不会刷新索引URL,例如http://www.bytelife.net/index.html这个文件,通常我们的请求是http://www.bytelife.net/,因此官方的方案针对于静态网站来说不算完美。
优化方案
可以通过简单修改官方的函数来解决这个问题,点击刚刚创建的CDN缓存刷新函数列表中的函数名称,将index.js文件内容替换为下面的代码,最后点击右上角的“部署”按钮即可:
/* eslint-disable no-param-reassign */
'use strict';
const TimeoutWatcher = require('./common/TimeoutWatcher');
const CosCdnRefreshTask = require('./common/CosCdnRefreshTask');
const { getParams, logger, getLogSummary } = require('./common/utils');
exports.main_handler = async (event, context) => {
/**
* set a timer to terminate the cdn refresh task, ensure log message is printed
*/
let runningTask;
const watcher = new TimeoutWatcher({
timeLimit: context.time_limit_in_ms,
trigger(error) {
if (runningTask && runningTask.cancelTask) {
runningTask.cancelTask(error);
}
},
error: new Error('task is timeout'),
});
logger({
title: 'param as follow: ',
data: { event },
});
/**
* parse param from event and process.env
*/
const { secretId, secretKey, token, objects, triggerType, cdnHosts } = getParams(event);
logger({
title: 'param is parsed success',
});
const taskResults = [];
const task = new CosCdnRefreshTask({
secretId,
secretKey,
token,
objects,
triggerType,
cdnHosts,
});
if (watcher.isTimeout()) {
// if current is timeout, trigger the cancel task in next tick
process.nextTick(() => task.cancelTask(watcher.error));
} else {
runningTask = task;
}
const results = await task.runTask();
results.forEach(item => {
taskResults.push(item)
// 如果以 /index.html 结尾,则增加目录首页/
// 例如 https://www.xxxx.com/index.html, 则增加 https://www.xxxx.com/
if(item.params.urls[0].lastIndexOf('/index.html') == (item.params.urls[0].length - 11)){
taskResults.push(item.substr(0, item.length - 10))
}
});
watcher.clear();
logger({
title: 'cos cdn refresh full logs:',
data: taskResults,
});
const { status, messages } = getLogSummary({
name: 'cos cdn refresh',
results: taskResults,
});
logger({
messages: messages.map(item => item.replace(/, /g, '\n')),
});
context.callbackWaitsForEmptyEventLoop = false;
if (status === 'fail') {
throw messages.join('; ');
} else {
return messages.join('; ');
}
};
Recommend
-
40
分享创造 - @SukkaW - # Suka ThemeModern · Powerful · Simple<
-
12
部署平台选型GitHub 和 Gitee(码云)是国内外比较流行的代码托管平台,现都推出 GitHub/Gitee Pages 可以存放静态网页代码,因此可以用来搭建自己的博客。 平台 优点 缺点 Github 全球最流行的平台,且免费 国内由于有墙,访问太慢 Gitee...
-
15
什么是 Hexo?Hexo 是一个快速、简洁且高效的博客框架。Hexo 使用 Markdown(或其他渲染引擎)解析文章,在几秒内,即可利用靓丽的主题生成静态网页。 Node.js 所带来的超快生成速度,让上百个页面在几秒内瞬间完成渲染。 Hexo 支...
-
11
上一篇文章介绍了 Emacs 的理念以及其强大的扩展功能,基本上能在 Emacs 里面做到事,我都在 Emacs 里面做。之前的博客一直都是用的 markdown 来书写,虽然 Emacs 也有 markdown 插件,但是总感觉体验不如 org-mode。这周末就趁着手热,把博客系统进行了升级,...
-
15
I do not know why exactly I am so stubborn to insist on making this site multilingual, and in a way that you may see multiple languages at the same time. But it is something. 我自己也不明白为什么我执拗得一定要把这网站做成多语言的,还是叫人 能...
-
4
我的hexo笔记 原创 编辑 ...
-
11
通过 Metaweblog API 给 Hexo 接入客户端Hexo 搭建静态博客的问题Hexo + GitHub Pages 搭建博客的方式已经非常流行了。但是 Hexo 的写作几乎必须在电脑上进行。在 Travis 等 CI 工具的支持下,可以通过在 GitHub 页面上新建文件,编写内容,...
-
17
一、Hexo Boot Hexo Boot 是基于 Spring Boot + MySQL 开发的一套开源的博客系统。前身是 ml-blog 博客系统,在此基础上演变和扩展而来。 二、扩展功能 Hexo Boot 博客系统除了继承 ml-blog 博客系统的文章管理、分类管理、系统参数设...
-
15
Table of Contents使用 Hexo 写博客是十分惬意的事。唯一有点不爽的,就是每次修改后都要重新生成并部署到 Github 上,这也是所有静态博客生成工具的通病。那么本文我们就利用 Trav...
-
7
wordpress学习 再次折腾,wordpress导航继续研究 2014-01-15 上一次稍微整理...
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK