Created
October 19, 2013 22:51
-
-
Save IQAndreas/7062536 to your computer and use it in GitHub Desktop.
Slug function where there IS a trailing slash (note the difference between `contact.html` and `contact/index.html`)
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
# Sample output: | |
# URL: /contact.html SLUG: /contact | |
# URL: /contact.htm SLUG: /contact | |
# URL: contact.html SLUG: contact # The output only starts with a forward-slash if the input does (always) | |
# URL: /contact/index.html SLUG: /contact/ # <-- Here is the major difference between this and the other version | |
# URL: /index.html SLUG: / | |
# URL: index.html SLUG: (empty string) | |
# URL: /dummy/.html SLUG: /dummy/ # Just don't use stupid page names like this | |
# URL: /.html SLUG: / # Again, I'm just too lazy to account for stupid cases | |
# URL: /funny/images/cats.html SLUG: /funny/images/cats/ | |
def slug | |
# If `html?` remove trailing '.html' (or trailing '.htm') | |
# If `index?` remove trailing 'index.html' | |
# Done with regex instead of calling those two functions | |
self.fixed_octopress_url.sub( /(index)?\.html?$/ , "" ) | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment