1.3 KiB
1.3 KiB
title, date, tags
| title | date | tags | |
|---|---|---|---|
| hexo与md完美结合 | 2025-09-15 04:57:10 |
|
前言
想搭建一个博客,看了很多如halo、hexo、hugo、mkdocs、Jekyll等多种博客;都不满足我的需求
我的需求如下
- 完美支持md,目前主流语法
- 占用内存下,小服务器能跑
- 颜值不要太难看
搭建hexo
安装nodejs
自行安装
设置url按标题生成
在 hexo/_config.yml 里加:
permalink: :title.html
为了较为完美的实现md语法,自定义脚本实现链接
脚本存储位置:blog\scripts\md-link-fix.js
hexo.extend.filter.register('before_post_render', function (data) {
if (!data.content) return data;
// 处理 md 链接
data.content = data.content.replace(
/\[([^\]]+)\]\(([^)]+)\.md\)/g,
function (match, text, path) {
return `[${text}](${path}.html)`;
}
);
// 处理图片 (匹配  → 不动,只确保不拼 .html)
data.content = data.content.replace(/!\[([^\]]*)\]\(([^)]+)\)/g,
(match, alt, path) => {
return ``;
});
// console.log("过滤器已运行:", data.source);
return data;
});
目前图片链接处理可能还是会导致异常,问题在于会修稿所有链接,所以可能会误伤其他链接