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

feat(tags/post_link): search for both slug and title #5114

Merged
merged 1 commit into from
Nov 27, 2022
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
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