Skip to content

Instantly share code, notes, and snippets.

@peey
Last active October 19, 2023 12:14
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save peey/897e8ed33e412fdfe0fcacf002acc150 to your computer and use it in GitHub Desktop.
Save peey/897e8ed33e412fdfe0fcacf002acc150 to your computer and use it in GitHub Desktop.
Jekyll plugin for parsing of custom variables in permalinks
# will substitute :author with the variable author in your file (also works with defaults).
permalink: /:author/:slug/
# You need to have this extra permalink_custom_vars array to tell the plugin which substitutions to make
permalink_custom_vars: ['author']
# Note that you don't have to include the supported variables in this list as jekyll takes care of that
# For a complete list of variables jekyll supports, see: https://jekyllrb.com/docs/permalinks/#template-variables
@peey
Copy link
Author

peey commented May 17, 2017

To use, please put the .rb file in a directory named _plugins. See the article for more details.
Disclaimer: I only know as much ruby as I've learnt in the past 20 minutes. Safety not guaranteed.

@andreamoro
Copy link

andreamoro commented May 22, 2022

Hello @peey
Does this work with the modern version of Jekyll? I'm trying to make it something for the pages, where if they contains a :slug, this is going to be forming the pemalink later without success.

In fact, even a simple, hardcoded replacement is ignored.

 	if p.data['slug'].include?("/test/") 
            puts("rewriting the permalink")
            permalink = p.data['permalink'] = "/newurl"
       end

Do you have any idea?
Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment