Managing Jekyll Pages in Folders (on github-pages)

Viewed 910

I have a Jekyll website hosted on GitHub Pages. Now I am having so many pages and I would like to manage them in a folder called _pages. I ideally want to have this structure:

root
  |-> _pages
      |-> Index.md
      |-> contact.md
      |-> cv
          |-> cv.md
          |-> my_cv.pdf
  |-> _posts
  |-> [other things such as config and gemfile]

This I have done defining default permalinks in the _config.yml adding:

include:
  - _pages

defaults:
  - scope:
      path: "_pages"
      type: "pages"
    values:
      permalink: /:basename/ # make URL of pages in the folder _pages as on the root.

That works perfectly.

However, as you see inside the _pages I would like to have another subfolder named cv and put my cv.md and my_cv.pdf in the same folder (in the actual website I have much more of these files for pages.). Ultimately I would like to have a benefit of using [Download my CV](my_cv.pdf) relative local linking, which I suppose because the pdf and the .md file are in the same folder it will recognize it. However it is not the case. cv.md has the permalink of /cv/ and not the cv folder. So when I use [Download my CV](my_cv.pdf) it creates root/cv/my_cv.pdf where this pdf file actually does not exist!

How can I manage to fix this thing? what is your trick?

2 Answers

Unless this is something you plan to roll-out to dozens of sub-directories or dozens of sites, I'd just add the full path to the link. Something like [Download my CV]({{ '/path/my_cv.pdf' | relative_url }}) or [Download my CV]({{ '/path/my_cv.pdf' | absolute_url }}).

Failing that, you could add permalink: /path/where/pdf/lives/ in the cv.md frontmatter. This way they'll both be in the same directory. Of course, this means your cv.md won't build at example.com/cv/.

Related