惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Security Latest
Security Latest
C
CXSECURITY Database RSS Feed - CXSecurity.com
AI
AI
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
P
Palo Alto Networks Blog
Spread Privacy
Spread Privacy
Project Zero
Project Zero
Google Online Security Blog
Google Online Security Blog
The Cloudflare Blog
L
LangChain Blog
T
Tenable Blog
GbyAI
GbyAI
C
Cybersecurity and Infrastructure Security Agency CISA
大猫的无限游戏
大猫的无限游戏
Last Week in AI
Last Week in AI
量子位
Cloudbric
Cloudbric
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
美团技术团队
S
Secure Thoughts
P
Privacy & Cybersecurity Law Blog
S
Securelist
S
Schneier on Security
F
Full Disclosure
Engineering at Meta
Engineering at Meta
A
Arctic Wolf
Microsoft Security Blog
Microsoft Security Blog
Apple Machine Learning Research
Apple Machine Learning Research
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
爱范儿
爱范儿
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
P
Privacy International News Feed
宝玉的分享
宝玉的分享
A
About on SuperTechFans
博客园 - 【当耐特】
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Hugging Face - Blog
Hugging Face - Blog
Webroot Blog
Webroot Blog
Google DeepMind News
Google DeepMind News
H
Heimdal Security Blog
Y
Y Combinator Blog
月光博客
月光博客
H
Hacker News: Front Page
MongoDB | Blog
MongoDB | Blog
C
Check Point Blog
TaoSecurity Blog
TaoSecurity Blog
腾讯CDC
N
Netflix TechBlog - Medium

北门清燕

🎙️ 科技热文播报 - 2026-03-14 【vscode扩展】apis-tester Notion工具人bot VPS橱窗 - 一个简单的哪吒面板主题 ios17.0可以安装Trollstore了 windows服务器安装mysql踩坑指北 为哪吒面板增加视频背景 继续折腾astro serv00部署FreshRSS 【原创】油猴脚本:哪吒VPS橱窗后台脚本 哪吒面板终极进化之VPS橱窗 哪吒面板default主题小鸡底部增加购买同款按钮 Typecho二开魔改简单指北 【原创】油猴脚本:论坛快捷回帖 简单米表:Typecho-Simple-Mibiao Windows 11 23H2更新遇到下载错误解决方法 Microsoft 365 E5开发者订阅管理员双重认证丢失解决方法 Virtualbox安装Ubuntu不完全指北 一剑开天门 将chrome谷歌浏览器轻松打造成rss阅读器 地震云 罗刹海市 关于笑果我觉得还是罗翔老师说的好 推荐正在玩的游戏:SimpleMMO,附游戏助手SMMOHelper 集成Elog使用notion数据库 【原创】ios捷径:法定工作日打卡提醒 测试AI docker部署freshrss apifox自动导入apidoc接口数据 node项目部署到ftp vite项目使用tinymce插件axupimgs实现多图片上传 tomcat服务器上utf8编码的文件乱码解决方法 快捷指令:图床 七牛上传视频获取视频封面和缩略图 注销网站得慎重 【原创】ios捷径:捷径库 【原创】ios捷径:自动壁纸 【原创】ios捷径:倒班闹钟 idea找回执行git pull操作后,被覆盖的本地未提交的代码 altserver跳坑指北 吐一吐三丰云免费服务器 Microsoft Store中的应用软件如何备份数据 卖盘 利用frp实现微软远程桌面管理内网电脑之不完全指北 apicloud用tortoisesvn管理代码,实现按不同分支编译打包app vscode插件提示:command 'extension.updateSettings' not found解决方法 apicloud使用alipayplus支付宝支付模块注意事项 【原创】越狱插件安装注意事项 api.closeFrameGroup的一些注意事项 【原创】ios捷径:我的心愿单 【原创】ios捷径:一键获取urlscheme 【原创】ios捷径:一键签到 【原创】ios捷径:qq群一键签到 【原创】ios捷径:百度搜索风云榜2.1.0 【原创】ios捷径:一键天气预报 【原创】ios捷径:微博热搜榜2.0强势更新 ios捷径:bmqy捷径库 自定义IntelliJ IDEA配置和插件的存放目录,以方便同步idea配置 wordpress平台next主题 vscode本地调试asp ajaxFileUpload上传成功也执行error方法 更换回wordpress。。。 一键收取熊猫守护者威力值 vscode软件窗口标题栏显示文件完整路径 微信小程序“支付签名验证失败”问题的解决参考 “idea已连接上ftp但看不到文件”的解决办法 js格式化时间显示 js实现中文转换成拼音 h5移动端ios输入法软键盘导致fixed布局bug的解决方案 生命不息,折腾不止之“hexo” echarts中tooltips自定义数据结构与样式 淘米辅助工具 聚名网辅助工具 仿站制作6 wordpress新添加页面显示评论 华为mate8(b584)root过程简要记录 asp解析json的方法 为子主题增加主题选项功能 自制chrome扩展:百度云分享链接一键登录 清燕的云集小店 Google play下载app状态栏进度显示异常的应对方法 吐槽百度翻译之离线翻译包 现在只有人民才是真正的为人民 吐槽腾讯大王卡 wordpress添加twentysixteen子主题 idea配置less自动编译 使用chrome浏览器调试移动端web页面 idea编译less并使用autoprefixer sublime自动编译less2css插件,保存时提示系统找不到指定文件 吐一吐中信的升白金 Android手机下输入框获取焦点时, 输入法挡住输入框bug的解决方法 wordpress头像不显示解决方法 用子主题functions.php添加自定义功能后访问网站报错解决方法 ueditor百度编辑器添加自定义模板并设为默认 仿站制作5 读老树画画随感 VMware-workstation 12 安装 Mac OS X 10.10 做梦想 再咏咳 webstorm10配置less编译环境
再次折腾hexo
bmqy · 2022-08-07 · via 北门清燕

