From 7f9a8bee16dc983d2740f9f8fc2d506ee726cf22 Mon Sep 17 00:00:00 2001 From: Mimi <1119186082@qq.com> Date: Thu, 24 Nov 2022 14:09:27 +0800 Subject: [PATCH] feat(tags/post_link): search for both slug and title --- lib/plugins/tag/post_link.js | 5 +++-- lib/plugins/tag/post_path.js | 5 +++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/plugins/tag/post_link.js b/lib/plugins/tag/post_link.js index d8d94fbfb8..553e7599ce 100644 --- a/lib/plugins/tag/post_link.js +++ b/lib/plugins/tag/post_link.js @@ -8,7 +8,7 @@ const { postFindOneFactory } = require('./'); * Post link tag * * Syntax: - * {% post_link slug [title] [escape] %} + * {% post_link slug | title [title] [escape] %} */ module.exports = ctx => { return function postLinkTag(args) { @@ -24,7 +24,8 @@ module.exports = ctx => { escape = 'true'; } - const post = postFindOneFactory(ctx)({ slug }); + const factory = postFindOneFactory(ctx); + const post = factory({ slug }) || factory({ title: slug }); if (!post) { throw new Error(`Post not found: post_link ${slug}.`); } diff --git a/lib/plugins/tag/post_path.js b/lib/plugins/tag/post_path.js index 0b81ed69e9..89346560f4 100644 --- a/lib/plugins/tag/post_path.js +++ b/lib/plugins/tag/post_path.js @@ -8,14 +8,15 @@ const { postFindOneFactory } = require('./'); * Post path tag * * Syntax: - * {% post_path slug %} + * {% post_path slug | title %} */ module.exports = ctx => { return function postPathTag(args) { const slug = args.shift(); if (!slug) return; - const post = postFindOneFactory(ctx)({ slug }); + const factory = postFindOneFactory(ctx); + const post = factory({ slug }) || factory({ title: slug }); if (!post) return; const link = encodeURL(resolve(ctx.config.root, post.path));