Redirects in Jekyll

Hi, what is the easiest way to create a redirect on gh-pages?

I have seen that there is a plugin: https://github.com/jekyll/jekyll-redirect-from

But I wonder if it would be easier to create a new varaible at _config.yml and (I do not know how but) use it in the code like the twitter_username: xtwitter_account.

I want to have a link on the index page, just like the about page, but with a redirect:


layout: page
title: Acerca de
permalink: /about/

Thanks for your help

what exactly do you want to happen? a user lands on the page and they automatically get a different page? for what purpose? just trying to make sure we understand.

Jekyll itself cannot do that - usually this is something you would do thru your server/host. I use AWS S3 and it has a redirect ability.

Thanks Rdyar,

Not as you said, sorry. They do not get redirected once they land, they get redirected if they click on a link so they can use a service. Imagine that there is a link on this page (or Jekyll site) to make a donation and you want it to show on the top of your site and all the pages, because it is important for you. I hope you understand why I want to do it (though my need is not a donation link, but something else harder to explain).

that just sounds like a regular link to me… I think what you are asking is how to have it next to the link to the About page in the main nav?

what theme are you using? should be easy, just look thru the layouts or includes and you can see how they are built - unless of course you are using a gem based theme in which case none of those are there by default, you would need to add them.

Do you have a link to your repo?

strong text

If I use a link like

<div class="trigger"> <a class="page-link" href="https://www.worldometers.info/coronavirus/">Corona </a> </div>

next to the About link in the index.html, it does not show when I commit to github.

where was that file? inside the _site folder? if so that is not where you need to edit it, that is where jekyll puts stuff that it creates, so nothing you do there will show on GH.

You need to find in the theme where it is building the main navagation. Your link above is to your site not the repo.

If you are building locally, you need to get the theme files into your repo so you can edit them - most likely you are using a gem based theme which means the files are hidden from you.

Check this:

I think you need to edit: _includes/header.html but not positive. Looks like you can add a page to the main nav that is on the site - but I think an external link needs to be added into the actual nav section.

Sorry, about that.

Yes, that’s the point. Is there an easier way to create a link than creating a new page layout? Where is the Abou link created? Can it be modified? i have no _includes yet (the worokthrought is pretty clear if I do not mess it: https://www.youtube.com/watch?v=bDQsGdCWv4I&list=PLLAZ4kZ9dFpOPV5C5Ay0pHaa0RJFhcmcB&index=12)

Thanks for your help

right -that video is sort of on track - but what you should really do is copy the theme file into your repo (rather than starting from scratch) and then just edit it.

I think you need the header.html file that goes inside _includes.

So make a folder in your repo called _includes, and then do bundle info --path minima and see if it will show you where the hidden theme files are. If so go to that directory and copy the header.html file and paste it into the _includes folder you just made in your repo.

Then you just need to figure out how to edit it - I think that is the correct file, but I am not very familiar with themes. Try just putting some placeholder text in it and see where it shows up.

If you cannot locate your local files google jekyll minima theme and you should be able to find the repo for the theme on GH, then locate that file and copy it into your _includes folder.

Following your instructions, I created the _includes dir, copied the headers.html and do bundle info --path minima to find my hidden theme files: C:\ruby26-x64\lib\ruby\gems\2.6.0\gems\minima-2.5.1 and copy the header.html (as you said, same as https://github.com/jekyll/minima/blob/master/_includes/header.html)

One problem is that the theme does not really work as they say in the documentation: https://github.com/jekyll/minima#customize-navigation-links (There is no header_pages: about.md in the _config.yml file which would be a great solution.)

Now, I’m stuck in the figuring it part. What should I use? I would like to delete the whole thing and just leave the part for the header, but I’m not quite sure. Here is the header.html code, without any comments :frowning:

<header class="site-header">

<div class="wrapper">
{%- assign default_paths = site.pages | map: "path" -%}
{%- assign page_paths = site.header_pages | default: default_paths -%}
{%- assign titles_size = site.pages | map: 'title' | join: '' | size -%}
<a class="site-title" rel="author" href="{{ "/" | relative_url }}">{{ site.title | escape }}</a>

{%- if titles_size > 0 -%}
  <nav class="site-nav">
    <input type="checkbox" id="nav-trigger" class="nav-trigger" />
    <label for="nav-trigger">
      <span class="menu-icon">
        <svg viewBox="0 0 18 15" width="18px" height="15px">
          <path d="M18,1.484c0,0.82-0.665,1.484-1.484,1.484H1.484C0.665,2.969,0,2.304,0,1.484l0,0C0,0.665,0.665,0,1.484,0 h15.032C17.335,0,18,0.665,18,1.484L18,1.484z M18,7.516C18,8.335,17.335,9,16.516,9H1.484C0.665,9,0,8.335,0,7.516l0,0 c0-0.82,0.665-1.484,1.484-1.484h15.032C17.335,6.031,18,6.696,18,7.516L18,7.516z M18,13.516C18,14.335,17.335,15,16.516,15H1.484 C0.665,15,0,14.335,0,13.516l0,0c0-0.82,0.665-1.483,1.484-1.483h15.032C17.335,12.031,18,12.695,18,13.516L18,13.516z"/>
        </svg>
      </span>
    </label>

    <div class="trigger">
      {%- for path in page_paths -%}
        {%- assign my_page = site.pages | where: "path", path | first -%}
        {%- if my_page.title -%}
        <a class="page-link" href="{{ my_page.url | relative_url }}">{{ my_page.title | escape }}</a>
        {%- endif -%}
      {%- endfor -%}
    </div>
  </nav>
{%- endif -%}

When I commit the _includes/header.html the whole navbar disappears.

When referring a README on GitHub, always checkout the tag of the version you’re using.
In your case, it would be v2.5.1: https://github.com/jekyll/minima/tree/v2.5.1#customize-navigation-links


The header_pages: [about.md] is documentation. You need to edit your config file and add those lines yourselves.


Lastly, since this thread is about redirection, have you taken a look at the following plugin:

 <div class="trigger">
      {%- for path in page_paths -%}
        {%- assign my_page = site.pages | where: "path", path | first -%}
        {%- if my_page.title -%}
        <a class="page-link" href="{{ my_page.url | relative_url }}">{{ my_page.title | escape }}</a>
        {%- endif -%}
      {%- endfor -%}
    </div>

I think this is the part that adds the nav links, assuming it is the same version like ashmaroli says, so try:

 <div class="trigger">
      {%- for path in page_paths -%}
        {%- assign my_page = site.pages | where: "path", path | first -%}
        {%- if my_page.title -%}
        <a class="page-link" href="{{ my_page.url | relative_url }}">{{ my_page.title | escape }}</a>
        {%- endif -%}
      {%- endfor -%}
<a href class="page-link"="">Test</a>
    </div>

You could also just download the minima theme and then add your content to it and not use it as gem based. I personally don’t like the gem based themes as they are not easily edited. You would need to figure out what stuff to strip out (well, you can just copy the stuff you have locally when you located all the gem files), usually not too hard to do. or search for other non-gem based themes and use one of those.

The header links feature looks to only be for local pages - not external links which is what you need if I understand your question.

with it just as you have above?

@rdyar The author seems to have resolved their issue: