Search code examples
jekyllgithub-pagesbase-url

Setting BaseURLs per subfolder with Jekyll (GitHub Pages)


Is there a way to append a specific value to site.baseurl in different subfolders? For instance, I have two different subfolders each using a specific language (lang), and I want to append this value to site.baseurl for pages and documents in the subfolder. So for example,

  • A.md in subfolder lang1 would have the BaseURL of /my_site_url/lang1/, and
  • B.md in subfolder lang2 would have the BaseURL of /my_site_url/lang2/.

Is this possible with GitHub Pages, without build+serving my site locally beforehand?

Edit : I need BaseURLs for managing a Navigation Bar that goes through all individual pages in a subfolder. In such a case, prepending site.baseurl with the subfolder appended beforehand would be the most economic choice?


Solution

  • _config.yml

        baseUrl: /sub
        lang1Url: /lang1
        lang2Url: /lang2
    

    nav.html, footer.html

        <li><a href="{{ site.baseUrl }}{{ site.lang1Url }}/index.html">Home - lang 1</a></li>
        <li><a href="{{ site.baseUrl }}{{ site.lang2Url }}/index.html">Home - lang 2</a></li>