Skip to content
This repository has been archived by the owner on Mar 16, 2022. It is now read-only.

remove the "/" from the page URL #40

Closed
tomjoht opened this issue Aug 4, 2015 · 9 comments
Closed

remove the "/" from the page URL #40

tomjoht opened this issue Aug 4, 2015 · 9 comments

Comments

@tomjoht
Copy link

tomjoht commented Aug 4, 2015

I'm making my jekyll site relative, and designed to be deployed in a subdirectory off of a domain. This poses some problems with Jekyll-Search's ability to format correct links in the results.

When I click on a search result, the URL prepends a forward slash, like this:

/pageresult.html

As a result, the page doesn't load because I have my jekyll site in a directory such as domain/folder/subfolder/

When I click /pageresult.html, it goes to this:

domain/pageresult.html

instead of:

domain/folder/subfolder/pageresult.html

How can I remove the "/" before the page result? If the result would simply go to pageresult.html, it would load the page.

In the script, the searchResultTemplate shows this:

   searchResultTemplate: '<li><a href="{url}" title="{{page.title}}">{title}</a></li>',

I tried to determine how {url} gets populated from jekyll-search.js, but I couldn't see how to apply any kind of filter to remove the "/". Can you help? Thanks,

Tom

@christian-fei
Copy link
Owner

Hello,
I will look into it, thanks for submitting.
Could you pass me a sample jekyll _config.yml plz?

@tomjoht
Copy link
Author

tomjoht commented Aug 4, 2015

Sure, do you want me to email that file to you? I don't have any permalink setting in my configuration file, since I'm not using permalinks in this project. Everything is coded with a relative URL (because the same project might be pushed into different server folders or domains). As such, I don't think the configuration file will have any particularly interesting information.

@tomjoht
Copy link
Author

tomjoht commented Aug 10, 2015

Christian, I'm just following up on this issue. Did you have any solutions for me? Thanks.

@christian-fei
Copy link
Owner

Hello,
i'm sorry for letting you wait.
In thery you just need to set the baseurl property in _config.yml of your jekyll site, the url is something the plugin does not handle (or know what it is actually).

As a matter of face, you can check it out on this very example of this repository

Please tell me how it goes,

thanks

@tomjoht
Copy link
Author

tomjoht commented Aug 10, 2015

Thanks. But I'm not using the baseurl for my Jekyll site. I have a
technical documentation site, and I shift around the directory where it's
published. If I were to specify a baseurl in the configuration file, it
would lock me into always publishing it in that folder. In short,
everything is relative.

I just need to somehow modify the {url} property in the plugin. This is the
problematic part:

searchResultTemplate: '

  • <a href="{url}"

    title="{{page.title}}">{title}

  • The {url} value that gets inserted has a forward slash, such as
    /sample.html instead of just sample.html. How can I remove that forward
    slash? You said the url is something the plugin does not handle or know
    what it is. Is this url value coming from the page.url from Jekyll's
    universal tags?

    In other places in my theme, I used this replace filter to get rid of the
    slash:

  • [email protected]
    wrote:

    Hello,
    i'm sorry for letting you wait.
    In thery you just need to set the baseurl property in _config.yml of your
    jekyll site, the url is something the plugin does not handle (or know what
    it is actually).

    As a matter of face, you can check it out on this very example of this
    repository
    https://github.com/christian-fei/Simple-Jekyll-Search/blob/master/_config.yml#L8

    Please tell me how it goes,

    thanks


    Reply to this email directly or view it on GitHub
    remove the "/" from the page URL #40 (comment)
    .

  • @christian-fei
    Copy link
    Owner

    Always removing the slash would not be wise.
    I will add the option to specify a baseUrl inside the JS plugin, does this make sense?

    @christian-fei
    Copy link
    Owner

    Please check this out and tell me what you think and if it works for you:
    https://github.com/christian-fei/Simple-Jekyll-Search#templatemiddleware-function-optional

    @tomjoht
    Copy link
    Author

    tomjoht commented Aug 10, 2015

    Awesome. Thanks for addressing this issue!

    However, I realize now that I'm an idiot. I didn't realize that the {url}
    value was set with the search.json file:

    "url": "{{ page.url | replace: '/','' }}",

    I just added the replace filter there.

    This actually fixes my problem. I just didn't communicate the issue very
    well, and when I originally looked in the .js for where that url value was
    coming from, I couldn't make sense of things. So it turns out this is a
    rather easy fix. Thanks so much for your help.

    Tom


    blog: idratherbewriting.com
    twitter: tomjohnson
    408-540-8562

    On Mon, Aug 10, 2015 at 3:08 PM, christian-fei [email protected]
    wrote:

    Please check this out and tell me what you think and if it works for you:

    https://github.com/christian-fei/Simple-Jekyll-Search#templatemiddleware-function-optional


    Reply to this email directly or view it on GitHub
    #40 (comment)
    .

    @christian-fei
    Copy link
    Owner

    Aaaalright, now it makes sense :)
    No problem, glad you're using the plugin!

    Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
    Labels
    None yet
    Projects
    None yet
    Development

    No branches or pull requests

    2 participants