How do I get Jekyll scope/value pairs from config.yml - jekyll

How can I pull a default scope/value from my Jekyll _config.yml file into my default layout?
Here is part of the _config.yml
# default settings
defaults:
-
scope:
path: "" # an empty string here means all files in the project
type: posts
values:
author: ME
layout: post
class: article
I want to print something simple like {{ site.defaults.scope.type }}

You can simply get the value class by using page.class in a page that conforms to the path and type specified. For example:
config.yml
defaults:
-
scope:
path: ""
type: posts
values:
class: a post
-
scope:
path: ""
type: not_posts
values:
class: not a post
_posts/****-**-**-post.html
---
layout: post
---
{{ page.class }}
Output
a post

Related

Extracting values from YAML into Jinja template for Ansible playbook

I have a YAML file with content as like below:
cat ../../ansible/playbooks/vars/patching-config.yml
---
patching_tag_name: "Patching"
my_windows_patching:
- {
OS: "WINDOWS",
tag_value: "myProdA",
frequency: "Month", #patching frequency. OneTime|Day|Hour|Week|Month|Minute
interval: 1, #interval of the schedule.
rebootSetting: "never", #ifRequired|never|always
PatchGroup: testA,
startDate: "2020-01-16T23:59:59Z",
expiryDate: "2020-02-16T23:59:59Z",
duration: "PT2H0M",
timeZone: "Australia/Sydney",
updateClassifications: "Critical,Important,Moderate"
}
I want to extract the values of updateClassifications from above YML file in Jinja Template file MaintenanceWindow.yml.j2
Resources:
WindowsNonProdBaseline:
Type: AWS::SSM::PatchBaseline
Properties:
Name: Windows-Non-Prod-Baseline
Description: Baseline containing all updates approved for Windows instances
OperatingSystem: {{ item.OS }}
PatchGroups:
- {{ item.PatchGroup }}
ApprovalRules:
PatchRules:
- PatchFilterGroup:
PatchFilters:
- Values:
# - Critical
# - Important
# - Moderate
{% for item in item.updateClassifications %}
- {{ item }}
{% endfor %}
I'm trying with the code described above, below one more time snippet:
{% for item in item.updateClassifications %}
- {{ item }}
{% endfor %}
I'm calling patching-config.yml in my tasks/main.yml as below
- include_vars: "{{playbook_dir}}/vars/patching-config.yml"
ignore_errors: yes
- name: create a cloudformation stack
cloudformation:
stack_name: "New-Ansible-cloudformation"
state: "present"
disable_rollback: true
template_body: "{{ lookup('template', '../../cloudformation/patching/MaintenanceWindow.yml.j2') }}"
with_items: "{{ telstra_windows_patching }}"
Finally, invoking role as below
cat ansible/playbooks/patching.yml
---
- hosts: localhost
roles:
- patching-cf-ssm
Unfortunately, it is not working.
Any lead shall be greatly appreciated.
Couple of things:
Your task is using telstra_windows_patching in with_items where as your variable file has variable name as my_windows_patching.
Assuming you are using the same name say my_windows_patching in your task and var file, if you are trying to save json object in yaml variable my_windows_patching you don't need - before curly braces. You can define something like this
my_windows_patching:
{
OS: "WINDOWS",
tag_value: "myProdA",
frequency: "Month", #patching frequency. OneTime|Day|Hour|Week|Month|Minute
interval: 1, #interval of the schedule.
rebootSetting: "never", #ifRequired|never|always
PatchGroup: testA,
startDate: "2020-01-16T23:59:59Z",
expiryDate: "2020-02-16T23:59:59Z",
duration: "PT2H0M",
timeZone: "Australia/Sydney",
updateClassifications: "Critical,Important,Moderate"
}
If you want to use elements inside my_windows_patching object with dot notation directly you could change the variable from object to a list something like,
my_windows_patching:
- OS: "WINDOWS"
tag_value: "myProdA"

How to open URLs in new tab in config.yml of Jekyll / Github pages site?

I'm self-taught/totally new to Jekyll and Github Pages and was wondering how to go about opening a URL in a new tab with markdown in the config.yml page.
This is the website theme I'm using. I want the last 'github' link to open in a new tab, instead of the default, which is opening in the current tab.
The _config.yml looks like this:
# # # # # # # # # # # # #
# K i k o - p l u s #
# # # # # # # # # # # # #
# Basic
name: "Kiko Plus"
author:
facebook: your-id
youtubeUser: your-id
youtubeChannel: your-id
twitter: your-id
github: your-id
stackoverflow: your-id
quora: your-id
linkedin: your-id
pinterest: your-id
googlePlus: your-id
instagram: your-id
reddit: your-id
medium: your-id
tumblr: your-id
email: your-id#your-email.com
copyright:
year: 2017
name: Kiko
# Google-analytics
google-analytics:
id: ""
# Disqus
disqus:
id: "kiko-plus"
# URL
url: "https://AWEEKJ.github.io" # the base
hostname & protocol for your site
# url: "http://localhost:4000" # use this url when
you develop
baseurl: "/Kiko-plus" # the subpath of your site
# http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
timezone: Asia/Seoul
permalink: /:year-:month-:day/:title/
# Pagination
paginate: 5
paginate_path: /page:num/
# Markdown
markdown: kramdown
kramdown:
input: GFM
# Navigation
nav:
- name: "About"
url: "/about"
- name: "Archive"
url: "/archive"
- name: "Tags"
url: "/tags"
- name: "Github"
url: "https://github.com/AWEEKJ/Kiko-plus"
# Sass
sass:
sass_dir: _sass
style: :compressed
# Scopes
defaults:
-
scope:
path: ""
type: "pages"
values:
layout: "page"
-
scope:
path: ""
type: "posts"
values:
layout: "post"
# jekyll-seo-tag,
gems:
- jekyll-seo-tag
- jekyll-paginate
- jekyll-admin
exclude: [vendor]
To do this in any basic markdown post, naturally you'd do
[a link](http://example.com){:target="_blank"}
But since this link is in the site setup, that doesn't work. I've searched a ton and tried 5 or 6 different recommendations but to no avail.
Any ideas? Would be uber appreciated!!!!
You need to add target="_blank" to index.html line 12 as follow:
{{ nav.name }}
I found a plugin that automatically sets any external URL to open in a new tab:
https://rubygems.org/gems/jekyll-target-blank
Add the following to your site's Gemfile
gem 'jekyll-target-blank'
and add the following to your site's
_config.yml
plugins:
- jekyll-target-blank
You may also need to run bundle install to install the new Gem
{:target="_blank"} works for me:
[text](http://url){:target="_blank"}

Phraseapp tag configuration

So I have a bunch of translated keys set up like this:
|-- en
homepage.json
login.json
signup.json
|-- de
homepage.json
login.json
signup.json
I want to upload these to PhraseApp via their command line tool. Basically, it reads a .phraseapp.yml file for config settings and runs.
My current .phraseapp.yml looks like this:
phraseapp:
access_token: 123456789
project_id: 123456789
file_format: nested_json
push:
sources:
- file: <locale_name>/*.json
params:
file_format: nested_json
pull:
targets:
- file: <locale_name>/*.json
params:
file_format: nested_json
However, this setup just uploads all of these json files to the en and de locales, completely ignoring the namespace implied by filename. How can I retain namespaces with PhraseApp?
At the very least, I'd like to be able to include the namespace as a tag, something like this:
phraseapp:
access_token: 123456789
project_id: 123456789
file_format: nested_json
push:
sources:
- file: <locale_name>/<namespace>.json
params:
file_format: nested_json
tags: <namespace>
pull:
targets:
- file: <locale_name>/*.json
params:
file_format: nested_json
This obviously doesn't work, as it causes PhraseApp to look for a file literally named <namespace>. Any ideas?
Try using the placeholder <tag> instead of <namespace>. This way the keys will be tagged with the name of the file they belong to when running phraseapp push.
In order to put back the keys into the right file when downloading the locales again (phraseapp pull), you have to setup multiple target file paths with the tag-parameter respectively.
According to this, your .phraseapp.yml can look something like this:
phraseapp:
access_token: ...
project_id: ...
file_format: nested_json
push:
sources:
file: ./<locale_name>/<tag>.json
pull:
targets:
# homepage
-
file: ./<locale_name>/homepage.json
params:
tag: "homepage"
# login
-
file: ./<locale_name>/login.json
params:
tag: "login"
# signup
-
file: ./<locale_name>/signup.json
params:
tag: "signup"
The workflow is described more detailed here: https://phraseapp.com/docs/guides/working-with-phraseapp/structuring-localization-files/#keeping-separate-files
Have a nice weekend and best regards!
Cornelius

How can I create a directory for each category under _posts in Jekyll?

I am trying to have such a structure in my Jekyll site:
_posts
php
2014-10-31-this-is-a-test.md
ruby
2014-12-01-some-other-test.md
I would like all posts in the php directory to be in the PHP category, and all posts in ruby to be in the Ruby category. Here is my _config.yml file:
defaults:
-
scope:
path: ""
type: "posts"
values:
layout: post
comments: true
share: true
-
scope:
path: "_posts/php"
type: "posts"
values:
category: PHP
-
scope:
path: "_posts/ruby"
type: "posts"
values:
category: Ruby
However, this doesn't work. Any ideas?
path: "php" or path: "ruby" sets the category.
Note: any category set in the front matter will replace the one in default config.

Upgrade Jekyll from 0.12.1 to 1.0.0 categories have double url

We have a pretty basic Jekyll site, lots of posts all divided up into categories. We're using the generate categories plugin.
Our categories were accessible at http://fake.com/categories/cat_index
After upgrading from 0.12.1 to 1.0.0, all of the category posts now have a url of http://fake.com/categories/cat_index/categories/cat_index
The only big thing I know changes between versions was the addition of the baseUrl being exposed to the liquid templates, but I can't figure out how that would have affected the post generation.
Searching this site and the rest of the internet I haven't been able to find anyone else having a similar error. I tried using a different category plugin, but had the same error.
A stripped version of the _congig.yml (just took out actual category/post names to maintain client anonymity)
exclude: [Gemfile, Gemfile.lock, Procfile]
safe: false
permalink: /:title
pygments: false
source: .
destination: ./_site
plugins: ./_plugins
relative_permalinks: false
primary_nav:
- label: 'Home'
href: ''
secondary_nav:
# - label: 'Example 1'
# href: link1.html
# - label: 'Example 2'
# href: link2.html
sections:
- key: 'fake'
label: 'Fake'
children:
- key: 'post-title'
label: 'Post Title'
- key: 'fake2'
label: 'Fake2'
children:
- key: 'post-title2'
label: 'Post Title2'
# configs for unwrapped.rb plugin
unwrapped_dest_directory: 'unwrapped'
unwrapped_template_path: '_includes/styleguide'
unwrapped_template_file: 'unwrapped.html'