I have Jekyll site hosted on GitHub Pages. The file _config.yml has this content (excerpt):
# Defaults
defaults:
# _pages
- scope:
path: "_pages"
type: "pages"
values:
layout: "single"
read_time: true
So when the site is built, I can open a page by its URL like this:
https://repo.github.io/_pages/some-page/
I read all the docs for Jekyll but it is not clear to me how to turn this URL to be https://repo.github.io/some-page/ or maybe https://repo.github.io/pages/some-page/.
_pages can be seen as collection directory.
Therefore by simply having the following config:
collections:
pages:
output: true
will give you URLs like https://repo.github.io/pages/some-page.html
To get custom URLs you may add a permalink sub-config:
collections:
pages:
output: true
permalink: /:collection/:path/
will give you URLs like https://repo.github.io/pages/some-page/
For more possibilities, refer the official docs
Related
I have simple jekyll site. Every post in _posts has paramter author in it's front matter:
---
layout: post
title: my title
author: John Doe
---
...
How should I set permalink in _confing.yml if i want it to be /author/title/?
For example post above would have permalink:
mysite.com/john-doe/my-title/
Thank you for help.
I solved this using jekyll_custom_permalink plugin.
Installation
Add the plugin to your site's Gemfile:
group :jekyll_plugins do
# your other jekyll plugins...
gem 'jekyll_custom_permalink', '~> 0.0'
end
Then run
$ bundle install
Usage
Lets assume that you have some options for your collection "projects" defined in _config:
collections:
projects:
output: true
permalink: projects/:title/
You would like to use custom Front Matter in the paths of your projects. For example, it would be great to be able to include the Front Matter variable type in the links to your projects, which is defined in every file belonging to the "projects" collection.
---
layout: page
type: python
title: MyAwesomeProject
---
Some content
You can use the type variable in your permalink by first adding it to an array of custom permalink placeholders for the collection, and then adding the placeholder to the permalink setting prefixed with a : like every other Jekyll placeholder.
collections:
projects:
output: true
custom_permalink_placeholders: ["type"]
permalink: projects/:type/:title/
These settings lead to the "project" page, shown above, to be live at /projects/python/MyAwesomeProject.
SOURCE: https://github.com/NiklasEi/jekyll_custom_permalink/blob/master/README.md
I'm unable to see the index.html get rendered with jekyll's front matter. In fact, the front matter is all I see on the webpage.
Here is the folder layout:
and the _config.yml:
title: badabing badaboom
email: xyz#gmail.com
description: tbd
#baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
twitter_username:
github_username:
encoding: utf-8
# Build settings
theme: jekyll-theme-clean-blog
plugins:
- jekyll-feed
remote_theme: StartBootstrap/startbootstrap-clean-blog-jekyll
# Exclude from processing.
# The following items will not be processed, by default.
# Any item listed under the `exclude:` key here will be automatically added to
# the internal "default list".
#
# Excluded items can be processed by explicitly listing the directories or
# their entries' file path in the `include:` list.
Any ideas on how I could fix this, or what I should look into?
My god... *facepalm
I just needed to get rid of .nojekyll
GitHub Pages will use Jekyll to build your site by default. If you
want to use a static site generator other than Jekyll, disable the
Jekyll build process by creating an empty file called .nojekyll in the
root of your publishing source, then follow your static site
generator's instructions to build your site locally.
I have installed the jekyll-compose gem to streamline creating pages, posts etc. In the documentation. I have it working (i.e using the CLI commands I am able to generate, drafts, posts and pages).
However when I generate a post for example, I want it to have certain variables in the front matter. There is functionality mentioned in the ReadMe of Jekyll Compose that says you can set front matter defaults for posts and for drafts.
I have followed the instructions by adding the required lines in the config.yaml of my site, however posts and drafts that I generate using jekyll-compose do not generate with the variables I want.
Jekyll-compose states that if you want default front matter variables you need add something like this to your _config.yaml:
jekyll_compose:
default_front_matter:
drafts:
description:
image:
category:
tags:
posts:
description:
image:
category:
tags:
published: false
sitemap: false
I have tried both their default config above and also my own below
jekyll_compose:
default_front_matter:
drafts:
main_img_url:
author_name:
categories:
description:
posts:
main_img_url:
author_name:
categories:
description:
But neither work when I generate a new post or draft. There are no error messages which makes it difficult to debug.
Originally my Jekyll version was at 3.7.0, I thought it might be an problem of a Jekyll version being too old. However this problem persisted when I updated Jekyll to 3.8.6.
It also does not work when I put default values for my custom variables, i.e:
jekyll_compose:
default_front_matter:
drafts:
main_img_url: "https://images-we-got-pop.imgix.net/website/blog/pop-logo-small.png"
author_name: "Me"
categories: "general"
description: "Description"
posts:
main_img_url: "https://images-we-got-pop.imgix.net/website/blog/pop-logo-small.png"
author_name: "Me"
categories: "general"
description: "Description"
My _config file looks like this:
title: Title
email: your-email#domain.com
description: > # this means to ignore newlines until "baseurl:"
Write an awesome description for your new site here. You can edit this
line in _config.yml. It will appear in your document head meta (for
Google search results) and in your feed.xml site description.
baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
twitter_username: name
github_username: name
# Build settings
markdown: kramdown
theme: minima
plugins:
- jekyll-feed
- jekyll-paginate-v2
exclude:
- Gemfile
- Gemfile.lock
- Makefile
- README.md
permalink: /pages/:year/:month/:day/:title/
jekyll_compose:
default_front_matter:
drafts:
main_img_url:
author_name:
categories:
description:
posts:
main_img_url:
author_name:
categories:
description:
future: true
pagination:
enabled: true
sort_reverse: true
trail:
before: 1
after: 1
and my Gemfile looks like this:
source "https://rubygems.org"
ruby RUBY_VERSION
gem "jekyll", "3.8.6"
# This is the default theme for new Jekyll sites. You may change this to anything you like.
gem "minima", "~> 2.0"
# If you want to use GitHub Pages, remove the "gem "jekyll"" above and
# uncomment the line below. To upgrade, run `bundle update github-pages`.
# gem "github-pages", group: :jekyll_plugins
# If you have any plugins, put them here!
group :jekyll_plugins do
gem "jekyll-feed", "~> 0.6"
gem "jekyll-paginate-v2", "~> 1.9"
gem 'jekyll-compose', "~> 0.11"
end
I am expecting my custom front matter to appear in my newly generated posts:
---
title: this-is-a-new-post
date: 2019-10-09 10:45 +0100
main_img_url:
author_name:
categories:
description:
---
But I only get the standard ones that get created with the post/draft, eg:
---
title: this-is-a-new-post
date: 2019-10-09 10:45 +0100
---
Any ideas??
Ok I managed to fix this myself after seeing the syntax for the custom variables was different on GH compared to what I found when digging into the jekyll-compose post creation methods on rubydoc.info.
Basically there was PR that changed the syntax merged in to master but not yet released, hence why I was having difficulty getting it to work
The current syntax as of the latest release:
jekyll_compose:
draft_default_front_matter:
description:
image:
category:
tags:
post_default_front_matter:
description:
image:
category:
tags:
published: false
sitemap: false
Compared to the config structure illustrated in the Readme and on master in the jekyll-compose repo, but had't been released at the time when I looked at the docs:
jekyll_compose:
default_front_matter:
drafts:
description:
image:
category:
tags:
posts:
description:
image:
category:
tags:
published: false
sitemap: false
I was trying to set different layouts depending on the directory of the pages, like:
defaults:
-
scope:
path: ""
type: "pages"
values:
layout: "default"
-
scope:
path: "www/grid"
type: "pages"
values:
layout: "grid"
-
scope:
path: "www/product"
type: "pages"
values:
layout: "product"
As recommended, I saved the _config.yml file, stopped and rerun the jekyll serve command. Yet, after reloading the pages, nothing seemed affected.
To solve the problem, I:
Saved the _config.yml file
Stopped the jekyll serve command
Deleted the .jekyll-metadata file
Run the jekyll serve command
After that everything worked fine.
The .jekyll-metadata (which I assume is some cache) file is rebuilt after the serve command.
I have a markdown file as follows:
---
title: My Page
categories:
- first
- second
---
In my _config.yml file, I set the permalink to /:categories/:title.html
So when I generate the site, the permalink ends up being /first/second/title.html, whereas
I was hoping Jekyll would create /first/title.html and /second/title.html
Is there a way to do this without custom plugins?
Cheers
The easiest and to me best way is to define the permalink via frontmatter. This is also great for search engine optimization. First you tell Jekyll via _config.yml how Jekyll should build the links if you forget to set it via frontmatter:
_config.yml
# Build settings
permalink: /:categories/:title/
Define a permalink...
2014-10-17_my_post.md
---
layout: post
title: 'Post with permalink'
permalink: /this-is-the-unique-permalink/
---
My Post
According to these docs, it looks like each Jekyll page can only have one category. categories is kind of a misnomer, because you're really defining a "category hierarchy" - like a file path - so the post really resides in a single (sub)category. In this limited sense, you can't do what you want with vanilla Jekyll.
However, Jekyll will process files just sitting around in any directory that doesn't start with an underscore and it follows symlinks. So, for example, if you make directories for each category and place your page in one of them, you can create symlinks to any number of other "categories".
mkdir first second
touch first/page.md
ln -s ../first/page.md second/