Make kramdown's ALDs available on entire Jekyll site - jekyll

I'm using Jekyll to make a site that makes frequent use of kramdown's attribute list definitions. However the only way I can make this work right now is to include all of the definitions in every page e.g.
{:def1: ...}
{:def2: ...}
{:def3: ...}
This seems really smelly to me since if I want to change a definition, I need to do so in every single page. Ugh.
Is it possible to put these definitions somewhere where they will be included in every page? I tried putting them in a layout but it seems that Jekyll won't parse markdown in layouts.
I'm also open to alternatives to ALDs if this is not the right way to go about things.

If you want to add definitions to your posts, you can also create an .md file in your _includes folder with definitions like:
*[def1]: ...
*[def2]: ...
And then you can add this file to every post using {% include definitions.md %}.

It shouldn't be in the _layouts folder. Try keeping it in the _includes folder and then include it with this tag {% include definitions.html %}

Related

Why the jekyll is not running?

Hello I have a problem with my blog homepage (https://igorkowalczyk.github.io/blog) does not work, but normal posts such as (https://igorkowalczyk.github.io/blog/categories/offtop) do work.
I don't even know what the problem is.
I suspect that it's a problem with index but I don't know exactly.
Someone knows maybe for what it does not work?
Your IgorKowalczyk/blog/index.md uses paginator.posts, which should be working only in HTML files, not md (markdown files).
The categories/offtop.html is an HTML file, properly rendered/generated by Jekyll.
The pagination logic should not sit inside the content files (e.g. individual post or document files). It belongs in the layout files.
If you place markdown code into your layout or include files you will have to explicitly pass it through the markdownify filter.
My recommendation is to keep your content (e.g. blog posts) in .md files (which will only contain markdown syntax) and everything dealing with the structure of your site in .html files (which will only include HTML syntax).
The OP MAJO mentions in the comments having to restore the right content for the index.html file: commit ac2ad43

Jekyll link within page

I'm using Jekyll on Github, and I wonder whether there's a way to link to a section within a page. Say I have a section like
## Section 1 ##
section content
and later in the same page I want to link to this section. I've found how to link to another page within the blog and do footnotes, but not this.
As a note, I use markdown: kramdown in my _config.yml
kramdown supports the automatic generation of header IDs if the option
auto_ids is set to true (which is the default). This is done by
converting the untransformed, i.e. plain, header text
So in the above example ## Section 1 ##, it would generate the following id: id="section-1", then the anchor is linked to via the A element:
Section One
Or in plain kramdown/markdown: [Section 1](#section-1)
It seems that this has been changed to #heading-section-1 (checking on Jekyll 3.7.3 right now).
As a way to figure this out on your own, you can inspect the element and see the id being used on the rendered page.
I found a nice repository that helps add anchors to all headers in three simple steps.
From docs:
Download the anchor_headings.html file from the master branch
Toss that file in your _includes folder
Where you typically would put {{ content }} in your layout,
you would instead use this Liquid tag to output your page's content:
{% include anchor_headings.html html=content anchorBody="#" %}
As result you will see:
Which is easy to customize.
If the section of the page you want to jump to is not a section heading, then this accepted answer didn't work for me. The following worked for me:
[jump](#final-solution)
<div id="final-solution"></div>

Directly copy some Pelican templates to output folder

I have a few new templates in my pelican theme (a growing number of them, really). They are html files that hold simple web maps. I use these by {% include %}ing them after the content of a blog post. I place the path to the webmap1.html template in the markdown metadata, and then in article.html I {% include %} the web map html at the bottom of the file.
Thing is, I really would like to have these html files available as standalone html in my output as well. Initially I thought I'd be able to do this by placing webmap1.html in my content directory and using STATIC_PATHS to copy it to the output. However, I was unable to get the include statement to find an html file that is not within the theme/templates directory.
I also found that adding /theme/templates/maps or ../theme/templates/maps to STATIC_PATHS didn't work.
Of course, one way to do this would be to include identical files in both the content directory and the template directory, but that seems sloppy. Alternatively, I could add a command to pelican to copy the files from one place to another before the generation happens. Looking for an alternative solution though.
Thanks!
Well, turns out I was outsmarting myself with this. All I needed to do was use the
DIRECT_TEMPLATES = [
r'maps/webmap1',
]
setting in pelicanconf.py. That way, I can {% include 'maps/webmap1.html' %} in a separate template, and also write it to its own standalone location in the output directory.

Django translations inside included HTML template

I am including a file in a Django webpage using this:
{% include 'footer.html' %}
This included HTML file contains trans tags, which are not being translated. In fact, Django returns a TemplateSyntaxError:
Invalid block tag: 'trans'
I know that the include tag does not process the included file. I've seen other questions ask about overriding blocks in included files, to which the answers mentioned that this is not possible in Django. I presume this is the same problem.
Is there a way to force Django to process included files, or some other tag that achieves this? Or maybe Python code, as a last resort?
Important note: I cannot simply add the footer in a base file and extend from this base, because I already have a base, which is actually the one trying to include footer.html (I have several base templates for different sub-sites, but all of which should use the same footer).
inside footer.html you need to load i18n
{% load i18n %}
quote from the docs:
As with all template tags, this tag needs to be loaded in all
templates which use translations, even those templates that extend
from other templates which have already loaded the i18n tag.

A static blog generator with multiple image directories

Question: what software should I use to achieve a static site generator like described below?
I'm looking for a static blog generator, which... generates static blogs, of course :). However I need something more, like a nice set of themes to choose from, and, what is even more important, a specific way of managing assets.
When I write articles/posts/text, I create a new directory. Then inside I have a file like article.md, or article.textile. I also have files with code, and pictures, and charts etc. Everything is inside this one directory. Then I used to run a tool to convert it to html, and copy the html to a website for publishing. However there was always a problem with images. I had to copy the images somewhere e.g. to Wordpress and then change the image urls in the html. This is not the best way to do it.
I'd like to have a static blog generator, which would let me keep my normal structure: one directory per post, and keep all the images from the directory in generated structure, so I can have relative paths to the images.
I really don't like the idea to keep all articles in one global directory, and all images in another global one.
I've checked jekyll, and pelican so far, and read about couple others, but I haven't found any solution to that problem. I know that, as usually, you will have many nice ideas to check.
And of course I know that most probably this post will be "closed and not constructive", or with any other funny explanation, but maybe someone will manage to post any solution before that.
Hugo can do this. cd to empty folder of your choice, then
create the scaffolding:
hugo new site .
After that you can put your content in content, example:
content
post
alpha
index.md
1.jpg
2.jpg
bravo
index.md
1.jpg
2.jpg
Build site:
hugo
Result is generated in public folder:
public
post
alpha
index.html
1.jpg
2.jpg
bravo
index.html
1.jpg
2.jpg
Jekyll does not explicitly enforce a rule about where to put your assets like images with the exception that Jekyll will not copy files directly in a folder beginning with an underscore. Although the general practice would be to put all images in the \assets\ directory, you can put it anywhere else other than the _posts\ directory, which is what you wanted.
This is the default behavior, but there are ways to get around this:
Have your posts live outside the _posts directory
Put all your posts outside the default _posts folder along with the images (this will copy all the files without any YAML frontmatter, and preprocess all the files with the YAML frontmatter). However, any other function you can do with posts automatically in Jekyll won't work anymore. This may or may not be an issue.
Plugins
Here's a plugin (link to SO question) written specifically for making Jekyll copy files in the post directory. If you do use this you can definitely just write the following Markdown and it'll link relative to the post as it should. :
![Image title](my_image_filename.png)
Jekyll asset path plugin is another robust plugin that does something similar, but does not keep your images in one directory, it does however link images relative to your post title though.
Jekyll asset pipeline is another another plugin that handles CSS and JS, which might be something you want to have in conjunction with plugin 1.
Do note however that the use of third party plugins is not supported with GitHub Pages site generation, meaning you will have to generate them in another branch or locally, and then pushing the static HTML files to master. This might be an issue for you if you're planning to host with GitHub Pages, else on your own server instance you're good to go.
I also want my posts to be "self contained", text content and image assets being in one single folder. I'm using Jekyll.
I have made this possible with a Pull Request on the great jekyll-picture plugin.
I can then use the simple {% picture my-image.png %} syntax to show the image in my post that is in the same folder.
Here is an example: https://github.com/nhoizey/nicolas-hoizey.com/tree/master/_posts/2015/06/19-mon-jeu-esviji-integre-a-framagames
One year after my previous answer, I have now developed a Jekyll plugin that helps keep posts assets alongside the Markdown file, it might fill your needs: https://nhoizey.github.io/jekyll_post_files/