I have a bunch of documents in a collection that when developing, are more easily identified by their 'title code' which is why it would be best to use it as their filename (it helps keep a structure and order). Something like this:
_stories
CH1S1.md
CH1S2.md
CH2S1.md
However, for the pretty urls, a slug from the document's title is better. From the docs it seems that just using the :title permalink parameter is exactly what I want, but the output always uses the document's filename (as if it was using :name instead of :title).
Here is my collection definition in _config.yml:
collections:
stories:
output: true
permalink: /:collection/:title/
Of course, in each individual document's Front Matter I am setting the title property, so I am not sure why this is not working.
I am on the latest version of Jekyll.
Try to set the permalink, instead of title, in YAML Front Matter of each file like this:
permalink: /stories/mystory/
Related
I'm using jekyll-seo-tag to automatically create meta-tags for my Jekyll blog posts.
Each post on my blog has a tags property in its front matter, which are used in its search system:
---
tags: [how, to, do, this, that, those]
---
I want these tags to be included in the meta-tags of the generated HTML, through jekyll-seo-tag.
How can that be done?
This is a pretty niche problem, but... I run a blog that runs on Jekyll and I post very regularly. To keep my editing sane I regularly archive posts, and those archived posts get a pretty strict structure. But, I go a full year before archiving.
Where this hurts is in links to other posts. I used to be able to absolutely reference the file name (per jekyll markdown internal links), but this appears to be being deprecated:
Deprecation: A call to '{% post_url 2018-09-06-peppermint %}' did not match a post using the new matching method of checking name (path-date-slug) equality. Please make sure that you change this tag to match the post's name exactly.
Now, if I have to include the full path to the file, then when I archive my posts for the year I have to parse all of the posts for the entire year and update any links between them to include the new file path for their archived location, defeating the point of using this tool at all. A direct link to the page would actually be better, given that I change my URL structure less often.
Is there a better solution for internal links that doesn't depend on the file structure, allowing a file to be moved without having to update every link to that file?
Example File structure:
_posts
-2018
-post1
-post2
-etc
-Archive
-2017
-2016
If there's no better answer, I may just have to go back to using absolute external links.
Solution 1. Use your own include
Create an post_url.html file and write this:
{% include post_url.html slug="2018-09-06-peppermint" %}
The include (called post_url.html) should find the post with the right slug and echo the link, like this:
{% assign link = site.posts | where:'slug',include.slug %}
{{ link[0].title }}
Solution 2. Search and replace
You have to parse posts? A simple search and replace on all files, looking for (/2018/ and replace with (/Archive/2018/ should do the trick (if you use markdown links). This should take just a few seconds.
I reedit my posts all the time and the dates don't mean anything so I want to remove them from the posts' titles (not from the titles of the markdown files).
By title I take that you mean the url segments which contain the date + the post title. If so:
you can specify the permalink to Not contain the date on post basis (front matter) like so:
---
title: My new post
permalink: /:title/
---
or if you want this to apply to posts, use it in _config.yml:
permalink: /:title/
There are also other predefined permalinks here, and their components (slugs) can be used in the customization above.
I have a site that has a lot of markdown files sorted into appropriate folders.
Jekyll creates their HTML versions and the TOC (table of contents) automatically.
In the _config.yml file I can rename some folders, rearrange them (e.g., if I don't want them sorted alphabetically).
I went through their documentation (http://jekyllrb.com/docs/home/) and I did not see a way to hide a file/folder from the TOC. I hope I have missed something.
What I want is to hide some folders and files from the TOC, but keep them live so people with the correct URL can still read the articles. As to why - legacy stuff I don't want people to find by themselves, but old links must still work and I must keep the information online.
Thus, I cannot use the published: false approach in the heading of the markdown file itself, as this will bring it offline.
Here is an example of my config file:
"someFolderWithChildren":
title: "Name of my folder"
position: 10
"someFolderWithChildren/child-folder-I-want-hidden":
title: "hidden folder 1"
published: false
visible: false
noToc: true
hidden: true # these did not work (I admit to guessing in frustration a lot)
"someFolderWithChildren/another-folder-I-want-hidden":
title: "hidden folder 2"
position: 8
"someFolderWithChildren/folder-i-want-in-the-toc":
title: "some live folder"
position: 1
"someFolderWithChildren/folder-i-want-in-the-toc/child-folder-i-want live":
title: "yet another live foder"
position: 0
I really hope someone can point me in the right direction.
EDIT: to answer the comment and answer - I do not use posts, I am afraid, I am tied with other types of content. Further digging showed that the TOC tree is actually a custom JS widget and it seems I need to look into the way its data source is generated by the existing plugins. Thank you for your assistance and your time.
Well, depends what you exactly want. If you just want to have a unpaginated list of all your posts (TOC), then you a are fine and that can be done easily. But if you want a paginated list, you might be comfortable with a workaround.
Without paginator
In your index.html modify {% for post in site.posts %} to
{% assign posts = site.posts | where:"hide", "false" %}
{% for post in posts %}
...
and add a entry hide:[true,false] in the yaml-header of your posts. You can work with front matter defaults so you just have to set hide:false in the posts you want to exclude.
With paginator
First of all, up to now (Jekyll 2.5.3) and to my knowledge there is no possibility to filter the output of the paginator without using a plugin. But as far, as i remember things might change in the upcoming versions of jekyll.
I would recommend, to work with a collection of documents for the posts that should not show up. Collections are rendered like posts (if you pass the same layout to the collection), but since the paginator only works on posts your documents (posts) in a separate collection won't show up in the paginated list of posts as rendered by the paginator.
I hope, i could help...
It turned out that the site i had had a custom plugin that goes through all md files, creates a list for the TOC and serializes it to a json file that is then used by a client-side treeview widget (kendo ui, btw) for its data source. So, i ended up with a few lines of ruby code that skipped adding the folders i want hidden to that json.
While that worked for me, i see the idea in the posted answer and it is perhaps the way to go in a more oob scenario.
I am building an octopress blog. In that blog, a number of entries have footnotes. The markdown files currently denote a footnote like so:
"This is the main text <footnote>and this is the footnote</footnote> where
we speak of main-text things"
What I want to do is extract the footnotes from the body text and then have access to both the main text AND the footnotes as variables in the layout.
I've made some progress with this by creating a filter but it doesn't work very well because filters always output directly on return and I need to format the footnotes.
Would a generator be more appropriate? A converter? Should I not be using liquid tags at all in this case?
Filters make the most sense to me. Is there a way to get the return value of a filter without it printing to the screen? I currently use this:
{{ content | footnotes }}
But that just dumps the array as one big, unformatted array. If it isn't blindingly obvious already, I'm just getting started with Liquid and I'm a little confused.
Depending on your markdown parser you could just write the footnotes normally in the markdown. This is what I'm using on my blog. This is my config in the _config.yml file:
markdown: rdiscount
rdiscount:
extensions:
- autolink
- footnotes
- smart
Then I just use footnotes by using [^1] to specify the footnote and
[^1]: My footnote
To show it at the bottom of the screen.
Or are you trying to show footnotes at some other part of the screen and not at the bottom of the post?