hexojs / hexo

A fast, simple & powerful blog framework, powered by Node.js.
https://hexo.io
MIT License
38.82k stars 4.75k forks source link

Add `:path` as a valid permalink component? #5462

Open 45gfg9 opened 2 months ago

45gfg9 commented 2 months ago

Check List

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 commented 2 months ago

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.