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.
Related
I want to extract the pages mentioned in the infobox and templates of pages.
E.g. From this page:
https://en.wikipedia.org/wiki/DNA
I want to extract all of the links in the infobox, like: "Genetics", "Introduction to Genetics" etc.
I want to do it, by using the sql dumps, possibly avoiding to parse the xml of whole pages, and I don't want to do it with APIs.
I could not find a way.
While Pagelinks does include also the links of infoboxes, I cannot find a way to exclude them.
I thought Templatelinks may have that info, but it is not: I could not find the pageids of the corresponding links in infoboxes.
Where is this information stored?
Or which kind of tables should I look at?
I consulted previous questions:
where can I find the infobox templates used in wiki?
and Mediawiki reference:
https://www.mediawiki.org/wiki/Manual:Templatelinks_table#Schema_summary
but could not find a solution.
That is a sidebar rather than an infobox: https://en.wikipedia.org/wiki/Template:Genetics_sidebar
I don't think there's a way of doing it other than parsing the content of the template to extract the links or using the API: e.g. https://en.wikipedia.org/w/api.php?action=query&prop=links&titles=Template:Genetics%20sidebar&pllimit=100&plnamespace=0
Something like this should also work but it's not returning any results for me:
SELECT * from pagelinks
where pl_title = 'Genetics_sidebar'
and pl_namespace = 0
and pl_from_namespace = 10
https://quarry.wmcloud.org/query/71442
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.
My github jekyll structure looks like next:
after I enter _posts and create .md file, it looks like:
the corresponding code is:
Generics were introduced to the Java language to provide tighter type checks at compile time and to support generic programming.
The generics looks like:
```Java
List<String> list = new ArrayList<>();
//add item to list
String s = list.get(0);
```
or
```Java
public class Box<T> {
// T stands for "Type"
private T t;
//other code
}
```
The most commonly used type parameter names are:
```
E - Element (used extensively by the Java Collections Framework)
K - Key
```
We can see that the format is nice, such as it has syntax highlight.
I called it preview page
However, when I enter into my page by typing my github page url to see, it likes:
I called it real page
We can see that real page looks bad, e.g. there is no syntax highlight, there are multiple borders for quoting code syntax etc.
Thus, how to make the real page format is the same as preview page?
I suppose that you're relatively new to Jekyll so I have to do some clarification to you.
The result that you call "preview" is the result of your markdown parsed by GitHub. All markdowns have something in common so it's very likely that even if your parser is different almost all the things are parsed similarly. You could see a difference at the beginning of your "preview": the yaml content is displayed as a table.
Let's come back to Jekyll. If you're using the default settings, the parser of your code is kramdown (you could change it in the _config.yml file). When you execute Jekyll, it builds your website. That means that it parses your markdown and convert it to HTML. How it converts to HTML depends on a lot of things based on your configuration and plugin installed.
By default, you have no highlight. If you want to change it, take a look at the jekyll documentation. By default, it uses Rogue but you can also use Pigments or some other highlighter of your choice.
I don't think that this answer covers all your doubts and certainly not all your problems but it's to let you understand that your question, as it was posted, have not so much sense since your "preview page" and your "real page" are two completely distinct things. So google a bit, find what you want to achieve and ask a new question (you will surely have one in the near future).
Happy coding!
I am new to html/css but am attempting to create a blog using Jekyll and this theme I found here https://github.com/rosario/kasper
The homepage index.html has the all the posts in a paginated list. This is cool. However i would like to group my posts into different categories and have an additional page for each group which would have a paginated list of just posts of that groups.
I can create the additional pages but can't get the lists using any sort of variant of the code in index.html but specifying a group.
Is this possible?
There is also another way to do that. Is using Jekyll Collections.
For each collection you can have a _folder containing your markdown files. Then you can call your posts within this folder from whatever page you want.
To do so, you will need to: 1st. add your collections to your _config.yml file:
collections:
example1:
permalink: /example1/:path/
example2:
permalink: /example2/:path/
example3:
permalink: /example3/:path/
2nd. create a folder to each collection, like: _example1, _example2 and _example3
3rd. create a new html file from which you call each collection:
{% for article in site.example1 %} ... {% endfor %}
That's it! I hope to have helped. If I have, please mark this answer as useful. If you need more assistance, feel free to contact me.
You should share your code with your answer if you want a more detailed answer for your question. As far as I understood you are having trouble with creating a list of blog posts that are all same category. If this is correct then you can achieve it by using liquid for loop. If you look into the code on your index.html it has this for loop
{% for post in paginator.posts %}
If you modify it like below
{% for post in site.categories.comedy %}
Where comedy is a category name. This way we access the category within the site object and get all the posts under this category. If you place similar loops on your separate pages while changing the category names you can have different category lists on different pages. Make sure that you correctly input the category names in your post's front matter. If I succeeded in answering your question please mark the answer as correct.
I'm writing template documentation for a wiki and wanted to include a working example of the template. However, I wrote the template to auto-categorize various fields and the entire template itself is also auto-categorized.
This means if I simply call on the template, it will categorize the doc page...and because the actual template page transcludes the doc page, the template page will also be categorized.
Is there a way to prevent these categories from automatically kicking in?
Something like the following should do the trick. Wrap the categorization in your template inside a parserfunction:
{{#ifeq: {{NAMESPACE}} | Help || [[Category:Some_Category]] }}
This sets the category when the template is transcluded onto a page that is not in the "Help" namespace.
Another option is to allow a parameter such as demo to avoid including the category.
If you don't mind being slightly cryptic, you could do the category in the template as {{{cat|[[Category:Some_Category]]}}}; then specifying the parameter as {{my template|cat=}} will prevent the category inclusion.
I'm not sure if I understand the question completely (what is "auto-categorize various fields"?). I am assuming here that you want to show a template "in action" on a documentation page - without attaching some categories (those categories the documentation page usually attaches to articles using this template) to the documentation page.
So
<onlyinclude>[[Category:Some_Category]]</onlyinclude>
will not do the job - as the template is in fact included. Right?
Try passing a parameter categorize=false to the template to indicate that categories are not to be attached in this case:
{{#ifeq:{{{categorize|}}}|false||[[Category:Some_Category]]}}
The double pipe after "false" means: if(categorize==false) then (empty), else [[Category:Some_Category]] - i.e. it is an equivalent construction for if(NOT(categorize==false))...
Good luck and thanks for all the fish,
Achim