Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: skip_render not working in post_asset_folder #5258

Merged
merged 1 commit into from
Aug 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
]);
});
});
Loading