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

推荐订阅源

TaoSecurity Blog
TaoSecurity Blog
L
LINUX DO - 最新话题
Help Net Security
Help Net Security
N
News | PayPal Newsroom
www.infosecurity-magazine.com
www.infosecurity-magazine.com
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
The Last Watchdog
The Last Watchdog
S
Security @ Cisco Blogs
W
WeLiveSecurity
C
CXSECURITY Database RSS Feed - CXSecurity.com
Webroot Blog
Webroot Blog
T
Troy Hunt's Blog
V
Vulnerabilities – Threatpost
Google Online Security Blog
Google Online Security Blog
N
News and Events Feed by Topic
T
Threat Research - Cisco Blogs
Security Archives - TechRepublic
Security Archives - TechRepublic
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
T
Tor Project blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
D
Darknet – Hacking Tools, Hacker News & Cyber Security
PCI Perspectives
PCI Perspectives
Google DeepMind News
Google DeepMind News
T
Tailwind CSS Blog
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Apple Machine Learning Research
Apple Machine Learning Research
IT之家
IT之家
S
SegmentFault 最新的问题
J
Java Code Geeks
P
Privacy & Cybersecurity Law Blog
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
博客园 - 【当耐特】
博客园_首页
H
Hacker News: Front Page
T
Threatpost
Jina AI
Jina AI
博客园 - Franky
月光博客
月光博客
L
LINUX DO - 热门话题
The Cloudflare Blog
H
Heimdal Security Blog
博客园 - 司徒正美
酷 壳 – CoolShell
酷 壳 – CoolShell
Cloudbric
Cloudbric
雷峰网
雷峰网
Hugging Face - Blog
Hugging Face - Blog
S
Secure Thoughts
T
Tenable Blog
I
Intezer
OSCHINA 社区最新新闻
OSCHINA 社区最新新闻

Hyde Blog

Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog 关于我 关于我 Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog Hyde Blog
Hyde Blog
Hyde · 2025-10-05 · via Hyde Blog

批量生成封面 ​

提示

这是一个适用于 vitepress 的 Vite 插件,vitepress 启动时,插件会指定的 Markdown 自动生成 frontmatter。

github 地址:点击跳转

特色 ✨ ​

  • 🚀 自动生成 frontmatter
  • 🚀 支持新习俗 frontmatter

安装 ​

pnpm 推荐npmyarn

sh

pnpm i vitepress-plugin-auto-frontmatter

sh

npm install vitepress-plugin-auto-frontmatter

sh

yarn add vitepress-plugin-auto-frontmatter

配置 ​

vitepress/config.ts 中配置插件

提示

壁纸获取列表请参考Wallpaper。 图片路径可以是本地(例如/img/bg/1.png),也可以是在线 url(将封面壁纸上传到自己图床后,把多个壁纸 url 写到一个列表里)。然后随机自动注入到 Markdown 文章或者新创建的 Markdown 文章

ts

import { Wallpaper } from "./ConfigHyde/Wallaper"; // 导入Wallaper模块
const CoverImgList = Wallpaper; // 获取壁纸列表

const teekConfig = defineTeekConfig({
  vitePlugins: {
    autoFrontmatterOption: {
      exclude: { title: true, date: true }, // 排除自动生成字段
      transform: (frontmatter) => {
        // 如果文件本身存在了 coverImg,则不生成
        if (frontmatter.coverImg) return; // 随机获取 coverImg

        const list = CoverImgList;

        const coverImg = list[Math.floor(Math.random() * list.length)];

        const transformResult = { ...frontmatter, coverImg };

        return Object.keys(transformResult).length
          ? transformResult
          : undefined;
      },
    },
  },
});

插件默认忽略 frontmatter 中 layout: home 和["node_modules", "dist"]目录下的文件,且只扫描 Markdown 文档。

插件默认给 Markdown 文件生成 title 和 date 两个属性,其中 title 为文件名(支持带序号的文件名,如 01.xx.md),date 为文件的创建日期。

md

---
title: 文件名
date: yyyy-MM-dd hh:mm:ss
---

拓展 ​

如果壁纸 url 地址更换了,那么 Markdown 文章之前自动注入的封面图片 url 地址还是之前的,这时候需要批量先删除 coverImg 信息,再重新生成 coverImg 信息,这里可以利用 Vscode 的搜索正则表达式来批量替换为空

sh

coverImg:\s*/home/[^,]*

正则表达式含义说明:

  • coverImg: 直接匹配字符串 "coverImg:",用于定位 Frontmatter 中的封面图片字段。
  • \s: 匹配零个或多个空白字符(包括空格、制表符、换行符等),用于处理冒号后的可能缩进或换行。
  • /home/: 直接匹配字符串 "/home/",表示封面图片路径以该目录开头。
  • [^,]: 匹配除逗号以外的任意字符, 表示匹配零次或多次