Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed UTF-8 slugs, closes #29. #113

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 11 additions & 2 deletions lib/ext/ext.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
require 'iconv'

class Object
def meta_def name, &blk
(class << self; self; end).instance_eval do
Expand All @@ -7,8 +9,15 @@ def meta_def name, &blk
end

class String
def slugize
self.downcase.gsub(/&/, 'and').gsub(/\s+/, '-').gsub(/[^a-z0-9-]/, '')
# http://websideattractions.com/2008/11/06/squish-the-slug-the-rails-way
def slugize(slug='-')
slugged = Iconv.iconv('ascii//TRANSLIT//IGNORE', 'utf-8', self).to_s
slugged.gsub!(/&/, 'and')
slugged.gsub!(/[^\w_\-#{Regexp.escape(slug)}]+/i, slug)
slugged.gsub!(/#{slug}{2,}/i, slug)
slugged.gsub!(/^#{slug}|#{slug}$/i, '')
slugged.downcase!
URI.escape(slugged, /[^\w_+-]/i)
end

def humanize
Expand Down
5 changes: 4 additions & 1 deletion lib/toto.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,10 @@ def archives filter = ""
end

def article route
Article.new("#{Paths[:articles]}/#{route.join('-')}.#{self[:ext]}", @config).load
path = self.articles.select do |article|
File.basename(article, ".#{self[:ext]}").slugize.eql? route.join('-')
end.last || File.join(Paths[:articles], "#{route.join('-')}.#{self[:ext]}")
Article.new(path, @config).load
end

def /
Expand Down