Static files don't show up in Jekyll - ruby

I'm trying to print my static images in my page following this basic steps in Jekyll documentation:
https://jekyllrb.com/docs/static-files/
My files are in assets/img and my config file has these lines (space indented)
defaults:
- scope:
path: "assets/img"
values:
image: true
I have a Jekyll brand new website. Now in my about.md page I want to print all the images:
{% assign image_files = site.static_files | where: "image", true %}
{% for myimage in image_files %}
{{ myimage.path }}
{% endfor %}
Needless to say it prints nothing.
While I can print {{ site.static_files | inspect }} including all files: fonts, images, zips etc I cannot print image_files variable, nor myimage
What is happening?

In root project create folders assets and img inside assets folder.
Put your image inside img
Example:
myblog
.
├── 404.html
├── about.md
├── assets
│   └── img
│   └── filename.png
In _config.yml:
defaults:
- scope:
path: "assets/img"
values:
image: true
In your posts, ex:about.md, put something like that:
{% assign image_files = site.static_files | where: "image", true %}
{% for myimage in image_files %}
![{{myimage.name}}]({{ myimage.path }})
{% endfor %}

Related

Jinja using a variable as the name of the file used in a Jinja "include"

Within jinja I am trying to pass a variable into the file name used by the "include" for example: {% include = variable1 %}
Something like this:
{% set filepath = ['Templates/file1.j2', 'Templates/file2.j2', 'Templetes/file3.j2'] %}
These are the files:
{% for list in filepath -%}
'{{ list }}'
{% endfor %}
{% set Mypath = filepath[1] %}
This is the path and file to use: '{{ Mypath }}'
{% include "'" Mypath "'" %}
The result I am hoping to achieve should look like this.
{% include = 'Templates/file2.j2' %}.
Is is possible to pass a variable into an include in this fashion within Jinja?

Ansible string concatenation into config file

I have a list of variables ("/dev/sda", "/dev/sdb") which I would like to to dynamically update a config file.
The config file is finally expected to look like
filter = [ "a|/dev/sda[145]|", "a|/dev/sdb[145]|", "a|/dev/mapper/3500.*part1|", "r|.*|" ]
Currently, the config file looks like this.
filter = [ "a|/dev/mapper/3500.*part1|", "r|.*|" ]
I have the answer to my own question. I am not sure if this is the "jinja" way of doing things.
{% set ldsk = [] %}
{% for disk in ldisks %}
{{ ldsk.append( "\"|a"+ disk +"[145]|\"") }}
{% endfor %}
filter = [ {{ ldsk | join(", ") }}, "a|/dev/mapper/3500.*part1|", "r|.*|" ]

Jekyll responsive image plugin won't render

