Jekyll issue with overlapping scopes in _config.yml - jekyll

I have an issue using scopes in my _config.yml file:
In a multilingual blog, I want to use a given layout for all posts, and then customize permalinks for each language with a more specialized scope. Here is my configuration:
defaults:
-
# defaults for all files in the project
scope:
path: ""
values:
layout: my-page-layout
-
# defaults for all posts in the project
scope:
path: ""
type: posts
values:
layout: my-post-layout
-
# defaults for all english posts in the project
scope:
path: en
type: posts
values:
permalink: /en/:year/:month/:title/
-
# defaults for all french posts in the project
scope:
path: fr
type: posts
values:
permalink: /fr/:year/:month/:title/
English posts under the path en effectively have the right layout (my-post-layout), but not the french posts under the path fr which have the default layout (my-page-layout).
Looks like the scope corresponding to the pair "fr/posts" overrides the default values for all posts, while this is not the case for the scope corresponding to the pair "en/posts".
What am I missing?
EDIT:
The directory structure of my jekyll project looks like this (I removed unrelevant files):
./
├──_layouts/
│ ├──my-page-layout.html
│ └──my-post-layout.html
│
├──en/
│ ├──_posts/
│ │ └──2016-12-01-my-post-in-english.md
│ │
│ └──my-page-in-english.html
│
├──fr/
│ ├──_posts/
│ │ └──2016-12-01-mon-post-en-français.md
│ │
│ └──ma-page-en-français.html
│
└──_config.yml

Edit :
Reading from your code :
defaults:
-
scope:
path: ""
values:
layout: wasthishelpful-page
lang: en
-
scope:
path: fr
values:
lang: fr
-
scope:
path: ""
type: posts
values:
layout: wasthishelpful-post
-
scope:
path: en/_posts
values:
permalink: /en/:year/:month/:title/
-
scope:
path: fr/_posts
values:
permalink: /fr/:year/:month/:title/
And from jekyll code, we can see that we have a precedence problem.
The second rule applies to /fr path, but will not be overriden by third rule that applies to / path.
The solution is to declare your third rule before the second one by inverting them.
defaults:
-
scope:
path: ""
values:
layout: wasthishelpful-page
lang: en
-
scope:
path: ""
type: posts
values:
layout: wasthishelpful-post
-
scope:
path: fr
values:
lang: fr
...

Related

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 do I get Jekyll scope/value pairs from config.yml

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

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'