Category templates in Jekyll - jekyll

On my site, there will be two types of posts: blog and portfolio. I want to have a page for each of these categories, displaying only posts from that category.
What is the best way to achieve this in Jekyll? I've done some homework but I'm struggling to find a good answer.

If you put the post into folder posts and portfolio, jekyll will naturally defined two categories
root
|-- posts
| `-- _posts
| |-- 2012-01-12-post.textile
| `-- 2012-03-22-post.textile
`-- portfolio
`-- _posts
|-- 2011-04-05-post.textile
`-- 2012-02-02-post.textile
Then you can have a generator that will create the category page, you may then take inspiration from this post: http://www.justkez.com/generating-a-tag-cloud-in-jekyll/ except that instead of generating the tag page, you generate the category page.
EDIT
There is also this plugins generate_category.rb that can help you: http://recursive-design.com/projects/jekyll-plugins/

Related

Setting permalink: none still results in date in URL for Jekyll

I'm trying to set up Jekyll based blog posts on my site, but running into trouble styling the URLs how I'd like (<site URL>/blog/<blog title>). Based on the documentation here, I should be able to do this by either doing permalink: none and setting the category to blog or by doing permalink: /:category/:title or permalink: /blog/:title in my _config.yml file, but none of these produces the desired result, with even the none preset just giving me /blog/2022/06/22/<blog title>.html
Any ideas what I'm doing wrong?
As far as I know, there isn't a way to introduce a string in the permalink like that.
However, you can try forcing all your posts to have a category blog thus allowing you do use permalink: /:categories/:title. To do that you can move your posts directory inside a blog directory. That'll tell Jekyll that all posts there are part of the blog category:
$ tree .
├── blog
│   └── _posts
│   └── 2022-06-23-welcome-to-jekyll.markdown
[…]
A problem with that approach is that other category names will appear in the final URL as well. For example, I created a default Jekyll site (with jekyll new test), changed the permalink definition in _config.yml and moved the posts directory like above. The resulting permalink for the default post is:
http://localhost:4000/blog/jekyll/update/welcome-to-jekyll
If you don't care about categories, or if having some posts get extra categories but everything being contained in /blog, this should work.

Relative links (to headings) in mkdocs with markdown_include.include

I'm not sure it's even possible to solve this problem - but I'd ask anyways:
I'm working on a python project using mkdocs for the documentation.
The project structure (simplified) looks roughly like this:
./
|-- docs
|-- index.md
|-- page2.md
└-- [other documentation stuff]
|-- [the actual program stuff]
|-- README.md
└-- mkdocs.yml
I'm using the markdown_extensions markdown_include.include (declared in the mkdocs.yml),
and the index.md consists only of the line {!README.md!} to include the markdown file at this place.
This works nicely, displaying the README.md as the overview page of the docs.
The problem I ran into now is that in the README.md, I want to have a statement "For more detail, see XY", where XY should be a link to a heading in page2.md in the docs.
With mkdocs, I can simply write see [here](page2.md#heading2), and that works perfectly in the docs. But when I look at the README.md directly (e.g. on github), that gives me a 404.
When I put see [here](docs/page2.md/#heading2), it works from the README.md, but not in the docs created by mkdocs.
Is there any good way to work around this? Help would be much appreciated!

Jekyll site.categories is empty

I have tried this code {{site.categories | inspect}} in default.html, but it returns empty space like this {}.
My post has a front matter that includes categories: apple.
What have I missed?
oh i found..
My jekyll theme post was referenced from 'docs' folder, but jekyll said every posts should be placed in _post folder. so jekyll site variable could not read categories of posts in docs folder.

In Jekyll is there an easy way to change an output path for a folder with html

I am using Jekyll for some static site templates and I have a folder of product html pages which I want to be bundled into the root site/ folder rather than into a site/products folder.
example below with just 2 product pages:
src folder
src/products/123.html
src/products/146.html
output to site
site/123.html
site/146.html
Is there an easy way to do this?
Additionally would there be an easy way to append products- to each file in this folder?
site/product-123.html
site/product-146.html
Try looking into Jekyll collections. You'll specifically want the Permalink feature. Hopefully the following snippet will get you started.
config.yml
collections:
products:
output: true
permalink: /product-:title/
source tree
_products
|
1.html
2.html
3.html
...
output tree
_site
|
product-1
|
index.html
product-2
|
index.html
product-3
|
index.html
...
This creates the "pretty permalinks" structure where file endings are removed by using index.html within a directory of the correct name. Of course you could set it to create the "ugly permalinks" (project-1.html, etc), but I like this style more.

Show pages under one folder in Jekyll?

I think the native way of managing pages of Jekyll, i.e. by creating .md file / folders under the root folder, is a bit messy.
Thus I want to put, every page I want to show, into the folder called "pages". Additionally, I'd like these pages to have a cascaded structure: say if my folder has the structure:
pages
|-> parent1
|-> index.html
|-> son1.html
|-> son2.html
|-> parent2
|-> index.html
Then in the pages-listing page, it should be something like this:
page listing
* parent1
* son1
* son2
* parent2
And additionally, the other *.html file, which are not under pages folder, should not be shown in this page-listing page.
How should I do that?
Thanks a lot.
There is nothing preventing you from doing so. In the above scenario, yourdomain.tld/pages/prent1/son1.html would be the URL of the parent1/son1 file.
Creating a nested listing, however, will be more complicated. You could either epscify that structure in the YAML Front Matter, or use posts.
pages
|-> parent1
|-> _posts/
|-> index.html
|-> son1.html
|-> son2.html
|-> parent2
|->_posts
|-> index.html
=> That way your files would be posts in the categories parent1 and parent2 and you could create the listing by displaying the categories and their contents.
If you really want to display a tree structure without using posts and categories, then you will need to do more black magic. But fortunately, Liquid offers a split filter which you could use to split the path of the site into chunks, e.g.
{% for page in site.pages %}
{{ page.url | split:'/' | join:'+'}}
{% endfor %}
Instead of joining them (this is purely for demonstartion), you'd want to populate an array which holds the tree structure and then later on iterate over that array to display the directory tree. It is possible, but not easy. And i don't think there is something readily available.
Probably writing a plugin is easier.