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

Underscores in post name converted to hyphens #4135

Closed
rogerjohansson opened this issue Nov 13, 2015 · 6 comments
Closed

Underscores in post name converted to hyphens #4135

rogerjohansson opened this issue Nov 13, 2015 · 6 comments

Comments

@rogerjohansson
Copy link

@rogerjohansson rogerjohansson commented Nov 13, 2015

In 3.0.0, if a post (file) name contains underscores, they are converted to hyphens in the URL output by {{ post.url }}. This does not happen in 2.5.3. Is this an intentional change and can it be worked around? I have not been able to find anything in the documentation or existing issues.

@rebornix
Copy link
Contributor

@rebornix rebornix commented Nov 15, 2015

When I send pr #4100 , I thought it was just a cased/uncased issue, now it turns out to be a bigger problem.

In 2.5.3, we use document and post separately to store post files and other pages. For document, the title is slugified however for post, the title is just what we extract from the filename.

:title  => slug,
def process(name)
      m, cats, date, slug, ext = *name.match(MATCHER)
      self.date = Utils.parse_date(date, "Post '#{relative_path}' does not have a valid date in the filename.")
      self.slug = slug
      self.ext = ext
end

In 3.0.0, we merged document and post into one document.rb, which means, the title of each post is slugified: title: Utils.slugify(data['slug']) || Utils.slugify(basename_without_ext).

We can't simply remove the slugify as it will affect original documents. So a proper solution here is: keep the title slugified and add a new property like unslugified_title then users can customize their permalink as /:categories/:year/:month/:day/:unslugifed_title/. Users will have all backwards compatibility.

@envygeeks , are you okay with this suggestion? Or maybe you can propose a name better than unslugified_title ( I'm not a native English speaker, naming is always the hardest part 😢 )

@envygeeks
Copy link
Contributor

@envygeeks envygeeks commented Nov 15, 2015

IMO merge it with #title (:title) in your current pull, where title will keep the case, -, and _, whichever you use and guard against special chars and :slug will not. /cc @parkr @jekyll/core

@rebornix
Copy link
Contributor

@rebornix rebornix commented Nov 15, 2015

@envygeeks thanks! I'll update my pr later.

@rogerjohansson This issue can be resolved once my pr is merged into master and Jekyll release 3.0.1 (I suppose). Before that, you can use a tiny plugin jekyll-post-unslugify I just wrote to workaround, then you can have your title back.

@rogerjohansson
Copy link
Author

@rogerjohansson rogerjohansson commented Nov 15, 2015

@rebornix Thanks! Your plugin seems to work as advertised :-).

@rebornix
Copy link
Contributor

@rebornix rebornix commented Nov 16, 2015

SLUGIFY_RAW_REGEXP = Regexp.new('\\s+').freeze
SLUGIFY_DEFAULT_REGEXP = Regexp.new('[^[:alnum:]]+').freeze
SLUGIFY_PRETTY_REGEXP = Regexp.new("[^[:alnum:]._~!$&'()+,;=@]+").freeze

I find we have defined Pretty mode in Util.Slugify. This mode can keep characters like _, ~, etc, but currently we only use default mode across the entire code base.

@envygeeks Can we use pretty mode for :title? It would be like a hole in the default mode or raw mode if we only handle _ specially

@jekyllbot
Copy link
Contributor

@jekyllbot jekyllbot commented Feb 17, 2016

This issue has been automatically marked as stale because it has not been commented on for at least
three months.

The resources of the Jekyll Core team are limited, and so we are asking for your help.

If you can still reproduce this error on the 3.0-stable branch or on master,
please reply with all of the information you have about it in order to keep the issue open.

Thank you for all your contributions.

@jekyllbot jekyllbot closed this Jun 6, 2016
@jekyll jekyll locked and limited conversation to collaborators Jul 5, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
4 participants
You can’t perform that action at this time.