I need to include raw text from a bunch of files inside a Jekyll collection. I don't want to process them in any way, I just need to dump the raw text using a collection. It feels like the following should work:
---
layout: default
---
{% for item in site.fragments %}
{{ item.content }}
{% endfor %}
I have declared the collection in the _config.yml file, like so:
collections:
- fragments
Surprisingly, the output of item.content is not the raw text inside the file, but rather the processed HTML that results from running Jekyll on top of the file.
Clearly I must be misunderstanding something fundamental, since stitching together text files should be trivial for a text processor like Jekyll.
Related
In my current Jekyll setup I am writing all my posts using the asciidoc (.adoc) file format, specifically I'm using these plugins
plugins:
- jekyll-asciidoc
- jekyll-redirect-from
- jekyll-feed
I am in need to create a custom HTML component which I have added in component.html under the _includes folder, following the includes feature of Jekyll.
I am able at the moment to use Liquid in a Markdown file to render the HTML component by just using
{% include component.html %}
at any point in my posts, but I can't do the same with asciidoc files. I've taken a look at their documentation and I can't find a suitable way to make use of this Jekyll feature.
Is there a way to use Liquid in asciidoc?
After a little bit of research I've found a couple of things with which I was able to inject _includes HTML components in an asciidoc file.
jekyll-asciidoc has a special page attribute to enable Liquid preprocessing, you can find the docs at :page-liquid:
So, in order to enable Liquid preprocessing you just have to add this to the asciidoc post
:page-liquid:
With this, Jekyll is going to parse every Liquid statement in your file before actually passing it to the asciidoc generator.
The post needs another little change at this point, citing the docs:
If you’re using the Liquid include tag to include HTML into the AsciiDoc document, enclose it in a passthrough block.
++++
{% include file.html %}
++++
By default :page-liquid: will escape Liquid generated content, which is why you need to enclose the {% include ... %} statement in the asciidoc Passthrough construct ++++ that is going to inject raw HTML into the page itself.
In conclusion, this is what an example post should look like:
_includes/component.html
<p>Some sample text</p>
_posts/liquid-in-asciidoc.adoc
---
title: "HTML component in adoc
---
:page-liquid:
++++
{% include component.html %}
++++
I am using Jekyll + Liquid + Markdown to generate static html pages. Consequently, this is really a question specific to the Jekyll framework and Liquid template generator because there is syntax that conflicts with Liquid in some of my Markdown files.
Is there a quick and dirty work-around I can use for the time being in order to prevent Liquid from parsing certain files?
Use Raw:
Raw temporarily disables tag processing. This is useful for generating content (eg, Mustache, Handlebars) which uses conflicting syntax.
{% raw %}
In Handlebars, {{ this }} will be HTML-escaped, but
{{{ that }}} will not.
{% endraw %}
I have a Jekyll project and I'm trying to implement multilingual functionality.
My data files were stored in _data/my_data.yml, and accessed in the templates via the {% for data in site.data.my_data %} Liquid template tag.
I have now copied and translated my data files into _data/en/my_data.yml and _data/it/my_data.yml and created two .md files, using the same template, with respective lang attributes in the front matter.
I am trying to dynamically access the correct data based on this lang attribute however it's throwing all sorts of errors.
Things I've tried
{% for data in site.data.[page.lang].my_data %}
{% for data in site.data[page.lang]my_data %}
{% for data in site.data.{{page.lang}}.my_data %}
Any ideas?
In case anyone runs into this in the future, solved it with pretty much the only combination I hadn't tried yet:
{% for data in site.data[page.lang].my_data %}
I have a collection of css files I combine into one with Jekyll. This is very easy:
{% for file in site.css %}
{{ file }}
{% endfor %}
However, there is a special case where I want to include just a single one of those files. The pages.css file.
site.css is a collection, so I simply put all my css files in a folder called _css and in _config.yml added:
collections:
css:
output: false
I was able to include only the _css/pages.css files using {{ site.css | where:"title", "Pages" | first }}. But I was wondering if there is a nicer way of doing it. Something like {{ site.css/pages.css }}
Is there a way to do it like that? Wihtout a where and first clause?
For the exception I would use an if statement and not loop over the files.
However, I would consider cache while using this solution. If one pages uses 'superlargecombined.css' and another one uses 'superlargecombinedcsswithoutonepart.css' the client needs to download them both (fully). That is in not an optimization. If you keep your css files seperated they can be cached and will be downloaded once, independent of your page css configuration. Combining things that always need to stick together is a good solution though (to minimize requests), but note that with HTTP2 the need to minimize requests will reduce drastically.
Hope this helps!
I'm trying to use GitHub Pages for my project's documentation, but it includes generated html files that turn out to have illegal liquid tags. I don't need any expansion beyond the _layout itself, but as far as I can tell, any {% ... %} tags in the articles' content themselves are also evaluated and there seems to be no way to suppress this, other than adding {% raw %}...{% endraw %} around the entire contents of every single article.
Is there any way to do this at the call site? Something along the lines of {{ content | unrendered }} would be excellent.
Note: this seems to be the opposite problem to many others, who are using page.content in a pre-render context and wanting it to be rendered; I've tried page.content but as far as I can tell it's exactly the same in my case, so no dice.
page.content was raw in the jekyll 2.x era. Now its rendered content.
You can use a hook plugin to add a page.raw field on any page.
Jekyll::Hooks.register :pages, :pre_render do |document|
document.data['raw'] = document.content
end
If you want to do the same on posts and collections items, use a documents hook :
Jekyll::Hooks.register :documents, :pre_render do |document|
Note :
In :pre_render hooks document.content contains raw content
In :post_render hooks document.content contains rendered content