Jekyll multiple post types - jekyll

I'm currently building my new personal website and I'm trying out Jekyll, now I was wondering what the best way is to get multiple post types.
I basically want to have 2 categories: blog and work
I was looking up some ways and one way was to just create folders for each specific category
- work
-- _posts
--- portfolio01.md
--- portfolio02.md
- blog
-- _posts
--- blogitem01.md
--- blogitem02.md
This way seems to work just fine.
After checking if this was the correct solution I found another one, this basically suggested to use subfolders inside the _posts folder and then define a category in the post itself.
- _posts
-- blog
--- blogitem01.md
--- blogitem02.md
-- work
--- portfolio01.md
--- portfolio02.md
Both methods seem to have the exact same output, is there any real difference in this?
Method one seems to be easier as you don't have to set a specific category inside each post.

They are both the same. They are both perfectly valid.

- work
-- _posts
--- portfolio01.md
--- portfolio02.md
- blog
-- _posts
--- blogitem01.md
--- blogitem02.md
This approach will automatically assign categories to your posts. The portfolio01.md and portfolio02.md posts will automatically be assigned the work category. The blogitem01.md and blogitem02.md will automatically be assigned the blog category.
- _posts
-- blog
--- blogitem01.md
--- blogitem02.md
-- work
--- portfolio01.md
--- portfolio02.md
This approach will not automatically assign categories to any of your posts. You can specify the categories manually in the Front Matter of each post.
If you aren't using categories, then both approaches do the same thing.

Related

Implementing a glossary in Jekyll

Am porting a doc site from Madcap Flare to GitHub Pages using Jekyll. One thing I'm wondering about is that is there a way of implementing an automatic glossary similar to Flare's:
https://www.madcapsoftware.com/blog/guest-post-madcap-flare-101-7-the-glossary/
In summary: I want to have a glossary file comprised of terms and definitions. Then if a term occurs in a topic, it automatically becomes a link or pop-up link to the definition.
If anyone has done this or knows a way to do it I would appreciate it.
Yes, this is possible. Pop-over elements are also possible but I have chosen the link example.
This plugin can create links to the glossary:
module GlossaryData
def glossary
self['glossary']
end
end
module Jekyll
class GlossaryLinkGenerator < Generator
def generate(site)
site.data.extend(GlossaryData)
glossary_terms = {}
site.data.glossary.each do |entry|
glossary_terms[entry['term'].downcase] = entry['definition']
glossary_terms[entry['term']] = entry['definition']
end
# pages
site.pages.each do |page|
glossary_terms.each do |term, definition|
page.content = page.content.gsub(term) do |match|
"<a href='/glossary.html##{term}'>#{term}</a>"
end
end
end
# posts
site.posts.docs.each do |post|
glossary_terms.each do |term, definition|
post.content = post.content.gsub(term) do |match|
"<a href='/glossary.html##{term}'>#{term}</a>"
end
end
end
# Notes
# For all content, use site.documents instead of the two code blocks for posts and pages above
# The site.documents attribute is an array of all the documents in your site,
# including pages, posts, and any other collections that you have defined in your configuration.
# You can use this attribute if you want to apply the glossary link generator to all types of documents in your site.
# You can also use site.collections[COLLECTION_NAME].docs if you want to apply it to a specific collection of documents.
# Just replace COLLECTION_NAME with the name of the collection you want to use.
# You can also use site.collections['posts'].docs for the posts instead of site.posts.
# site.collections is a hash of all the collections defined in your site's configuration,
# and each collection has a 'docs' attribute that returns an array of all the documents in the collection.
# This is useful if you want to apply the glossary link generator to a collection other than 'posts',
# or if you want to apply it to multiple collections.
end
end
end
Define your glossary in _data/glossary.yml:
- term: Jekyll
definition: A static site generator written in Ruby.
- term: Liquid
definition: A template language used by Jekyll to generate dynamic content.
- term: Markdown
definition: A lightweight markup language used to format plain text.
The test page to see that the glossary is working:
---
layout: post
---
jekyll or Jekyll? Both are matched due to downcasing.

Is it possible to create a single file for a collection?

I have a set of pages that are pretty similair, only a few attributes differ. In the collection docs it says I should create a single document for every item, like this:
_my_collection/
└── some_doc.md
└── more_doc.md
but that is not very convinient, I would rather create a single yaml-file with all the content in it:
my_collection.yaml
my_collection:
some_doc:
attribute_1: foo
attribute_2: bar
more_doc:
attribute_1: foo
attribute_2: bar
Is this at all possible?
I ended up using a really neat extension called data_page_generator
it can make pages out of yaml and csv and works out of the box.
UPDATED FOLLOWING QUESTION CLARIFICATION:
Not if you want to output pages. The file is the trigger to build a page. Except, as you point out, with a plugin/extension - which will not work on github.
Yes, if you are just referencing the values. Use something like:
{{site.myCollection.collectionFile.some_doc.attribute_1}}
Although this is probably better done as a data file inside your _data folder with something like:
{{site.data.myDataFile.some_doc.attribute_1}}
You can loop through values too in a file too - though be aware about how hash and arrays differ when you structure your file.

Applying multiple layouts to same collection item in jekyll

I have a jekyll collection _persons, with multiple peoples' profiles. Now I want to create multiple layouts for each person, e.g., a "Publications", and a "Bio" subpage for the same person.
How can I associate different layouts with the same person object? I'd also like to use sub-urls, such as:
\personA\publications\
\personA\bio\
Assuming that "bios" are the content type that you will be editing, you might create a symlink in your project root from _bios to _publications:
# Unix/Linux
ln -s _bios _publications
If you use windows, you'll need to check out mklink.
Then set up your config.yml like this:
collections:
bios:
output: true
publications:
output: true
defaults:
-
scope:
path: "_bios"
values:
layout: bio
permalink: /biographies/:title/
-
scope:
path: "_publications"
values:
layout: publication
permalink: /publications/:title/
Edit markdown files for your people in the _bios directory, and do not specify layout or permalink in their frontmatter.
When your site builds, you'll get permalinks like example.com/publications/personA and example.com/bios/personA. You can loop through site.publications and site.bios as usual.
You'll need to define the bio and publication layouts, and these will have access to any data you define in the frontmatter of your bio collection items.
Credit for this idea: https://github.com/jekyll/jekyll/issues/3041#issuecomment-267730851
It might be more semantic to have a collection _persons as a single point of truth and make two symlinks from this collection.
Good luck!

Is there a way to add another variable to site object in jekyll?

I'm creating a blog just to dump my notes in. I love how far I can go with site.tags and site.categories. All I really need now is the ability to have another filter option. Something li site.sublog it would help me create exactly what I need
So here's a post
---
layout: post
title: "Angular.js With Codeschool:part five"
date: 2015-05-14 07:57:01 +0100
category: [Angularjs-codeschool, basics]
tags: [angular with codeschool]
sublog: [web]
---
Basically I want to write notes on everything I am interested in: web, general tech, history ... and sort of create sub blogs
There are ways around it but now that I am here I just wanted to know if such a thing was possible
Categories and tags are treated specially by Jekyll, so you won't find that other front matter entries from a post will be collected into a site-wide variable like site.categories and site.tags are.
The Jekyll documentation has a tutorial on retrieving items based on front matter properties, which shows how to iterate over an entire collection and do some per-item processing based on a front matter variable's value.
You could iterate over your collection, inspecting the sublog values of each item and concat-ing them to a list of all known sublog values (perhaps removing duplicates using uniq afterwards, and optionally sort-ing them before further processing).
This would enable you to create a list of all sub blogs, and for each sub blog, create a list of posts within it (which is presumably your end goal).
You can store Sitewide information + configuration settings in _config.yml.
Your example shows Page specific information in the YAML front matter!
Read the Jekyll Documentation, please.

How can I have articles in Wintersmith not in their own subdirectory?

In Wintersmith, the default blog template generates posts from content/articles/<article>/index.md. This is fine as it allows associated files like images to be included with the article. But in practice, most "blog posts" are just text content associated with a template. Having to create subdirs is a minor annoyance, and if editing multiple entries in a tabbed editor, it's annoying having everything named index.md.
The site generator will spit out articles/basic-post.html files, but does not include these in the generated index or archive pages. How can I get the latter to work without breaking anything?
This may or may not be a simple problem, but I'm new to Wintersmith and haven't seen how to do this. I'm not sure it's as trivial as editing the default paginator (and I am not that used to CoffeeScript, which maybe it's time to address that :)
In paginator.coffee:
getArticles = (contents) ->
# helper that returns a list of articles found in *contents*
# note that each article is assumed to have its own directory in the articles directory
articles = contents[options.articles]._.directories.map (item) -> item.index
articles.sort (a, b) -> b.date - a.date
return articles
This looks like the place, however it seems like a bad idea to directly edit a plugin, for potential future updates to work.
Wintersmith is pretty awesome btw.
You were right: theanswer lies into the paginator plugin.
Wintersmith will constently watch the contents folder, building a ContentTree array.
That objet array will contain a descriptor for each file and folder within contents.
The getArticles just filter this possible candidates, and you just need to enhance it to get plain markdown files in the contents/articles folder.
getArticles = (contents) ->
# helper that returns a list of articles found in *contents*
# include articles with dedicated directory
articles = contents[options.articles]._.directories.map (item) -> item.index
# add articles that are in the *contents/articles* folder
articles = articles.concat contents[options.articles]._.pages
articles.sort (a, b) -> b.date - a.date
return articles