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

推荐订阅源

The GitHub Blog
The GitHub Blog
V2EX - 技术
V2EX - 技术
T
Threat Research - Cisco Blogs
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
T
Tor Project blog
Project Zero
Project Zero
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
C
Cybersecurity and Infrastructure Security Agency CISA
T
Tenable Blog
P
Privacy & Cybersecurity Law Blog
AWS News Blog
AWS News Blog
Scott Helme
Scott Helme
C
Cisco Blogs
Application and Cybersecurity Blog
Application and Cybersecurity Blog
O
OpenAI News
P
Privacy International News Feed
Google Online Security Blog
Google Online Security Blog
SecWiki News
SecWiki News
The Last Watchdog
The Last Watchdog
NISL@THU
NISL@THU
Attack and Defense Labs
Attack and Defense Labs
G
GRAHAM CLULEY
Security Latest
Security Latest
Help Net Security
Help Net Security
C
Cyber Attacks, Cyber Crime and Cyber Security
Hugging Face - Blog
Hugging Face - Blog
月光博客
月光博客
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻
A
Arctic Wolf
Security Archives - TechRepublic
Security Archives - TechRepublic
S
Security @ Cisco Blogs
腾讯CDC
S
Secure Thoughts
WordPress大学
WordPress大学
P
Proofpoint News Feed
H
Help Net Security
Simon Willison's Weblog
Simon Willison's Weblog
小众软件
小众软件
M
MIT News - Artificial intelligence
博客园 - 叶小钗
IT之家
IT之家
G
Google Developers Blog
博客园 - 聂微东
Google DeepMind News
Google DeepMind News
Microsoft Security Blog
Microsoft Security Blog
Hacker News - Newest:
Hacker News - Newest: "LLM"
Google DeepMind News
Google DeepMind News
N
News and Events Feed by Topic
N
News and Events Feed by Topic

纸鹿摸鱼处

北京实习300天 | 纸鹿摸鱼处 实习后买了一堆东西 | 纸鹿摸鱼处 谈谈不受欢迎的博客技术特征 | 纸鹿摸鱼处 我们的设备被拿来做了什么:软件的背景行为 | 纸鹿摸鱼处 生成式AI正在生成 | 纸鹿摸鱼处 前端字体二三事 | 纸鹿摸鱼处 深色模式开发的最佳实践 | 纸鹿摸鱼处 寻不回手工油糕 | 纸鹿摸鱼处 一些数码外设的评价和“捡垃圾”心得 | 纸鹿摸鱼处 朋友的 Vivado 和 Modelsim 装上了吗 | 纸鹿摸鱼处 迟到三月的年末博客杂谈:动力、文章和内容 | 纸鹿摸鱼处 VitePress 不完全优化指南 | 纸鹿摸鱼处 给电脑新手的笔记本开荒指南导读 | 纸鹿摸鱼处 再谈考试时钟:技术之外的思考 | 纸鹿摸鱼处 今日校园见闻:我已经出离高兴了 | 纸鹿摸鱼处 配置并差点运行不了 Java Applet | 纸鹿摸鱼处 Windows 上的开源软件入门 | 纸鹿摸鱼处 博客进化:从 Hexo 到 Nuxt Content | 纸鹿摸鱼处 祖母的90年代南昌差旅之险 | 纸鹿摸鱼处 Linux 下通过 Samba 共享文件夹 | 纸鹿摸鱼处 从“端口无法访问”到本地环境问题——朋友的博客踩坑记录 | 纸鹿摸鱼处 Windows 空间管理/清理指南 | 纸鹿摸鱼处 遭遇APP乱象:老人的「钱袋子」开线了 | 纸鹿摸鱼处 封面被 Linux QQ 官方用了,但是有一些小缺陷 | 纸鹿摸鱼处 Windows 终端体验优化指南 | 纸鹿摸鱼处 有问题,就要讲出来。 | 纸鹿摸鱼处 从 CSS 排序折腾到 Stylelint 和 pnpm | 纸鹿摸鱼处 使用 DOSBox 的多种方式 | 纸鹿摸鱼处 今日有「假」 | 纸鹿摸鱼处 写过的奇妙代码。 | 纸鹿摸鱼处 Arch Linux 启动引导修复 | 纸鹿摸鱼处 在延长今天和期待明天之间 | 纸鹿摸鱼处 今日无事,除了一些技术咨询 | 纸鹿摸鱼处 系统引导配置分享 | 纸鹿摸鱼处 病毒高占用CPU,三天杀俩 | 纸鹿摸鱼处 运营商又想多收话费了 | 纸鹿摸鱼处 电脑连接手机,手机给电脑传文件…… | 纸鹿摸鱼处 Moonlight 串流指南 | 纸鹿摸鱼处 SSH 免密登录 | 纸鹿摸鱼处 Termux 简单指南 | 纸鹿摸鱼处 Tailscale 不完全使用指南 | 纸鹿摸鱼处 Windows 安装指南 | 纸鹿摸鱼处 Arch Linux 易用性及美化 | 纸鹿摸鱼处 Arch Linux 初步配置 | 纸鹿摸鱼处 使用 ArchInstall 安装 Arch Linux | 纸鹿摸鱼处 VS Code 简单配置项 | 纸鹿摸鱼处 他修电脑又遇到了我 | 纸鹿摸鱼处 修监控 (授权转载) | 纸鹿摸鱼处 被大块落冰砸中的话—— | 纸鹿摸鱼处
把博客文章按年份放在子文件夹中了 | 纸鹿摸鱼处
纸鹿本鹿, hi@zhilu.cyou · 2024-04-29 · via 纸鹿摸鱼处

