In Jekyll's Front Matter, is there a way to make references to another document?
I have a custom collection, and would like to add meta-data in each document such as "parent-topic" (a link to the parent), and "children" (an array of documents), or "related-topics".
With such a reference I could access the linked documents' meta-data, such as their title, url, or other arbitrary data.
The idea is a hierarchy of documentation, with topics, sub-topics, sub-sub-topics, etc. And a topic page could show a list of child topics, or a breadcrumb for the parent topics, etc.
Real question that deserve a real answer. I also got this documentation problem. Following advise from Ben Balter, I started to use
collections
. The idea was to makeI gave up because it was simplest to code against
pages
. So, here's how I do documentation with pages.Prerequisites :
documentation is in a folder eg : documentation
permalink
is set topretty
in _config.ymlfolders hierarchy describes documentation organization
example
Note :
documentation/chapter-2/part-2/index.html
can also bedocumentation/chapter-2/part-2.html
, becausepermalink
is set topretty
, generated page will be atdocumentation/chapter-2/part-2/index.html
.weight
front matter variable. This can be anything you want. Numbering by tenth allows easy insertion for new doc.example front matter
_config.yml
example
Once those prerequisites are in place, it's easy to print a table of content and a breadcrumb.
Table of content
_includes/show-children.html
Use
This include can be called with several arguments :
dir : root dir to explore (ie : /documentation)
docs : an array of pages - default to site.pages
level: level at which we start printing (/documentation is at level 1, /documentation/chapter-1 is at level 2, and so on) Default to 'dir' level
maxLevel: where to stop to print - default to 100
On page layout if you just want to print page children you can do :
Breadcrumb
_includes/breadcrumb.html
_includes/get-parents.html
Use
Print
Documentation > chapter 1 > part 1
Print
Chapter 1 > part 1
Can it be more simple ?
Working code can be found here.