Hello-
I’m trying to publish a middleman site to Github Pages (specifically, the pages branch of a project repo), but I’m having difficulty getting the site to build links relative to a subdirectory (gh-pages requires your path to include /repo-name/
at the beginning of all links).
This is my first time working with Middleman. I’m coming from the Jekyll world, so I’ll try to explain what I’m attempting in Jekyll terminology.
In Jekyll you can define a variable called baseurl
in your config, which allows you to specify what path (if any) should come before your links when the site builds. As long as links in templates are written in the format of {{site.baseurl}}{{page.url}}
things work fine. You’d set baseurl
to your repo name for a standard GH-Pages workflow, but you could just change it to /
if you were going to publish the site to the root folder of a server instead. Best of all, the development server would respect baseurl
too, so you could view your site at localhost:4000/repo-name
without things breaking.
I’m trying to essentially do the same things in Middleman, but I’m having trouble figuring out how to make this happen.
In my templates, I’m using link_to
helpers and asset tags. In config.rb
I have the following set globally:
activate :directory_indexes
set :relative_links, true
And for the :build
environment, I have the following:
configure :build do
# Relative assets needed to deploy to Github Pages
activate :relative_assets
end
When I build the site, the asset tags for CSS and JS output relative links as expected. But my link_to
links in the navigation are still coming out as absolute paths.
I’m expecting this in haml:
=link_to "Introduction", "/frontmatter/introduction"
to become something like:
<a href="../../../frontmatter/introduction">Introduction</a>
on an interior page. (I’m also using directory indexes if that makes any difference).
But instead the links I’ve created with link_to
helpers all remain in this format:
<a href="/frontmatter/introduction">Introduction</a>
Am I doing something wrong? Alternatively, is there a way in Middleman to set something equivalent to a baseurl
variable that I prepend my links with?
Thanks and apologies for the long post!