我的博客很少写关于折腾博客的内容,因为我不想让博客变成博客的博客。这次的行为仅服务于博客的后期维护。

私以为,博客应当专注于内容,而不是囿于形式。

posts 目录文章过多

不知不觉,博客已经有了大约 45 篇文章,生成的文章链接以 :year:month/ (如 202404/) 开头,但 Markdown 源文件都放在了 _posts/ 目录下,不便于管理。因此,我想在_posts/ 目录里按年份创建子文件夹。

移动文章到年份文件夹

看了 参考资料,博主给出了一个实用命令 grep -r "date: '2015-" *.md -l | xargs mv -v -t 2015/,用于批量移动文件,我借助 Poe Assistant 写出了对应的 PowerShell 脚本。

powershell
# 搜索匹配的文件
Get-ChildItem -Filter "*.md" -Recurse | ForEach-Object {
    $filePath = $_.FullName
    $match = Select-String -Path $filePath -Pattern "date: 2020-" -Quiet

    if ($match) {
        # 获取文件名
        $fileName = $_.Name

        # 创建目标目录
        $targetDirectory = "2020"
        if (-not (Test-Path -Path $targetDirectory)) {
            New-Item -ItemType Directory -Path $targetDirectory | Out-Null
        }

        # 移动文件
        Move-Item -Path $filePath -Destination (Join-Path -Path $targetDirectory -ChildPath $fileName) -Verbose
    }
}

设置链接前缀

Hexo 会自动给文章链接带上子文件夹的名称,所以在 _config.yml 设置文章永久链接为仅 :title/,就可以满足需求。如果不想要文件夹名或者想要维持原来的 URL 配置,将原先文章永久链接中的 :title/ 替换为 :name/ 即可。

旧链接重定向

通过主题提供的自定义侧栏 Widget 能力,我为 404 页面引入了自定义脚本,用于重定向旧链接。

_config.stellar.ymlyaml
site_tree:
  error_page:
    leftbar: recent, timeline, notice_404
source/_data/widgets.ymlyaml
notice_404:
  layout: markdown
  content: |
    <!-- Notice 还没想好,以后再写吧 -->
    <script src="/static/handler-404.js"></script>

用正则表达式匹配、替换,就完成了重定向。

static/handler-404.jsjs
const newPath = location.pathname.match(/^(\/\d{4})\d{2}(\/.*)/)
if (newPath)
    location.href = newPath[1] + newPath[2]

Over.

还没有结束

上一节 的内容废弃了。

HTTP 状态码不该是 404,所以需要通过 Netlify 提供的 重定向能力,让状态码变为 3xx。

在建博客时埋了一个坑,我的链接是 :year:month/:title/,而 Netlify 的 Placeholder 仅支持诸如 :year/:month/:title/ 的形式,所以不能使用这种配置文件:

source/netlify.tomltoml
[[redirects]]
from = "/post/*"
to = "/:splat"

[[redirects]]
from = "/:year/:month/:date/:slug"
to = "/:slug"

所以我只能给每个博客 URL 分别设置重定向规则。为了获取先前的 URL 路径,我恢复了旧的 permalink 配置,把其中的 :title 改为 :name

_config.ymlyaml
permalink: :year:month/:name/
# permalink: :title/

要一条一条写重定向规则,有点麻烦,可以这么做:

  • 尝试用命令生成先前博客链接路径和新的博客链接路径 PS>

    hexo clean; hexo generate

  • findstr 不完全支持 PCRE,可以用 Select-String "\\\d{6}\\" 代替 PS>

    dir -s .\public\ | findstr -r "\\[0-9][0-9][0-9][0-9][0-9][0-9]\\"

再用正则表达式稍微替换一下输出(不要忘了/),就能得到 Netlify 的重定向规则文件了。

source/_redirectstext
……
/202304/vscode-simple-config /2023/vscode-simple-config
/202305/archinstall-guide /2023/archinstall-guide
/202306/archlinux-configure /2023/archlinux-configure
/202307/archlinux-beautify /2023/archlinux-beautify
……

如果 generate 的文件中没有 _redirects 文件,那就修改一下配置文件:

_config.ymlyaml
include: [_redirects]

这下应该 over 了。

又没有结束

5个月后,我通过 Google Search Console 发现收录的博客链接还是原先的。于是又通过 Nuxt 的能力编写了新的重定向脚本,并期待它能获取到 canonical 标签。