Created
November 19, 2015 18:54
-
-
Save becker1701/fd575b5f471b410568fe 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 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 |
hi, i tried post.rb but can not run it. i am newly at jekyll. i add post.rb under _plugins directory at master and wait to action but nothing occured. what i missed, could you tell me
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have problem with chinese characters in category url. Can you show me how to strip them?
example: when i create a category in a post like 'abc-糯米'
->by default: mysite/catgory/abc-糯米
->expect: mysite/category/abc
Thanks