Skip to content

Commit

Permalink
fix(post): skip_render not working in post_asset_folder (hexojs#5258)
Browse files Browse the repository at this point in the history
  • Loading branch information
D-Sketon authored Aug 1, 2023
1 parent 5d8dcec commit 35ceaae
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
6 changes: 5 additions & 1 deletion lib/plugins/processor/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,9 @@ function scanAssetDir(ctx, post) {

const assetDir = post.asset_dir;
const baseDir = ctx.base_dir;
const sourceDir = ctx.config.source_dir;
const baseDirLength = baseDir.length;
const sourceDirLength = sourceDir.length;
const PostAsset = ctx.model('PostAsset');

return stat(assetDir).then(stats => {
Expand All @@ -229,6 +231,7 @@ function scanAssetDir(ctx, post) {
throw err;
}).filter(item => !isExcludedFile(item, ctx.config)).map(item => {
const id = join(assetDir, item).substring(baseDirLength).replace(/\\/g, '/');
const renderablePath = id.substring(sourceDirLength + 1);
const asset = PostAsset.findById(id);

if (shouldSkipAsset(ctx, post, asset)) return undefined;
Expand All @@ -237,7 +240,8 @@ function scanAssetDir(ctx, post) {
_id: id,
post: post._id,
slug: item,
modified: true
modified: true,
renderable: ctx.render.isRenderable(renderablePath) && !isMatch(renderablePath, ctx.config.skip_render)
});
});
}
Expand Down
72 changes: 72 additions & 0 deletions test/scripts/processors/post.js
Original file line number Diff line number Diff line change
Expand Up @@ -1256,4 +1256,76 @@ describe('post', () => {
unlink(file.source)
]);
});

it('asset - post - common render', async () => {
hexo.config.post_asset_folder = true;

const file = newFile({
path: 'foo.md',
published: true,
type: 'create',
renderable: true
});

const assetFile = newFile({
path: 'foo/test.yml',
published: true,
type: 'create'
});

await Promise.all([
writeFile(file.source, 'test'),
writeFile(assetFile.source, 'test')
]);
await process(file);
const id = 'source/' + assetFile.path;
const post = Post.findOne({ source: file.path });
PostAsset.findById(id).renderable.should.be.true;

hexo.config.post_asset_folder = false;

return Promise.all([
unlink(file.source),
unlink(assetFile.source),
post.remove(),
PostAsset.removeById(id)
]);
});

it('asset - post - skip render', async () => {
hexo.config.post_asset_folder = true;
hexo.config.skip_render = '**.yml';

const file = newFile({
path: 'foo.md',
published: true,
type: 'create',
renderable: true
});

const assetFile = newFile({
path: 'foo/test.yml',
published: true,
type: 'create'
});

await Promise.all([
writeFile(file.source, 'test'),
writeFile(assetFile.source, 'test')
]);
await process(file);
const id = 'source/' + assetFile.path;
const post = Post.findOne({ source: file.path });
PostAsset.findById(id).renderable.should.be.false;

hexo.config.post_asset_folder = false;
hexo.config.skip_render = '';

return Promise.all([
unlink(file.source),
unlink(assetFile.source),
post.remove(),
PostAsset.removeById(id)
]);
});
});

0 comments on commit 35ceaae

Please sign in to comment.