hexo-abbrlink icon indicating copy to clipboard operation
hexo-abbrlink copied to clipboard

有关当下版本启用post_asset_folder后与abbrlink插件冲突解决方案

Open syunaht opened this issue 2 years ago • 6 comments

之前有几个issues已经提到该问题,但由于hexo更新,hexo-asset-image插件集成到hexo-renderer-marked

粗略的看了下代码,确实与abbrlink插件无关。于是硬着头皮研究了好久,现附解决方案。

node_modules\hexo\lib\models\post_asset.js目录中

改动1:

return join(post.path.replace(/\.html?$/, ''), this.slug);

改为:

return join(dirname(post.path), post.slug, this.slug);

改动2:

const { join} = require('path');

改为

const { join, dirname } = require('path');

本想写个Scripts优雅地解决,尝试了很久都无法实现,只能改hexo的代码。希望后来者有人能研究出来。

syunaht avatar Jan 07 '23 08:01 syunaht

这个问题由hex-asset-image 应该早就解决了才是 https://github.com/xcodebuild/hexo-asset-image/pull/58 不知道为啥继任者又出这个问题 😢

ohroy avatar Jan 07 '23 11:01 ohroy

之前有几个issues已经提到该问题,但由于hexo更新,hexo-asset-image插件集成到hexo-renderer-marked

粗略的看了下代码,确实与abbrlink插件无关。于是硬着头皮研究了好久,现附解决方案。

node_modules\hexo\lib\models\post_asset.js目录中

改动1:

return join(post.path.replace(/\.html?$/, ''), this.slug);

改为:

return join(dirname(post.path), post.slug, this.slug);

改动2:

const { join} = require('path');

改为

const { join, dirname } = require('path');

本想写个Scripts优雅地解决,尝试了很久都无法实现,只能改hexo的代码。希望后来者有人能研究出来。

请问大佬现在这个版本的文件是这样的如何改动? "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; const warehouse_1 = __importDefault(require("warehouse")); const path_1 = require("path"); module.exports = (ctx) => { const PostAsset = new warehouse_1.default.Schema({ _id: { type: String, required: true }, slug: { type: String, required: true }, modified: { type: Boolean, default: true }, post: { type: warehouse_1.default.Schema.Types.CUID, ref: 'Post' }, renderable: { type: Boolean, default: true } }); PostAsset.virtual('path').get(function () { const Post = ctx.model('Post'); const post = Post.findById(this.post); if (!post) return; // PostAsset.path is file path relative to public_dir // no need to urlescape, #1562 // strip /.html?$/ extensions on permalink, #2134 return (0, path_1.join)(post.path.replace(/.html?$/, ''), this.slug); }); PostAsset.virtual('source').get(function () { return (0, path_1.join)(ctx.base_dir, this._id); }); return PostAsset; }; //# sourceMappingURL=post_asset.js.map

AlexANSO avatar Jan 10 '24 14:01 AlexANSO

25年4月20日目前这个方案还有效吗?

wwzxhy avatar Apr 20 '25 13:04 wwzxhy

之前有几个issues已经提到该问题,但由于hexo更新,hexo-asset-image插件集成到hexo-renderer-marked 粗略的看了下代码,确实与abbrlink插件无关。于是硬着头皮研究了好久,现附解决方案。 node_modules\hexo\lib\models\post_asset.js目录中 改动1: return join(post.path.replace(/.html?$/, ''), this.slug);

改为: return join(dirname(post.path), post.slug, this.slug);

改动2: const { join} = require('path');

改为 const { join, dirname } = require('path');

本想写个Scripts优雅地解决,尝试了很久都无法实现,只能改hexo的代码。希望后来者有人能研究出来。

