emacs-love / weblorg

Static Site Generator for Emacs
https://emacs.love/weblorg
GNU General Public License v3.0
279 stars 21 forks source link

post.url as a shortcut for {{ url_for("post", slug=post.slug) }} #29

Closed semente closed 2 years ago

semente commented 3 years ago

I have multiple directories containing posts and I want to be able to generate a RSS feed for the posts of all these directories, and not just individually. And I could achieve this using the following route:

(weblorg-route
 :name "feed"
 :input-pattern "*/*.org"
 :input-aggregate #'weblorg-input-aggregate-all-desc
 :template "feed.xml"
 :output ".build/feed.xml"
 :url "/feed.xml")

The problem is that I can't set a proper item.link or item.guid for the RSS entry because it can't guess what is the route of some post. url_for requires a route name and I can't do something like <link>{{ url_for(post.route.name, slug=post.slug) }}</link>.

So I propose a post.url attribute to make this possible. It will also help those who want to reuse a feed.xml template between different "posts directories".

(by the way, would be interesting to support post.route.name as well)

clarete commented 3 years ago

Thanks for bringing this up @semente, and thanks for the insight on both providing direct access to the post's fully baked URL but also to notice that we currently don't have an edge between the post and its route, though we already support the opposite edge. I think both points should be addressed.

The only thing that I'd suggest changing in your proposal is that maybe I'd keep post.url and introduce something like post.full_url (please chime in on the name if you think this is a good idea). the way it is for two reasons:

  1. we get to keep backward compatibility
  2. then people can still have access to what they typed in the route rendered

What do you think?

semente commented 3 years ago
  1. we get to keep backward compatibility

hmm but do we already have a post.url? I couldn't use this in templates... Or I didn't understand why it would make a backward compatibility.

Anyway I'm fine in using another name. Perhaps absolute_url? full_url looks good too.

clarete commented 3 years ago
  1. we get to keep backward compatibility

hmm but do we already have a post.url? I couldn't use this in templates... Or I didn't understand why it would make a backward compatibility.

Anyway I'm fine in using another name. Perhaps absolute_url? full_url looks good too.

I have no idea why I thought we had anything in post.url I guess I made that up. I guess we should go with that name. Sorry about the confusion here.

clarete commented 3 years ago

I just pushed a commit with the feature implemented. I didn't really close the ticket because I didn't really document it yet! Anyway, let me know if you have any feedback on it 😄 Thank you for opening this issue with such a cool idea 🙇🏾

semente commented 3 years ago

opa @clarete, looks like this is not working. I get an undefined value instead the URL.

clarete commented 3 years ago

opa! Thanks for testing it out, @semente!!! I'll take another stab at it!

clarete commented 2 years ago

hi hi hello @semente 👋🏾 finally got to take another look at this issue and I'm now using this feature in weblorg's website itself! So if it breaks it will probably be more visible to me 😅

Please feel free to either reopen this issue or to open a new one if this doesn't work as expected and once again, thanks for both the suggestion and for all the time taken testing this out! 🙇🏾

semente commented 2 years ago

@clarete was testing this today and it worked partially. Post objects from weblorg-input-aggregate-all-desc's posts list returns the current page URL instead object's URL.

post.html:

{{ post.url }} <- this works!

posts.html:

  {% for post in posts %}
  {{ post.url }} <- this returns current page URL instead post's URL
  {% endfor %}

routes:

(weblorg-route
 :name "log"
 :input-pattern "log/*.org"
 :template "post.html"
 :output ".output/log/{{ file_slug }}.html"
 :url "/log/{{ file_slug }}.html")

(weblorg-route
 :name "log/"
 :input-pattern "log/*.org"
 :input-aggregate #'weblorg-input-aggregate-all-desc
 :template "posts.html"
 :output ".output/log/index.html"
 :url "/log/")