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

Handle '//' (double slash) caused by baseurl: '/' #6057

Closed
0xdevalias opened this issue Apr 29, 2017 · 2 comments · Fixed by #6058
Closed

Handle '//' (double slash) caused by baseurl: '/' #6057

0xdevalias opened this issue Apr 29, 2017 · 2 comments · Fixed by #6058

Comments

@0xdevalias
Copy link

@0xdevalias 0xdevalias commented Apr 29, 2017

  • I believe this to be a bug, not a question about using Jekyll.
  • I updated to the latest Jekyll (or) if on GitHub Pages to the latest github-pages
  • I read the CONTRIBUTION file at https://jekyllrb.com/docs/contributing/
  • This is a feature request.

  • I am on (or have tested on) macOS 10+

My Reproduction Steps

To start off with, I realise that setting baseurl to / is the wrong way to do it, but in reality, it seems it is often done, and sometimes seems to be the only way to workaround other bugs/things:

I figured that with the relative/absolute filters added in 3.3 there was now a standard/universal place to fix this in a way that would make the end user experience easier, while possibly also hinting them towards not using the 'bad method'

# _config.yml
baseurl: "/"

# default.html
<h1>{{ "/docs/assets/" | relative_url }}</h1>
<h1>{{ "/docs/assets/" | absolute_url }}</h1>

Outputs

<h1>//docs/assets/</h1>
<h1>http://localhost:4000//docs/assets/</h1>

The Output I Wanted

<h1>/docs/assets/</h1>
<h1>http://localhost:4000/docs/assets/</h1>

This could be achieved by using a regex/similar to strip off any trailing/leading slashes before concatenation.

For what it's worth, the hacky filter I used in my theme to work around this was:

module Jekyll
  module ChompSlashFilter
    def chomp_slash(input)
      input.chomp('/')
    end
  end
end

Liquid::Template.register_filter(Jekyll::ChompSlashFilter)

But this obviously doesn't let me work around it when it comes up in other plugins.

It would also be reasonable to expect a warning from Jekyll about how using / in baseurl is a bad idea/why, and how to do it better/properly (maybe a link to a blog post about it or similar).

@0xdevalias 0xdevalias changed the title Handle '//' caused by baseurl = '/' Handle '//' caused by baseurl: '/' Apr 29, 2017
@0xdevalias 0xdevalias changed the title Handle '//' caused by baseurl: '/' Handle '//' (double slash) caused by baseurl: '/' Apr 29, 2017
0xdevalias added a commit to 0xdevalias/devalias.net that referenced this issue Apr 29, 2017
@ashmaroli

This comment has been minimized.

Copy link
Member

@ashmaroli ashmaroli commented Apr 29, 2017

but in reality, it seems it is often done

I assumed this to be an edge-case circa this comment. Sent a PR to handle this.
Do stay tuned.

@0xdevalias

This comment has been minimized.

Copy link
Author

@0xdevalias 0xdevalias commented Apr 29, 2017

Thanks :) I added some inline comments to your PR

cirosantilli added a commit to cirosantilli/cirosantilli.github.io that referenced this issue Jun 10, 2017
cirosantilli added a commit to cirosantilli/cirosantilli.github.io that referenced this issue Jun 10, 2017
cirosantilli added a commit to cirosantilli/cirosantilli.github.io that referenced this issue Jun 10, 2017
@jekyll jekyll locked and limited conversation to collaborators Jul 11, 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.

3 participants
You can’t perform that action at this time.