Skip to content

Commit

Permalink
Merge 7f9a8be into 807ddd8
Browse files Browse the repository at this point in the history
  • Loading branch information
stevenjoezhang committed Nov 24, 2022
2 parents 807ddd8 + 7f9a8be commit 2750638
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
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
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 2750638

Please sign in to comment.