Last active
February 5, 2021 12:54
-
-
Save jonsage/82bea8bc62389b3c45485fe5b12a6534 to your computer and use it in GitHub Desktop.
Registers :build permalink placeholder that is replaced with the site build time (useful for cache-busting files)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# https://articles.inqk.net/2020/02/10/jekyll-permalinks.html | |
# place in `_plugins` directory | |
module Jekyll | |
module Drops | |
class UrlDrop < Drop | |
def build | |
@context.registers[:site].time.strftime("%s") | |
end | |
end | |
end | |
end |
Also, is @context
available in a Drop? I used @obj
because it should represent the site object document object (for which the permalink is being generated).
I can't remember anymore what data you can access from that object; I assume if you need the site object you can get to it but not sure how off the top of my head.
Hmmm, have had a look around the Jekyll codebase and I think there should be a .site
method accessible on @obj
that will get you the site. I don't know if that object has a .time
method on it but maybe give that a try and see how it goes.
To be clear, rather than:
@context.registers[:site].time.strftime("%s")
you'd have:
@obj.site.time.strftime("%s")
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
What's your configuration file look like?