Skip to content

Underscores in post name converted to hyphens #4135

@rogerjohansson

Description

@rogerjohansson

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.

Activity

rebornix

rebornix commented on Nov 15, 2015

@rebornix
Contributor

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

envygeeks commented on Nov 15, 2015

@envygeeks
Contributor

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

rebornix commented on Nov 15, 2015

@rebornix
Contributor

@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

rogerjohansson commented on Nov 15, 2015

@rogerjohansson
Author

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

rebornix

rebornix commented on Nov 16, 2015

@rebornix
Contributor
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

added
staleNobody stepped up to work on this issue.
on Feb 17, 2016
jekyllbot

jekyllbot commented on Feb 17, 2016

@jekyllbot
Contributor

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.

locked and limited conversation to collaborators on Jul 5, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

      Development

      No branches or pull requests

        Participants

        @envygeeks@rogerjohansson@rebornix@jekyllbot

        Issue actions

          Underscores in post name converted to hyphens · Issue #4135 · jekyll/jekyll