Skip to content

Commit 35ceaae

Browse files
authored
fix(post): skip_render not working in post_asset_folder (#5258)
1 parent 5d8dcec commit 35ceaae

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

lib/plugins/processor/post.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,9 @@ function scanAssetDir(ctx, post) {
217217

218218
const assetDir = post.asset_dir;
219219
const baseDir = ctx.base_dir;
220+
const sourceDir = ctx.config.source_dir;
220221
const baseDirLength = baseDir.length;
222+
const sourceDirLength = sourceDir.length;
221223
const PostAsset = ctx.model('PostAsset');
222224

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

234237
if (shouldSkipAsset(ctx, post, asset)) return undefined;
@@ -237,7 +240,8 @@ function scanAssetDir(ctx, post) {
237240
_id: id,
238241
post: post._id,
239242
slug: item,
240-
modified: true
243+
modified: true,
244+
renderable: ctx.render.isRenderable(renderablePath) && !isMatch(renderablePath, ctx.config.skip_render)
241245
});
242246
});
243247
}

test/scripts/processors/post.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1256,4 +1256,76 @@ describe('post', () => {
12561256
unlink(file.source)
12571257
]);
12581258
});
1259+
1260+
it('asset - post - common render', async () => {
1261+
hexo.config.post_asset_folder = true;
1262+
1263+
const file = newFile({
1264+
path: 'foo.md',
1265+
published: true,
1266+
type: 'create',
1267+
renderable: true
1268+
});
1269+
1270+
const assetFile = newFile({
1271+
path: 'foo/test.yml',
1272+
published: true,
1273+
type: 'create'
1274+
});
1275+
1276+
await Promise.all([
1277+
writeFile(file.source, 'test'),
1278+
writeFile(assetFile.source, 'test')
1279+
]);
1280+
await process(file);
1281+
const id = 'source/' + assetFile.path;
1282+
const post = Post.findOne({ source: file.path });
1283+
PostAsset.findById(id).renderable.should.be.true;
1284+
1285+
hexo.config.post_asset_folder = false;
1286+
1287+
return Promise.all([
1288+
unlink(file.source),
1289+
unlink(assetFile.source),
1290+
post.remove(),
1291+
PostAsset.removeById(id)
1292+
]);
1293+
});
1294+
1295+
it('asset - post - skip render', async () => {
1296+
hexo.config.post_asset_folder = true;
1297+
hexo.config.skip_render = '**.yml';
1298+
1299+
const file = newFile({
1300+
path: 'foo.md',
1301+
published: true,
1302+
type: 'create',
1303+
renderable: true
1304+
});
1305+
1306+
const assetFile = newFile({
1307+
path: 'foo/test.yml',
1308+
published: true,
1309+
type: 'create'
1310+
});
1311+
1312+
await Promise.all([
1313+
writeFile(file.source, 'test'),
1314+
writeFile(assetFile.source, 'test')
1315+
]);
1316+
await process(file);
1317+
const id = 'source/' + assetFile.path;
1318+
const post = Post.findOne({ source: file.path });
1319+
PostAsset.findById(id).renderable.should.be.false;
1320+
1321+
hexo.config.post_asset_folder = false;
1322+
hexo.config.skip_render = '';
1323+
1324+
return Promise.all([
1325+
unlink(file.source),
1326+
unlink(assetFile.source),
1327+
post.remove(),
1328+
PostAsset.removeById(id)
1329+
]);
1330+
});
12591331
});

0 commit comments

Comments
 (0)