Created
November 19, 2015 19:05
-
-
Save Teino1978-Corp/9086c9893c9f88bb58f8 to your computer and use it in GitHub Desktop.
Category slugify plugin for Jekyll 3.0.0: This plugin will slugify the categories listed in the YML frontmatter. Categories with multiple words will have the spaces replaced with dashes. Put this file in the _plugins directory.
This file contains hidden or 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
module Jekyll | |
class Document | |
#Updated for Jekyll 3.0.0 | |
# override post method in order to return categories names as slug | |
# instead of strings | |
# | |
# An url for a post with category "category with space" will be in | |
# slugified form : /category-with-space | |
# instead of url encoded form : /category%20with%20space | |
# | |
# @see utils.slugify | |
def url_placeholders | |
{ | |
collection: collection.label, | |
path: cleaned_relative_path, | |
output_ext: output_ext, | |
name: Utils.slugify(basename_without_ext), | |
title: Utils.slugify(data['slug']) || Utils.slugify(basename_without_ext), | |
year: date.strftime("%Y"), | |
month: date.strftime("%m"), | |
day: date.strftime("%d"), | |
hour: date.strftime("%H"), | |
minute: date.strftime("%M"), | |
second: date.strftime("%S"), | |
i_day: date.strftime("%-d"), | |
i_month: date.strftime("%-m"), | |
categories: (data['categories'] || []).map { |c| Utils.slugify(c) }.uniq.join('/'), | |
short_month: date.strftime("%b"), | |
short_year: date.strftime("%y"), | |
y_day: date.strftime("%j"), | |
} | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment