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.
Related
I am using Jekyll, writing both drafts and posts. I have many drafts (hidden) but only a few finished posts (published).
$ tree
...
├── _drafts
│ ├── <a bunch>
...
├── _posts
│ ├── <a few>
I would like to show the number of drafts (currently in _drafts) without publishing their contents.
This requires accessing "draft post" data in Liquid (Ruby), and while site.posts is defined, site.drafts is not.
How can I programmatically access drafts, without preprocessing?
One potential solution is:
Move all drafts from _drafts to _posts. This way, they can be accessed via site.posts.
In the YAML front matter of drafts, add tags: draft.
In Liquid: filter out all posts with tag draft from being displayed, but count their number.
This solution should work fine, but I'd like to keep drafts separate from posts somehow so that they can be distinguished at a glance. Maybe adding a _posts/drafts subdirectory is the best-of-both solution.
I'm using Jekyll for my blog. I want to protect some blog post with a password and I've decided to use Staticrypt.
I can encrypt the index.htmlpage of one of my blog post with the Staticryp CLI and my custom password_template.html. It outputs a index_encrypted.html.
My question is: Where do I put the index_encrypted.html? I can't add it to the _site since Jekyll return the build to default everytime I serve it.
I tried adding the index_encrypted.html to the _includes folder and calling the page from the .md post like this:
{% include index_encrypted.html %} but this just break the page.
Thank you!
I figured out how to do it.
Here's what I did:
Put the index_encrypted.html in _includes and _layouts
Add a permalink: /index_encrypted.html in front matter of the .md post you're targetting.
Add a layout: index_encrypted in front matter of the .md post you're targetting.
Delete the whole markdown content of the .md post.
Voila!
You front matter should look like this:
---
title:
date:
tags:
description:
layout: index_encrypted
permalink: "/index_encrypted.html"
---
Edit: Make sure to create a copy of your .md post for later use.
I have a project where I have posts on main page of the blog and I would love to have another posts folder inside subfolder(s).
I am talking about this structure:
_posts
_posts/2020-04-04-Testmain.md
subpage/_posts
subpage/_posts/2020-04-04-Testsub.md
subpage/index.html
index.html
I can access posts from subpage by using {% for post in site.categories.subpage %} inside subpage/index.html but I can't find a way how to force jekyll to also generate posts in the subpage folder so I can access it at page http://127.0.0.1:4000/subpage/testsub
Is it even possible? Or is it better to follow this structure?
_posts
_posts/2020-04-04-Testmain.md
_posts/subpage
_posts/subpage/2020-04-04-Testsub.md
If so, is there some setting required to make the post at http://127.0.0.1:4000/subpage/testsub ?
Found the solution!
In _config.yml you can use permalink: /:categories/:title
And with following file hierarchy:
_posts
_posts/2020-04-04-Testmain.md
subpage/_posts
subpage/_posts/2020-04-04-Testsub.md
subpage/index.html
index.html
You will get these websites:
http://127.0.0.1:4000/
http://127.0.0.1:4000/subpage/
http://127.0.0.1:4000/subpage/testsub
And you can still access all posts from selected subfolder with {% for post in site.categories.subpage %}
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.
I'm having a hard time configuring permalinks for my blog posts. The way I have my blog set up is root/news/index .
I set my _config.yml to "./" so all my articles are on the same directory as my news index.html. But whenever I click on my article's permalinks on the news homepage, it redirects me to "mysite.com/article" instead of "mysite.com/news/article". I've also tried "./news/" but it only creates another news folder inside my original news folder. I've also tried the setting "pretty" but it still goes to "mysite.com/.." not "mysite.com/news/..."
In the _config file you can change the permalink to anything you like, for example mine is
permalink: /blog/:title
As for the date you can choose your own date using the YMAL front matter, again in mine i have
title:example date: you can pick what ever date you want
So in your case I would try this
permalink: /news/:title