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

Add :path as a valid permalink component? #5462

Open
2 tasks done
45gfg9 opened this issue Apr 13, 2024 · 1 comment
Open
2 tasks done

Add :path as a valid permalink component? #5462

45gfg9 opened this issue Apr 13, 2024 · 1 comment

Comments

@45gfg9
Copy link

45gfg9 commented Apr 13, 2024

Check List

  • I have already read Docs page.
  • I have already searched existing issues.

Feature Request

So this feature request is essentially #5263, but I think it might be useful to others as well. I am using Hexo 7.1.1.

How about making :path a valid permalink component, just like :name where you have the filename of the source?

My current permalink setup is:

permalink: :path/:hash/

which yields something like https://example.com/path/to/012345abcdef/.

I'm no Hexo or JavaScript pro, so to me it doesn't look too complex. All I did to make this setup work is to add a single line:

--- a/lib/plugins/filter/post_permalink.ts
+++ b/lib/plugins/filter/post_permalink.ts
@@ -26,6 +26,7 @@
         id: id || _id,
         title: slug,
         name: typeof slug === 'string' ? (0, path_1.basename)(slug) : '',
+        path: typeof slug === 'string' ? (0, path_1.dirname)(slug) : '',
         post_title: (0, hexo_util_1.slugize)(title, { transform: 1 }),
         year: date.format('YYYY'),
         month: date.format('MM'),

Again, I'm not sure if this will have any negative consequences, just "it works for me." Any ideas?

Others

No response

@stevenjoezhang
Copy link
Member

This is indeed a solution, but I suggest renaming this option to something like dirname. In Hexo's design, a post's path is a getter, which is calculated based on the permalink. Using a parameter named path in the permalink would cause confusion.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants