Jekyll subfolders with different output - jekyll

In jekyll, i am using collections in order to define the contents of a site. I organised it like this:
site
_contents
jobs
_solutions
I want the files in solutions to generate pages, but not the ones in jobs. So i configured the collections like so:
collections:
contents:
output: false
solutions:
output: true
My boss, however, wants me to organise the site like so:
site
_contents
jobs
solutions
i tried to make this work by configuring like this:
collections:
contents:
output: false
solutions:
output: true
this does not work. Is what i'm trying to do possible?
// EDIT: another alternative in config.yml could be...
collections:
contents/jobs:
output: false
content/solutions:
output: true

Related

Ansible Inventory Multi-line Inventory arrays?

I'm trying to write an array in an Ansible inventory file (i.e. hosts.local) but the array seems to have to be all on one line and can't be split upon multiple:
[all:vars]
someArr=["This",
"doesn't",
"work"]
Is there any way of doing this in Ansible inventory files?
Is there any way of doing this in Ansible inventory files?
INI file doesn't support multiline. You may find some programming specific workaround but in this scenario, best is to use YAML for inventory. A sample inventory snippet:
all:
vars:
multiline: [
"This",
"is",
"multiline"
]
# Or use below style that results the same
#multiline:
# - "This"
# - "is"
# - "multiline"
hosts:
somehost:
Have a look at inventory basics for more details.

What are the return values of os.walk() in python?

I have a directory structure like this:
dir/
└── subdir
My code:
import os
for d in os.walk('dir'):
print(d)
I get the output:
('dir', ['subdir'], [])
('dir/subdir', [], [])
My question is what are those trailing [ ]s ?
There is 1 in the first tuple and 2 in the second.. it confuses me.
It's worth checking out the Python docs for questions like this as they tend to have pretty solid documentation: https://docs.python.org/2/library/os.html#os.walk
Generate the file names in a directory tree by walking the tree either top-down or bottom-up. For each directory in the tree rooted at directory top (including top itself), it yields a 3-tuple (dirpath, dirnames, filenames).
So it will always return a 3-tuple.
For your first directory 'dir', it contains one directory called 'subdir', and it doesn't contain any files so there's an empty list for filenames.
It then has another entry for subdir, which is your 'dir/subdir'. 'subdir' doesn't have any directories or files under it, so you have empty lists for both dirnames and filenames. The key thing is that it always returns a 3-tuple, and the last two elements are always lists, so there are no subdirectories or files, it will return empty lists.

Create multiple jekyll pages from yaml without using a plugin

I am working on a Jekyll site on and I want to be able to have a page for each person in the group. I know I can use a collections to generate pages, if the files in the collection are markdown. I want to be able to have yaml files in the collection, then generate pages after passing each yaml file to a template.
People files might look like this:
# person-1.yaml
name: thingy m. bob
position: coffee fetcher
bio: no bio needed
# person-2.yaml
name: mars e. pan
position: head honcho
bio: expert in everything
Then a template file like this (people-template.md):
# {{ page.name }} - {{ page.position }}
{{ page.bio }}
And the output would be individual file under /people/, i.e, /people/person-1, /people/person-2, which are formatted as in the template, but using the .yaml files.
I am using GitHub pages, so I don't want to have to use any plugins which that doesn't support.
I have implemented something similar ... this is the setup I created:
- _Layouts
- person.html
...
people
- index.md (list of people - see code below)
- _posts
- 2015-01-01-person-one.md (ordering defined by date which is thrown away)
- 2015-01-02-person-two.md
- 2015-01-03-person-three.md
...
Then for a list of people you can use something like:
<ul>
{% for person in site.categories.people %}
<li></li>
{% endfor %}
</ul>
with each person being in the form
---
name: "thingy m. bob"
# using quotes to avoid issues with non-alpha characters
position: "coffee fetcher"
bio: "no bio needed"
layout: person
---
any markdown if you want more of a description
I hope that has given you something to start with ... I think that putting the _posts folder under the people folder will automatically set the category to people. If I am wrong, just add category: people to the yaml.
You can set the pattern for the post urls in _config.yaml if you want to remove the date part.
Good luck

How to copy files from a ** desination to another in Gulp src and dist?

I have some problem can't find a direct answer on just this one.
I have a folder structure like this:
modules/**/views/**/*.html
modules/cart/views/templates/
modules/cart/views/content/
modules/cart/views/content/foo/
I want to move them so they end up like this:
Views/templates/
Views/content/
Views/content/foo/
I have tried base: and cwd: with
{ base: 'modules/**/views/**' }
Also with . and ./ etc.. but cant get it to work with two ** I dont want the first ** just files from the second ** and it's folder
Any clue? does it even work? Tried
I found a solution by using gulp-rename.
Not sure if it's the best one but worked.
I split my path. Get the name of the first **
renamed it to empty value, same with the views.
return gulp.src(config.vSrc)
.pipe(rename(function(path) {
var splitedPath = path.dirname.split('\\');
var moduleName = splitedPath[0];
path.dirname = path.dirname.replace(moduleName, '').replace('views', '');
gutil.log(path.dirname);
}))
.pipe(gulp.dest("Views"));
To update this answer, now a good way to do this is with gulp-flatten. It is very good at extracting specific folders from the folder hierarchy. I believe in the OP's case what he wants is:
gulp.src(['config.vSrc'])
.pipe(flatten({ subPath: [3] }))
.pipe(gulp.dest('Views'));
That should get the 4th, etc. folder on down. It is possible you would need this syntax:
subPath: [3,] I am not sure about that without testing it.

