Set global variables inside a Jekyll template - compilation

I have the following defined in my Jekyll config matter:
dir: a-directory/
I now want to have:
dir: a-directory/
images: {{ dir }}images/
However this won't work. One solution is to place this in my template file
{% capture images %}{{ site.dir }}images/{% endcapture %}
The variable images is now available to other points in that file. However it isn't available to any content being compiled in with that file, e.g my actual pages.
Doing {% capture site.images %} would seem the way to sort that, but you can't assign items to the site or page globals outside of the _config and front matter respectively.
Is it possible to achive this kind of global variable stacking?
(please avoid solutions involving changing my directory structure; if there are similar compilers offering more features without a huge change to workflow I'm open)

It seems YAML doesn't directly support concatenation. There are a few workarounds, though:
https://stackoverflow.com/a/23212524
https://stackoverflow.com/a/22236941

Related

Cross referencing algorithms

Scenario
Note: I am using the Java language for this effort.
Consider the following scenario. In a directory hierarchy, there are files that contain "template definitions". These definitions are then "included" by other files containing embedded templating logic. Here are some examples for reference.
A template definition:
_helpers.tpl:
...
{{- define "keycloak.selectorLabels" -}}
app.kubernetes.io/name: {{ include "keycloak.name" . }}
app.kubernetes.io/instance: {{ .Release.Name }}
{{- end }}
...
The details of the defintion are not important. I only care about the existence of the definition, i.e. it's name ("keycloak.selectorLabels") and where it's found (line N of _helpers.tpl).
(Note that the definition includes another defintion.)
A templated file that includes the definition:
service-http.yaml:
...
selector:
{{- include "keycloak.selectorLabels" . | nindent 4 }}
...
Definitions can be included by other definitions, in the same or other template files.
My objective
I want to scan these files to find 1) the definitions and 2) where they are included. I have working logic that collects this information now.
It would then output listings of the following information:
for each:
definition (the containing file and definition "metadata" - name and line found):
list of templated files that include the defintion (file and line(s) where included)
-or- indication that NO references were found for this definition
for each:
templated file:
list of definition inclusions (definition "metadata" and line(s) where included)
What I need help with
I'm trying to find or figure out an algorithm to do this "cross referencing" described above. I'm sure that with some trial and error I could come up with something that works (no saying how long it'll take or how well it would work), but am wondering if anyone has ideas or information about existing algorithms that do this kind of thing.
I tried to see if I could Google something, but not really sure what search terms to use. The things I did try didn't help.

reStructuredText Abstract appears in front of title, otherwise not recognized

Intro
I use (Python) Sphinx to create my personal homepage. It is a collection of technical articles and lately I notices that I write articles that are more of a blog type. Still I like to have a hierarchy other than a linear timeline of posts.
I was trying to get a RSS feed plugin to work and realized that this needs proper document meta data to work properly. There are bibliographic fields and there it says:
When a field list is the first non-comment element in a document (after the document title, if there is one), it may have its fields transformed to document bibliographic data.
First Try
So I assumed that I can do the following and get it right:
.. Copyright © 2014-2016 Martin Ueding <dev#martin-ueding.de>
###################################
The Idiosyncrasies of Bash's quotes
###################################
:Date: 2014-07-13 00:00:00
:Abstract:
The Bash shell has many quirks and takes a lot of time to master. The Fish
shell has a cleaner syntax but is not installed on many systems. The quote
idiosyncrasy of Bash is presented.
Rendering this gives the following:
Missing is the output of the document meta data. I added some little snippet to the template:
{% if meta is defined %}
<p>
{% for key, val in meta.items() %}
{{ key }} → {{ val }} <br />
{% endfor %}
</p>
{% endif %}
{% block body %} {% endblock %}
The Date and Abstract fields just get converted to a table. This is okay-ish for humans but does not help much in feed generation as I need a hard date.
Second Try
So perhaps my interpretation of “after the document title, if there is one” is wrong. So I now did the following:
.. Copyright © 2014-2016 Martin Ueding <dev#martin-ueding.de>
:Date: 2014-07-13 00:00:00
:Abstract:
The Bash shell has many quirks and takes a lot of time to master. The Fish
shell has a cleaner syntax but is not installed on many systems. The quote
idiosyncrasy of Bash is presented.
###################################
The Idiosyncrasies of Bash's quotes
###################################
And there one sees that the meta data is picked up nicely:
However, the abstract is in front of the title! This is a deal-breaker as this just does not look right. I like that my actual div.abstract CSS styling is now used.
Tried So Far
A workaround would be to just move the Date field up such that the RSS feed extension can pick up the date. Then in the theme I would have to somehow put in the date on the page. Or I duplicate it such that it is in a human-readable form in the table below the title and another copy before the title. This way I could control when updates to the RSS feed happen.
Alternatively I could add the title again in the template because I have the title variable there even if the title comes below this meta data table. Then I would need some CSS to remove the second <h1> from the page such that it looks like I want it. But that seems like a kludge and will break without CSS (which I guess is not too much of a requirement, otherwise the title will be duplicated).
Removing the copyright comment does not change anything, either.
Open Question
Is there a better way? Can I have the title first and still get Sphinx to pick up the meta data correctly?

Jekyll: Including markdown files as variables to be {{ include.variable }} within the main markdown file

The reason for the include inside an include is to help remove the majority of html from new users who want to edit the markdown not familiar with HTML and CSS. I have tried to include twice but there is a syntax error.
Original-document.markdown
{% include template-document.markdown variable={% include To-add-document.markdown %} %}
Template-document.markdown
{{ include.variable }}
To-add-document.markdown
**Filler markdown text etc.**
I am not sure if it is possible to set markdown file as a variable, an alternative I have found on stackoverflow is to use collections. However all my values are unique and have different values. The current alternatives are to generate more markdown files with inbuilt values or combine HTML with Markdown. Both become messy for users.
Is it possible to include markdown files as variables?
UPDATE:
I managed to solve it by making the variable a string which is the directory to the file.
Original-document.markdown
{% include template-document.markdown variable="To-add-document.markdown" %}
Template-document.markdown
{% include {{ include.variable }} %}

Just show up some posts on a jekyll blog if a YAML Frontmatter variable is set to a specific value

I am currently working on a static blog based on Jekyll and GH-pages.
At the top of my post overview site I do have a section where I would like to place some featured blogposts.
I could probably add the value "featured" to the "tags" in the YAML Front Matter of those posts and insert the line:
{% for post in site.tags.featured %}
Nevertheless I am one of those complicated guys who don't like to stick to the first solution that came in mind (although it probably might be the easiest one).
My idea was to add a new variable featured to my YAML Front Matter and label with the values yes or no (same thing here: yes, I do know that true and false would be easier but I like to be able to transfer the solution to another problem) if it is a featured content (and should be shown in this section) or if it is not.
That might be an easy solution for a jekyll expert but I am pretty new to that kind of static site generator and would love to hear your ideas.
If you assign featured: true or featured: yes, this filter will work :
{% assign featuredPosts = site.posts | where:"featured", true %}
A {% for post in featuredPosts %} will then do the trick.
Note : all the Truthy and Falsy in Liquid are not working in the actual Jekyll.

Including variables in jekyll from given file

I want to have my variable assignments placed in a single txt file or similar in jekyll, and have them included in my Front Matter for assignment. So instead of this:
---
variable1: abc
variable2: 123
---
I can have this:
---
{% include variables.txt %}
---
The purpose of this is to have a website that is editable by a technologically inexperienced client. I want to abstract out the core site structure from the things that need to be edited as much as possible - without setting up a CMS, or moving into a dynamic site (so it can still be hosted on github pages)
You could just throw all of your variables into your _config.yml file and then they can be accessed like this:
{{ site.variable1 }}

Resources