2023年05月06日

集成Elog,重新启用COS

2023-03-30

再次更新部署到虚拟机上,弃用COS

2022-08-07

再一次开始折腾hexo了,为了省下高昂的服务器费用,为了利用上永久的虚拟主机。 只不过可惜的是虚拟主机不能支持 https,所以无奈使用了COS。 还有一点就是用markdown写文章感觉确实不错,再加上github action加持,hexo用起来感觉也是相当不错的. 而且服务器的话WordPress还要考虑一堆的性能优化问题,静态博客就完全不用担心了。 下面简单记录下hexo的部署配置问题。

Hexo 配置

固定 ID

固定 ID 推荐使用hexo-abbrlink2

  • Add plugin to Hexo:

shell

npm install hexo-abbrlink2 --save
  • Modify permalink in config.yml file:

yaml

permalink: posts/:abbrlink/
  • optional settings:

yaml

abbrlink:
  start: 1000 # the first id, default 0

资源目录

yaml

# Directory
source_dir: source

在引用图片时通过路径/images/image.jpg,引入图片资源

Next 配置

创建标签云

默认无标签页,打开链接会404 创建标签页:

markdown

---
date: 2021-08-04 13:22:27
type: "tags"
---

创建分类页

默认无分类页,打开链接会404 创建分类页:

shell

hexo new page categories

markdown

---
date: 2021-08-04 13:22:33
type: "categories"
---

自定义样式

hexo根目录下的source新增一个_data目录,在该目录下新建styles.styl,这个文件将存放我们自定义的样式,然后在_config.next.yml文件中custom_file_path选项里面将style那一行取消注释。

yaml

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

添加备案号

yaml

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

自动化部署

COS

  • Installation

yaml

npm install hexo-deployer-cos --save
  • Options You can configure in _config.yml as follows:

yaml

deploy:
  type: cos
  secretId: yourSecretId
  secretKey: yourSecretKey
  bucket: yourBucket
  region: yourRegion

For projects that use pipelines, you may not want to expose COS properties in the project file, so we support getting them through environment variables.

yaml

COS_SECRET_ID=yourSecretId
COS_SECRET_KEY=yourSecretKey
COS_BUCKET=yourBucket
COS_REGION=yourRegion

Environment variables have lower priority than _config.xml configuration

FTPSync

  • Install hexo-deployer-ftpsync.

