From 394eab4a3afc561f294c2c7212ab2680d244b6fe Mon Sep 17 00:00:00 2001
From: Chris Frederick
Date: Sun, 7 Sep 2014 16:48:57 +0900
Subject: [PATCH 1/3] Add the slugify Liquid filter
---
lib/jekyll/filters.rb | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/lib/jekyll/filters.rb b/lib/jekyll/filters.rb
index 2664a01f..bcdf80ff 100644
--- a/lib/jekyll/filters.rb
+++ b/lib/jekyll/filters.rb
@@ -47,6 +47,17 @@ module Jekyll
converter.convert(input)
end
+ # Slugify a filename or title.
+ #
+ # input - The filename or title to slugify.
+ #
+ # Returns the given filename or title as a lowercase String, with every
+ # sequence of spaces and non-alphanumeric characters replaced with a
+ # hyphen.
+ def slugify(input)
+ Utils.slugify(input)
+ end
+
# Format a date in short format e.g. "27 Jan 2011".
#
# date - the Time to format.
From 77297744ceccd5a03e157c0aac82935d821307d3 Mon Sep 17 00:00:00 2001
From: Chris Frederick
Date: Sun, 7 Sep 2014 16:49:14 +0900
Subject: [PATCH 2/3] Add a test for the slugify Liquid filter
---
test/test_filters.rb | 6 ++++++
1 file changed, 6 insertions(+)
diff --git a/test/test_filters.rb b/test/test_filters.rb
index 58841fe8..e4f1adf3 100644
--- a/test/test_filters.rb
+++ b/test/test_filters.rb
@@ -217,5 +217,11 @@ class TestFilters < Test::Unit::TestCase
end
end
+ context "slugify filter" do
+ should "return a slugified string" do
+ assert_equal "q-bert-says", @filter.slugify(" Q*bert says @!#?@!")
+ end
+ end
+
end
end
From a2fedfc6150fe3a44889c05cce7b1b31c3fa188e Mon Sep 17 00:00:00 2001
From: Chris Frederick
Date: Sun, 7 Sep 2014 17:01:53 +0900
Subject: [PATCH 3/3] Document the slugify Liquid filter
---
site/_docs/templates.md | 11 +++++++++++
1 file changed, 11 insertions(+)
diff --git a/site/_docs/templates.md b/site/_docs/templates.md
index 5ace04fc..84655db8 100644
--- a/site/_docs/templates.md
+++ b/site/_docs/templates.md
@@ -211,6 +211,17 @@ common tasks easier.
+
+
+ Slugify
+ Convert a string into a lowercase URL "slug" by replacing every sequence of spaces and non-alphanumeric characters with a hyphen.
+ |
+
+
+ {% raw %}{{ page.title | slugify }}{% endraw %}
+
+ |
+
Data To JSON
|