Skip to content

Commit

Permalink
feat(tags/post_link): search for both slug and title (#5114)
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang authored Nov 27, 2022
1 parent 00bcce5 commit ca51e15
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
5 changes: 3 additions & 2 deletions lib/plugins/tag/post_link.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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}.`);
}
Expand Down
5 changes: 3 additions & 2 deletions lib/plugins/tag/post_path.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down

0 comments on commit ca51e15

Please sign in to comment.