shell

npm install hexo-deployer-ftpsync --save
  • Edit settings.

yaml

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

WX20220806-220705@2x.png

但这个方案存在一个问题,由于我们的静态网站有默认索引页面 index.html,而官方提供的这个函数只会刷新对应的文件的 URL,而不会刷新索引 URL,例如http://www.bytelife.net/index.html这个文件,通常我们的请求是http://www.bytelife.net/,因此官方的方案针对于静态网站来说不算完美。

优化方案 可以通过简单修改官方的函数来解决这个问题,点击刚刚创建的 CDN 缓存刷新函数列表中的函数名称,将 index.js 文件内容替换为下面的代码,最后点击右上角的“部署”按钮即可:

javascript

/* 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('; ');
  }
};

方案二

该方案参考自:https://blog.xm.mk/posts/fc83/#%E7%BC%93%E5%AD%98%E5%88%B7%E6%96%B0%E8%84%9A%E6%9C%AC

使用腾讯云的 Python-SDK 实现,写一个 Python 脚本,在部署完成后执行脚本调用 API 完成缓存刷新。

在仓库根目录下创建文件 flush-dns.py,文件内容如下,将其中的 https://blog.example.com/ 修改为你的 CDN 加速域名。

python

import json
import argparse
from tencentcloud.common import credential
from tencentcloud.common.profile.client_profile import ClientProfile
from tencentcloud.common.profile.http_profile import HttpProfile
from tencentcloud.common.exception.tencent_cloud_sdk_exception import (
    TencentCloudSDKException,
)
from tencentcloud.cdn.v20180606 import cdn_client, models

# 传入参数
parser = argparse.ArgumentParser(description='-i <secretId> -k <secretKey>')
parser.add_argument('-i', '--secretid', type=str, required=True, help='secretId')
parser.add_argument('-k', '--secretkey', type=str, required=True, help='secretKey')
args = parser.parse_args()

try:
    cred = credential.Credential(args.secretid,args.secretkey)
    httpProfile = HttpProfile()
    httpProfile.endpoint = "cdn.tencentcloudapi.com"

    clientProfile = ClientProfile()
    clientProfile.httpProfile = httpProfile
    client = cdn_client.CdnClient(cred, "", clientProfile)

    req = models.PurgePathCacheRequest()
    params = {"Paths": ["https://blog.example.com/"], "FlushType": "flush"}
    req.from_json_string(json.dumps(params))

    resp = client.PurgePathCache(req)
    print(resp.to_json_string())

except TencentCloudSDKException as err:
    print(err)

创建完脚本后,需要在工作流中调用,配置如下:

yaml

- name: Flush CDN
  env:
    SECRET_ID: ${{ secrets.SecretId }}      # 传入鉴权信息
    SECRET_KEY: ${{ secrets.SecretKey }}
  run: |                                    # 安装 sdk 并运行刷新脚本
    pip install --upgrade tencentcloud-sdk-python
    python flush-dns.py -i $SECRET_ID -k $SECRET_KEY

COS 配置

重定向规则

由于当时用WordPress时提供的rss订阅地址为/feed/,现在的订阅地址/feed.xml,为了兼容WordPress时订阅地址,需要做重定向规则配置:

  • 选择要设置的存储桶 - 基础配置 - 静态网站 - 编辑 - 重定向规则 - 新增规则,参考如下图配置:

    QQ%E6%88%AA%E5%9B%BE20240522132530.png
  • 内容分发网络 CDN 配置

    • 回源配置
    • 回源跟随 301/302 配置
    • 配置状态 - 开启
  • 配置完毕后,即可正常访问/feed/订阅地址

欢迎关注我的其它发布渠道

公众号小程序

文章标题:再次折腾hexo

文章作者:bmqy

文章链接:https://bmqy.net/2649.html[复制]

最后修改时间:


商业转载请联系站长获得授权,非商业转载请注明本文出处及文章链接,您可以自由地在任何媒体以任何形式复制和分发作品,也可以修改和创作,但是分发衍生作品时必须采用相同的许可协议。
本文采用CC BY-NC-SA 4.0进行许可。