hexojs / hexo

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

A more universal variable system both front-matter + file name + permalinks. #649

Closed reggi closed 10 years ago

reggi commented 10 years ago

This is a feature request, for a way to standardize the variable system. It revolves around the idea that any variable can be set within the post file-name and within the YML front-matter and that these variables can be both used in the layouts and in the permalink, (any place a variable can be used).

Here's an example of my config file.

permalink: :crazyid/:year/:month/:day/:title/
new_post_name: :crazyid-:year-:month-:day-:title.md # File name of new posts

Given the example file name:

jd91230ue-2014-03-14-hello-world.md

It's rendering out the url to:

http://localhost:4000/2014/05/30/jd91230ue-2014-03-14-hello-world/

I would expect it to be:

http://localhost:4000/jd91230ue/2014/05/30/hello-world/

It would be nice if the YML front-matter variables could be used for the permalink as well (a priority would need to take place between file-name and front-matter).

title: Hello World
crazyid: jd91230ue

---
Welcome to [Hexo](http://hexo.io/)! This is your very first post. Check [documentation](http://hexo.io/docs/) for more info. If you get any problems when using Hexo, you can 

for instance.

Or without setting it in the md post and it just being in the file name, being able to use the crazyid variable within the template / layout would be more universal.

tommy351 commented 10 years ago

OK. I'll try to implement this feature in 2.7.

sergiolepore commented 10 years ago

@tommy351 THIS

Seriously, this could be awesome. I could use a variable named language to define the post language, reflect it on the permalink, write a theme which queries posts by language variable and we'll be so close to resolve this: #474 :smiley:

reggi commented 10 years ago

I think it would also be wise to have some kind of "Hook" that allowed plugins to manipulate these variables before they're used, kind of like a "Middleware". This would allow me to have a post named hello-world.md which is mapped to :title and have the title be rendered out as Hello World (rather then hello world) in my blog post without any redundant YML front-matter or functions within the layout, could also be used to manipulate date with moment.js. Thoughts on this?

tommy351 commented 10 years ago

@reggi Hexo has "Filter" currently. But it's still weak. This part will be enhanced in future.

tommy351 commented 10 years ago

This feature will be released in 2.8.

sergiolepore commented 10 years ago

:D great! El jul 6, 2014 5:52 a.m., "SkyArrow" notifications@github.com escribió:

This feature will be released in 2.8.

— Reply to this email directly or view it on GitHub https://github.com/hexojs/hexo/issues/649#issuecomment-48106393.

reggi commented 9 years ago

Thank you so much for implementing. This works like a charm! :thumbsup: