Defaults in multiple config files in Jekyll - jekyll

I'm trying to define defaults in multiple config files, for the sake of organization and not having a huge config file. From what I can tell it doesn't work and the documentation doesn't mention anything about it but wasn't sure if I was missing something.
Here are both the config files:
_config.yml
defaults:
- scope:
path: ""
values:
value1: "Value1"
_config2.yml
defaults:
- scope:
path: ""
values:
value2: "Value2"
Here is an HTML file in the default directory
---
---
<p>{{ page.value1 }}</p>
<p>{{ page.value2 }}</p>
And here is the build command
jekyll build --config "_config.yml,_config2.yml"
With all of that, building the project generates the following for index.html
<p></p>
<p>Value2</p>
Even with changing the scopes it has the same result. It seems as though defining defaults in another config file will completely override defaults in the previous file. Is there a way to make something like this work?

The docs say:
Specify config files instead of using _config.yml automatically. Settings in later files override settings in earlier files.
In your case the default's scope.path is the key, and the values are overwritten because the scope.path is identical in both config files. If you changed the path in one file you should see both values appear.

Related

Exclude Jekyll posts from output (don't output individual HTML files)

Since I list all my posts in one page called fotos.html I don't need the individual posts to appear as HTML files in the _site output directory. How can I tell Jekyll to not output the .md posts in the _posts directory as individual HTML files?
[
E.g. The contents of Firmwochenende.html are present in fotos.html with properly formatted title and date. Firmwochenende.html includes only photos and nothing else, which is not useful at all.
I build using build exec jekyll serve and host on Github Pages: https://github.com/junge-pfarre/junge-pfarre.github.io
These are the relevant parts of _config.yml:
defaults:
- scope:
path: ""
values:
layout: "default"
- scope:
path: "assets/flyer"
values:
flyer: true
markdown: kramdown
permalink: :title
A simple post has these contents:
---
title: Jugendandacht Gründonnerstag
---
![Altar der Josefskapelle in der Pfarrkirche Baden St. Stephan][1]
[1]: {{ site.baseurl }}{% link /assets/fotos/Jugendandacht2018.jpg %}
You'll need to use a custom collection rather than the default as the _posts collection is, by design, always going to output individual files. If you create a new collection, you can specify output: false for that collection in your config file while still being able to iterate through it and display the content. From the Jekyll documentation:
# Config file
collections:
your_collection_name:
output: false
However, I saw that you mentioned pagination in the comments. I don't believe GitHub currently supports a gem that has pagination functionality for collections other than _posts (like jekyll-paginate-v2, though they're in talks on merging this in eventually). In the meantime, it looks like there are some solutions out there to help with this limitation.

Can you define Jekyll config defaults from variables in another file?

I'm trying to do this because I'm using a CMS where users will be able to edit a data file to make changes to the page instead of the _config.yml.
I'm wondering if it's possible to reference a variable from the data file and place this reference within the _config.yml.
Here's an example of what I'm trying to do;
Data File (/_data/site-data.yml)
navigation:
navigation_colour: '#462634'
Config File (/_config.yml)
defaults:
-
values:
navigation:
navigation_colour: site.data.site-data.navigation.navigation-colour
Is something similar to this possible?
Thanks!
You can assign at least in one config-file variables, I have not tested this over multiple files.
Variables inside YAML
YAML, hello will become Greetings earthling!
something: &hello Greetings earthling!
myref: *hello
MARKDOWN
{{ site.data.samplelist.myref }}
Jekyll does not parse variables in _config.yml. However inside your blog you can use liquid tags like {{site-data.navigation.navigation-colour}}. See here.
If its mandate to replace variables in _config.yml then use a custom or standard replacement plugin with grunt. So effective grunt build task will first perform token replacement in _config.yml and then do jekyll build.

Keep Jekyll output files from permalink generation

I have one page - hello.html. For this page i have two languages which are defined in a config file. Also i have two different output directories configuration, different the original file name - en/ and pl/. Now, i can generate one lang by dedicated config, after this i can do this for second one.
My question is how to keep en/ directory when i'm generating pl/ one and reverse, how to prevent removing them form public output directory?
Using keep_files jekyll config feature is not working because output directory/file name is different then original.
Hope that this is clear enough.
If you don't mind having two config files, exclude the en files in your pl config, and vice versa. For example, in your pl _config.yml:
exclude: ["en"]
In your en _config.yml:
exclude: ["pl"]
From https://jekyllrb.com/docs/configuration/:
Exclude
Exclude directories and/or files from the conversion. These exclusions are relative to the site's source directory and cannot be outside the source directory.
exclude: [DIR, FILE, ...]

Shorten url of sub-folders in Jekyll

I have a Jekyll project that includes a git submodule foobar with some markdown files that need to be rendered in addition to the ones in the main repo. These files have paths like ./foobar/docs/current/module-1.md.
With the current url scheme this means they get the path /foobar/docs/current/module-1.md, but I'd rather have the shorter path /current/module-1.md. Is this possible using the standard Jekyll install that comes with Github Pages?
You can use default configuration values to set permalink for your foobar folder.
In _config.yml, add :
defaults:
-
scope:
path: "foobar/docs/current"
type: "pages"
values:
permalink: /current/:basename

Exclude JSON files from r.js optimizer

I use a config.json file in my application to configure the application (big surprise) after deployment, pulling them in using the requirejs-text plugin. Ideally, I would like to keep this JSON file (among others) out of the optimized built file.
Here is my app hierarchy:
app/
data/
config.json
...
scripts/
main.js // require.config in here
controllers/
ctrl.js // Uses JSON files
My current build options (through gulp) for require.js are
{
baseUrl: 'app/scripts',
mainConfigFile: 'app/scripts/main.js',
name: 'main',
out: 'main.js'
}
Since these are just flat files I want to exclude and not modules, is there a way of keeping them out of the final file?
If you list it in the dependencies as 'text!config.json', you should be able to exclude it by listing it in exclude list as 'text!config.json'. I created a fake project to test it and it worked.
So:
{
baseUrl: 'app/scripts',
mainConfigFile: 'app/scripts/main.js',
name: 'main',
out: 'main.js',
exclude: ['text!config.json']
}