I have a folder hierarchy like this:
movie scripts/
Independence Day.md
Alien.md
The Omega Man.md
books/
fiction/
Dune.md
Childhood's End.md
nonfiction/
Unended Quest.md
software/
Photoshop.md
Excel.md
You get the idea.
My goal is to use Jekyll to generate a static non-blog site that lets me browse HTML versions of all my Markdown files. So the navbar would have Movie Scripts
, Books
, and Software
on it. Clicking Books
would unfurl two submenus, Fiction
and Nonfiction
, and clicking one of those would show all pages in that folder.
I've read Jekyll's documentation and watched the Pluralsight course on it, and I know how to render pages from a pages folder... but I can't quite work out how to create navigation from this directory structure.
Could anyone give me some tips? Is this something Jekyll natively supports, or will I have to write something that generates the output myself? Where do I start with this?
Instead of hard-coding navigation links, you can programmatically retrieve a list of pages to build the navigation for your site. Although there’s already information about interacting with data files in other Jekyll docs, this tutorial dives into building more robust navigation for your site.
Provided that the file has a front matter section, it will be transformed by Jekyll. The same will happen for any .html, .markdown , .md, or .textile file in your site’s root directory or directories not listed above.
Since version 3.2 , a new Jekyll project bootstrapped with jekyll new uses gem-based themes to define the look of the site. This results in a lighter default directory structure: _layouts, _includes and _sass are stored in the theme-gem, by default.
The Jekyll engine will autoload all data files (using either the .yml , .yaml, .json, .csv or .tsv formats and extensions) in this directory, and they will be accessible via `site.data`. If there's a file members.yml under the directory, then you can access contents of the file through site.data.members .
I'm sure there will be many approaches, but I would use Jekyll collections.
If is your first time, I will be very detailed:
Configure Collections on your _config.yml file
collections:
movie-scripts:
output: true
books:
output: true
software:
output: true
Add folders to the root of the project directory (same name as each one of the collections)
_movie-scripts
_books
_software
Create subfolder for each categorie. For e.g.:
_movie-scripts/sci-fi
_books/fiction
_software/Jekyll
Add the markdown files to each of the collection’s subfolders.
Note: You should use also the Front-Mater to create categories that you might need to filter or search in the future.
Add a folder _data and create 3 YAML files with all the data for your movie-scripts, books and software. For e.g the movie-scripts.yml:
- title: Back to the Future
image-path: /images/movie-scripts/back-to-the-future.jpg
url: http://www.imdb.com/title/tt0088763/
short-description: This is a 1980s sci-fi classic about traveling through time
year: 1980
categorie: sci-fi
- title: Star Wars
image-path: /images/movie-scripts/start-wars.jpg
url: http://www.imdb.com/title/tt0076759/
short-description: Star Wars is an American epic space opera franchise centered on a film series created by George Lucas
year: 1977
categorie: sci-fi
Create 3 HTML's pages to access your 3 collections (movie-scripts, books and software). For e.g. the movie-scripts, the 10 most recent additions to your site:
---
layout: page
permalink: /movie-scripts/top-ten/
---
{% for movie in site.data.movie-scripts limit:10 %}
<li>
<img src="{{ movie.image-path }}" alt="{{ movie.title }}"/>
<a href="{{ movie.url }}">{{ movie.title }}</a>
<p>{{ movie.short-description }}</p>
<p>{{ movie.year }}</p>
<p>{{ movie.categorie }}</p>
</li>
{% endfor %}
Advice: If this is your first time, do baby steps. Try to do the first colection first, step by step, run the Jekyll server at each time and see if works, go to the next step...
Let me know if it help you, please!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With