Jekyll Filename Without Date

I want to build documentation site using Jekyll and GitHub Pages. The problem is Jekyll only accept a filename under _posts with exact pattern like YYYY-MM-DD-your-title-is-here.md.
How can I post a page in Jekyll without this filename pattern? Something like:
awesome-title.md
yet-another-title.md
etc.md
Thanks for your advance.
Don't use posts; posts are things with dates. Sounds like you probably want to use collections instead; you get all the power of Posts; but without the pesky date / naming requirements.
https://jekyllrb.com/docs/collections/
I use collections for almost everything that isn't a post. This is how my own site is configured to use collections for 'pages' as well as more specific sections of my site:
I guess that you are annoyed with the post url http://domaine.tld/category/2014/11/22/post.html.
You cannot bypass the filename pattern for posts, but you can use permalink (see documentation).
_posts/2014-11-22-other-post.md
---
title: "Other post"
date: 2014-11-22 09:49:00
permalink: anything-you-want
---
File will be anything-you-want/index.html.
Url will be http://domaine.tld/anything-you-want.
What I did without "abandoning" the posts (looks like using collections or pages is a better and deeper solution) is a combination of what #igneousaur says in a comment plus using the same date as prefix of file names:
Use permalink: /:title.html in _config.yml (no dates in published URLs).
Use the format 0001-01-01-name.md for all files in _posts folder (jekyll is happy about the file names and I'm happy about the sorting of the files).
Of course, we can include any "extra information" on the name, maybe some incremental id o anything that help us to organize the files, e.g.: 0001-01-01-001-name.md.
The way I solved it was by adding _plugins/no_date.rb:
class Jekyll::PostReader
# Don't use DATE_FILENAME_MATCHER so we don't need to put those stupid dates
# in the filename. Also limit to just *.markdown, so it won't process binary
# files from e.g. drags.
def read_posts(dir)
read_publishable(dir, "_posts", /.*\.markdown$/)
end
def read_drafts(dir)
read_publishable(dir, "_drafts", /.*\.markdown$/)
end
end
This overrides ("monkey patches") the standard Jekyll functions; the defaults for these are:
# Read all the files in <source>/<dir>/_drafts and create a new
# Document object with each one.
#
# dir - The String relative path of the directory to read.
#
# Returns nothing.
def read_drafts(dir)
read_publishable(dir, "_drafts", Document::DATELESS_FILENAME_MATCHER)
end
# Read all the files in <source>/<dir>/_posts and create a new Document
# object with each one.
#
# dir - The String relative path of the directory to read.
#
# Returns nothing.
def read_posts(dir)
read_publishable(dir, "_posts", Document::DATE_FILENAME_MATCHER)
end
With the referenced constants being:
DATELESS_FILENAME_MATCHER = %r!^(?:.+/)*(.*)(\.[^.]+)$!.freeze
DATE_FILENAME_MATCHER = %r!^(?>.+/)*?(\d{2,4}-\d{1,2}-\d{1,2})-([^/]*)(\.[^.]+)$!.freeze
As you can see, DATE_FILENAME_MATCHER as used in read_posts() requires a date ((\d{2,4}-\d{1,2}-\d{1,2})); I put date: 2021-07-06 in the frontmatter.
I couldn't really get collections to work, and this also solves another problem I had where storing binary files such as images in _drafts would error out as it tried to process them.
Arguably a bit ugly, but it works well. Downside is that it may break on update, although I've been patching various things for years and never really had any issues with it thus far. This is with Jekyll 4.2.0.
I wanted to use posts but not have the filenames in the date. The closest I got was naming the posts with an arbitrary 'date' like 0001-01-01cool-post.md and then use a different property to access the date.
If you use the last-modified-at plugin - https://github.com/gjtorikian/jekyll-last-modified-at - then you can use page.last_modified_at in your _layouts/post.html and whatever file you are running {% for post in site.posts %} in.
Now the dates are retrieved from the last git commit date (not author date) and the page.date is unused.
In the json schema for the config file are actually some useful information. See below code block for some examples.
I have set it to /:categories/:title. That drops the date and file extension, while preserving the categories.
I still use a proper date for the file name because you can use that date in your templates. I.e. to display the date on a post using {{ page.date }}.
{
"global-permalink": {
"description": "The global permalink format\nhttps://jekyllrb.com/docs/permalinks/#global",
"type": "string",
"default": "date",
"examples": [
"/:year",
"/:short_year",
"/:month",
"/:i_month",
"/:short_month",
"/:day",
"/:i_day",
"/:y_day",
"/:w_year",
"/:week",
"/:w_day",
"/:short_day",
"/:long_day",
"/:hour",
"/:minute",
"/:second",
"/:title",
"/:slug",
"/:categories",
"/:slugified_categories",
"date",
"pretty",
"ordinal",
"weekdate",
"none",
"/:categories/:year/:month/:day/:title:output_ext",
"/:categories/:year/:month/:day/:title/",
"/:categories/:year/:y_day/:title:output_ext",
"/:categories/:year/:week/:short_day/:title:output_ext",
"/:categories/:title:output_ext"
],
"pattern": "^((/(:(year|short_year|month|i_month|short_month|long_month|day|i_day|y_day|w_year|week|w_day|short_day|long_day|hour|minute|second|title|slug|categories|slugified_categories))+)+|date|pretty|ordinal|weekdate|none)$"
}
}