I am using the jekyll responsive image plugin. I have a template like i should, and it can reach the template and the css. It does render a img code, but the path is wrong an it does not render any resized images.
Here is my template:
{% capture srcset %}
{% for i in resized %}
/{{ i.path }} {{ i.width }}w,
{% endfor %}
{% endcapture %}
{% capture class_caption_tuple %}
class="pic caption"
{% endcapture%}
{% capture class_pic_tuple %}
class="pic"
{% endcapture%}
{% if alt %}
{% capture alt_tuple %}
alt="{{ alt }}"
{% endcapture%}
{% endif %}
{% if width %}
{% capture width_tuple %}
width="{{ width }}"
{% endcapture%}
{% capture styled_width_tuple %}
style="width:{{ width }};"
{% endcapture%}
{% endif %}
{% if title %}
{% capture title_tuple %}
title="{{ title }}"
{% endcapture%}
{% endif %}
{% if class %}
{% capture class_pic_tuple %}
class="pic {{ class }}"
{% endcapture%}
{% capture class_caption_tuple %}
class="pic caption {{ class }}"
{% endcapture%}
{% endif %}
{% assign largest = resized | sort: 'width' | last %}
{% if caption %}
<div {{ class_caption_tuple | strip_newlines }} {{ styled_width_tuple | strip_newlines }}>
{% endif %}
{% if url%}
<a href="{{ url }}" target="_blank">
{% endif %}
<img src="/{{ largest.path }}" srcset="{{ srcset | strip_newlines }}" {{ alt_tuple | strip_newlines }}
{{ title_tuple | strip_newlines }} {{ class_pic_tuple | strip_newlines }} {{ width_tuple | strip_newlines }}>{%
if url%}</a>{% endif %}{% if caption %}{{ caption | strip_newlines }}</div>{% endif %}
Here is my config:
responsive_image:
# [Required]
# Path to the image template.
template: _includes/responsive-image.html
# [Optional, Default: 85]
# Quality to use when resizing images.
default_quality: 90
# [Optional, Default: []]
# An array of resize configuration objects. Each object must contain at least
# a `width` value.
sizes:
- width: 255
- width: 510
- width: 1020
# [Optional, Default: false]
# Rotate resized images depending on their EXIF rotation attribute. Useful for
# working with JPGs directly from digital cameras and smartphones
auto_rotate: false
# [Optional, Default: false]
# Strip EXIF and other JPEG profiles. Helps to minimize JPEG size and win friends
# at Google PageSpeed.
strip: false
# [Optional, Default: assets]
# The base directory where assets are stored. This is used to determine the
# `dirname` value in `output_path_format` below.
base_path: assets
# [Optional, Default: assets/resized/%{filename}-%{width}x%{height}.%{extension}]
# The template used when generating filenames for resized images. Must be a
# relative path.
#
# Parameters available are:
# %{dirname} Directory of the file relative to `base_path` (assets/sub/dir/some-file.jpg => sub/dir)
# %{basename} Basename of the file (assets/some-file.jpg => some-file.jpg)
# %{filename} Basename without the extension (assets/some-file.jpg => some-file)
# %{extension} Extension of the file (assets/some-file.jpg => jpg)
# %{width} Width of the resized image
# %{height} Height of the resized image
#
output_path_format: assets/responsive/%{width}/%{basename}
# [Optional, Default: true]
# Whether or not to save the generated assets into the source folder.
save_to_source: false
# [Optional, Default: false]
# Cache the result of {% responsive_image %} and {% responsive_image_block %}
# tags. See the "Caching" section of the README for more information.
cache: false
# [Optional, Default: []]
# By default, only images referenced by the responsive_image and responsive_image_block
# tags are resized. Here you can set a list of paths or path globs to resize other
# images. This is useful for resizing images which will be referenced from stylesheets.
extra_images:
- assets/foo/bar.png
- assets/bgs/*.png
- assets/avatars/*.{jpeg,jpg}
Here is my responsive img caller:
{% responsive_image path: "img/seo_img.png" alt: "Prolike" caption: "Caption." class: "center medium" %}
Here is the image i get.
<img src="/" srcset=" " alt="Prolike" class="pic center medium">
Why is does it render the path as "/"?
And why won't jekyll render the images.

How to create dynamic files?

i´m trying to rename ethernet-interfaces on Linux. Each interface with the name enp0s* have to be eth*. First, i create udev-rules for renaming. that works fine. Secondly i have to create new configuration-files for each interface ( ' etc/sysconfig/network-scripts/ifcfg-eth* ' ). I don´t know, how to create the loop to place parameters in each interface. Can somneone help me?
Thats an extract of my playbook:
- name: Get new interface-names of the new created udev-rules
become: yes
shell: cat /etc/udev/rules.d/70-persisten-ipoib.rules.cfg | egrep -i 'eth.'
register: car
- name: Create new-ifcfg-eth* files
template:
with_items: "{{ car.stdout_lines }}"
register: cat
template: src= roles/configure_network/templates/create_ifcfg.cfg.j2 dest=/etc/sysconfig/network-scripts/ifcfg-{{ item }}
# Template: roles/configure_network/templates/create_ifcfg.cfg.j2
{% for interface in cat.results %}
NAME="eth{{ item.name }}
TYPE=Ethernet
BOOTPROTO={{item.bootproto|default('dhcp')}}
IPV4_FAILURE_FATAL=no
IPV6INIT=no
{% if item.ipaddress is defined %}
IPADDR={{item.ipaddress}}
{% endif %}
{% if item.netmask is defined %}
NETMASK={{item.netmask}}
{% endif %}
{% if item.gateway is defined %}
GATEWAY={{item.gateway}}
{% endif %}
PEERDNS=no
{% if item.dns is defined %}
DNS1={{item.dns}}
{% endif %}
ONBOOT={{item.onboot|default('yes')}}
{% endfor %}
Just fix your syntax:
- name: Create new-ifcfg-eth* files
template:
src: create_ifcfg.cfg.j2
dest: /etc/sysconfig/network-scripts/ifcfg-{{ item }}
with_items: "{{ car.stdout_lines }}"
register: cat
Remove double template call, use relative path (no need to define full path to role's own templates), use YAML syntax instead of key=value (you had spaces in them, which are not allowed).

Salt Jinja Syntax error: no filter named 'yaml_encode'

When running salt '*' state.highstate, my SLS files fail to render with the following message:
Data failed to compile:
----------
Rendering SLS 'base:files' failed: Jinja syntax error: no filter named 'yaml_encode'; line 6
---
{% for folder, options in salt['pillar.get']('dirs', {}).items() %}
{{ folder }}:
{%- load_yaml as foo %}
file.directory:
{% for key, val in options.items() %}
- {{ key }}: {{ val|yaml_encode }} <======================
{% endfor %}
- order: 1
{%- endload %}
{% endfor %}
---
The docs show this filter just being used wherever you want to escape YAML so I don't know why the filter is not defined.
All minions and the master are running Ubuntu Server 14.04, and Salt 2014.7.1 from the Launchpad PPA
Although the filter is documented, it is misleading as the docs are generated from the current develop branch, not the latest stable branch.
The docs for older versions are available from readthedocs.org.
The pull request that introduced this feature did not yet get "merged back" into 2014.7.

Resources