请问大佬现在这个版本的文件是这样的如何改动? "use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; const warehouse_1 = __importDefault(require("warehouse")); const path_1 = require("path"); module.exports = (ctx) => { const PostAsset = new warehouse_1.default.Schema({ _id: { type: String, required: true }, slug: { type: String, required: true }, modified: { type: Boolean, default: true }, post: { type: warehouse_1.default.Schema.Types.CUID, ref: 'Post' }, renderable: { type: Boolean, default: true } }); PostAsset.virtual('path').get(function () { const Post = ctx.model('Post'); const post = Post.findById(this.post); if (!post) return; // PostAsset.path is file path relative to public_dir // no need to urlescape, #1562 // strip /.html?$/ extensions on permalink, #2134 return (0, path_1.join)(post.path.replace(/.html?$/, ''), this.slug); }); PostAsset.virtual('source').get(function () { return (0, path_1.join)(ctx.base_dir, this._id); }); return PostAsset; }; //# sourceMappingURL=post_asset.js.map

我尝试使用deepseek辅助修改代码,但没有效果,不过找到了其他的解决办法

wwzxhy avatar Apr 21 '25 12:04 wwzxhy

2025.5.1更新,之前疏忽了写错了一点点

1.问题分析

首先这个问题确实与abbrlink插件无关,而是与修改博客_config.yml配置文件中的URL选项有关。

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: https://mifazhan.top/
permalink: posts/:title/

例如在我将配置修改为上述形式后,文章图片便无法正确加载,

无论是理应会自动转换的![](filename/image.jpg),还是img 标签都无法正常显示

而这时使用asset_img 语法引用的图片则没有任何问题,依然可以正常显示。

这时倘若将配置改为permalink: :title/或改回默认,文章图片所有的引用都不会出问题

2.尝试修改post_asset.js文件

目前post_asset.js的结构有所变更,用户syunaht的方法无法直接使用,

尝试在deepseek的指导下修改post_asset.js文件

将25行代码修改如下所示

return path_1.posix.join(
            path_1.posix.dirname(post.path), // 使用 posix.dirname 确保路径格式
            post.slug,
            this.slug
        );

重新生成本地运行测试无效

3.寻找新的解决方法

既然我们需要修改URL配置,而修改后其他引用方法会失效

那么索性寻找方法,将![]()引用方法转换为 ​​asset_img 语法

hexo-image-link插件完美解决了这个问题

按照介绍安装后,hexo clean && hexo g && hexo s本地运行测试问题解决

如果没有看懂后续会出专门的博客文章,敬请期待

博客(mifazhan.top)

wwzxhy avatar Apr 21 '25 13:04 wwzxhy

1.问题分析

首先这个问题确实与abbrlink插件无关,而是与修改博客_config.yml配置文件中的URL选项有关。

# URL
## Set your site url here. For example, if you use GitHub Page, set url as 'https://username.github.io/project'
url: https://mifazhan.top/
permalink: posts/:title/

例如在我将配置修改为上述形式后,文章图片便无法正确加载,

无论是理应会自动转换的![](filename/image.jpg),还是![](image.jpg)都无法正常显示

而这时使用img 标签引用的图片则没有任何问题,依然可以正常显示。

这时倘若将配置改为permalink: :title/或改回默认,文章图片引用都不会出问题

2.尝试修改post_asset.js文件

目前post_asset.js的结构有所变更,用户syunaht的方法无法直接使用,

尝试在deepseek的指导下修改post_asset.js文件

将25行代码修改如下所示

return path_1.posix.join(
            path_1.posix.dirname(post.path), // 使用 posix.dirname 确保路径格式
            post.slug,
            this.slug
        );

重新生成本地运行测试无效

3.寻找新的解决方法

既然我们需要修改URL配置,而修改后![]()引用方法会失效

那么索性寻找方法,将![]()引用方法转换为 ​​asset_img 语法

hexo-image-link插件完美解决了这个问题

按照介绍安装后,hexo clean && hexo g && hexo s本地运行测试问题解决

如果没有看懂后续会出专门的博客文章,敬请期待

博客(mifazhan.top)

当初给hexo提交过代码修复这类问题,检查没通过也懒得去搞了 已经很久没更博客了,hexo也基本不更新了,这个问题只能等后来者解决了

syunaht avatar Apr 30 '25 13:04 syunaht