Why is default layout not being applied to pages? - jekyll

I am trying to use Github Pages and Jekyll for the first time. I created a repo and followed the instructions to set it up.
I am having trouble getting the default layout to work. A layout file: _layouts/default.html exists in the repository and my _config.yml looks like:
defaults:
-
scope:
path: ''
values:
layout: 'default'
Even with the setting above, the pages are not getting the default layout applied. See the Github Repositry and My github page that currently shows:
Look in _config.yml, why is default layout not being applied??
Without any layout.
What am I missing?

All your pages must have a front matter (event empty) if you want Jekyll to parse them.
Without a front matter, your pages are just copied like static files.
So, your index.html must be :
---
---
Look in _config.yml, why is default layout not being applied ?
default layout is them applied.

Related

Github Pages Build of Jekyll site is missing pages

I'm trying to use Github pages with Jekyll. Most of my pages are displayed as expected, but others (that I can see in the local build) do not show on the Github pages build.
The pages that do work are in the _pages folder with their permalinks set in the front matter. Like this
---
type: page
permalink: /about/
layout: default
---
The pages that don't work are in a folder _projects with similar, but slightly different front matters
---
permalink: /projects/foo
layout: post
---
When I try to access foo.com/projects/foo/ it gives me error 404, but foo.com/about/ works as expected. There are no front matter defaults, so what you see is what is there.
I found my solution in the similar questions as I was writing this, but couldn't with a google search.
Github Pages didn't like having the permalinks for _projects in the format /projects/foo/, but /projects/foo.html works like a charm.

Set a global permalink in Jekyll without the path?

I would like all posts and pages on my Jekyll site to have the same link structure: example.com/my-title, regardless of the directory structure I use to store my files.
Looking at the documentation it seems like I should be able to implement this by putting the following line in my _config.yml:
permalink: /:title.
This almost works. All posts (in the _posts/ directory) get the correct URL. And all pages in my site's home directory also get the correct url. However, pages that are in subdirectories still have the directory path prefixed to the url. For example, if I have a page pages/cats/my-cat.md the URL is example.com/pages/cats/my-cat, instead of what I want (example.com/my-cat). If I set the permalink for that page directly in the front matter as /my-cat I get the desired outcome, but I'd rather not do this on every page.
Is it possible to remove the path from all page URLs?
I see a number of other questions about Jekyll permalinks but nothing that addresses this exactly. This answer from 2013 says that pages will "always remain relative path" but that's fairly old, and also seemed like a throwaway assertion rather than an evidence-backed claim.
You can use Jekyll defaults to apply fallback front matter for files based on a type and/or path. It has the same effect as setting the front matter inside each file. Here's how you could apply that permalink to all pages:
_config.yml:
defaults:
- scope:
path: ''
type: pages
values:
permalink: /:title
It's also a great way to set other common fields, e.g. layout.
Official documentation for further details: https://jekyllrb.com/docs/configuration/front-matter-defaults/

Why are jekyll pages in subfolders not using my theme

I am using Jekyll to create a website on GitHub Pages. I have a _config.yml file with the following contents (this is the entire file):
theme: jekyll-theme-leap-day
collections:
tutorials:
output: true
I have a few dozen pages in my root folder, and a _tutorials folder which contains about 10 more pages. If it matters, all of my pages are MarkDown (.md extension).
All pages in my root have the proper styling (one of GitHub's built-in themes "Leap Day"). However, all of my subpages have a white background and are left-justified - it seems the theme is not applying there.
The only front matter in any of my pages is where I either specify the title: or (both in the pages in the root and subfolders).
Is there some setting I have to place in my _config.yml to tell the pages in _tutorial to use the same theme as the pages in my root folder? Do I need to put some Front Matter on each page to have it use the theme?
I tried adding the theme explicitly under the tutorials: section in my _config.yml but my tutorial pages still didn't use the theme.
Each theme comes with a specific set of layouts, chances are that your posts aren't using any of the new layout themes, so you need to check if them have a layout key in front natter specifying which layout to use, and change it to make your posts use a specific layout, or define a default layout to use when no layout key is present in posts adding a default value in _config.yml.
Update
Add the default layout to all of your pages in _config.yml:
defaults:
- scope:
path: ""
values:
layout: default
That should fix the issue.

GitHub Pages - frontmatter causes page to break

I am publishing pages from my /docs folder as per https://github.com/blog/2228-simpler-github-pages-publishing
If I include this front matter on a page, the build breaks.
---
layout: page
title: "Help Page"
permalink: /help
---
The page is built but only contains the data from the <body> element. No headers, no stylesheet, just garbled HTML. The same occurs if I use layout: post.
If I removed the line layout: page then everything works.
According to the GitHub documentation - https://help.github.com/articles/configuring-jekyll/ - I should be able to use this frontmatter in my pages.
What blindingly obvious thing have I missed?
The "slate" theme only has a "default" layout.
So switching to layout: default fixed the issues.

generate subpages from template in jekyll

Is it possible to have a template in Jekyll, that will be filled for each subpage of a certain category with different data..
Say I have portfolio page, then I link to my works from there, each separate work page is using the same template, just the text and pics are changing.
So what I would like to have is portfolio/work1, portfolio/work2 generated from the same template and then I would iterate over _data yml files to fill in details for each work...
Is that possible in Jekyll? I couldn't find any articles on that topic.
You can use default setup for your portofolio folder.
1. In _config.yml, set :
defaults:
-
scope:
path: "portofolio"
type: "pages"
values:
layout: "work"
2. Create a _layouts/work.html template.
_
3. In your portofolio/indexhtml page
If you want to override layout, just do :
---
layout: page
...
---
This can be done with 'Collections' which is a function in Jekyll. See Jekyll Collections. If you are not sure what Collections is for then maybe Ben Balter's explanation could help.
In your situation: You want a portfolio page with subpages for each piece of work. Create a collection named Portfolio in your _config.yml like below:
# Collections
collections:
portfolio:
output: true
Then create a folder called _portfolio in your jekyll files. You then can clarify in your front matter on each piece of work i.e. work1.md inside _portfolio which could display images, tags etc along with content like you would write a post in Jekyll. In your front-matter for each work example, you can define what template/layout you would want to use for the work examples.