简体   繁体   中英

How to use version.rb plugin in Jekyll static site generator

Here is the plugin code...

module Jekyll
  module VersionFilter
    def versioned_url(input)
      "#{input}?#{Time.now.to_i}"
    end
  end
end

Liquid::Template.register_filter(Jekyll::VersionFilter)

I am trying to cache bust/version control my .css file. I am new to Liquid. I am having trouble figuring out this basic plugin. Any help?

You need to put version.rb into the _plugins/ directory in the root of your Jekyll site. If you don't have a _plugins/ directory, create one.

For usage - it looks like it gives a new filter that you can apply to text - so you'd use it in your templates to filter the references to your CSS files, adding the query string so that they aren't cached - but I'm sure there's more info on that wherever you got the code from.

For what it's worth, breaking caches with querystrings isn't the best solution. It'd probably be better to write a plugin that adds a new string to the actual filename, and then adds that string to the urls where those assets are included in the templates - but that is a bit more complex.

If using an existing plugin for static asset versioning is an option for you, try jekyll-minibundle .

Assuming you keep non-stamped CSS files in _styles (note the _, because you don't want these to be exported to the production site) and want the stamped CSS files to appear in css , do the following:

<link href="{% ministamp _styles/site.css css/site.css %}" rel="stylesheet" media="screen, projection">

That works fine in combination with compass, just make compass export to _styles .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM