How to add permalink and variables globally to Jekyll pages inside a specified directory - jekyll

I'm setting up a website with multi language support.
In the root directory I have one or more directories based on the language locale, e.g.: /en /it
I'm trying to set one language as default and let Jekyll generate its pages in the root of the _site directory, by setting the defaults section in _config.yml as described below. Other directories will be generated as usual.
I don't want:
to use a plugin since it have to work also with GitHub pages
to set a lang: en variable in each page front-matter but setting it globally in _config.yml instead if possible
put a load of files/directories in the root directory, just the various en, it, fr etc (if not having something like described below, but using a master pages directory).
I tried various solutions, including:
using collections: it works as expected with the example below but I don't want to use them for various reasons, like not having sitemap plugin working with them
using this solution, but it doesn't work with multiple pages with same name and other types of documents
This works with collections with an _en directory in the root:
collections:
en:
output: true
permalink: /:path
defaults:
...
- scope:
path: ""
type: "en"
values:
layout: "default"
lang: "en"
permalink: /:path
Not this, IMHO as it should be for pages:
defaults:
...
- scope:
path: "en"
type: "pages"
values:
layout: "default"
lang: "en"
permalink: /:path
In brief I need:
custom variables set for each page in the specified directory globally instead in each page front matter
make Jekyll to generate all pages from the specified directory to build in the root of _site directory using a global permalink

Related

Jekyll - Add custom page

I want to add some custom pages under a different folder, not the _posts
I want to use _doc inside I have multiple files.
_doc
|_installation.md
|_configure.md
|_uninstall.md
I tried this. But when I hit the URL I got 404 error.
installation.md file in _doc folder
---
layout: post
date: 2020-06-06 22:00:00 +0530
title: DOC for installation
description: DOC for installation
categories:
- doc
tags:
- doc
permalink: /doc/installation
---
Rest of the content goes here
Im able to solve this.
Just add the _doc in config file.
include: ['_doc']

Cannot import variables from sass file in Jekyll

I have a variables.scss file that holds all of my sass variables in my root. I want to import it in my other scss files so that I can use these variables:
#import "/variables.scss";
However when I run the project, I get the following error:
Conversion error: Jekyll::Converters::Scss encountered an error while converting 'assets/css/index.scss':
File to import not found or unreadable: /variables.scss. Load path: C:/Ruby25-x64/lib/ruby/gems/2.5.0/gems/minima-2.5.0/_sass on line 1
What am I doing wrong and how can I properly import my sass variables. here is my config_.yml file:
# Welcome to Jekyll!
#
# This config file is meant for settings that affect your whole blog, values
# which you are expected to set up once and rarely edit after that. If you find
# yourself editing this file very often, consider using Jekyll's data files
# feature for the data you need to update frequently.
#
# For technical reasons, this file is *NOT* reloaded automatically when you use
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.
# Site settings
# These are used to personalize your new site. If you look in the HTML files,
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.
title: Project
email: your-email#example.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: jekyllrb
github_username: jekyll
# Build settings
markdown: kramdown
theme: minima
plugins:
- jekyll-feed
- jekyll-paginate-v2
collections:
posts:
output: true
permalink: /releases/:path
permalink: pretty
sass:
sass_dir: _sass
style: compressed
future: true
published: true
# Exclude from processing.
# The following items will not be processed, by default. Create a custom list
# to override the default setting.
# exclude:
# - Gemfile
# - Gemfile.lock
# - node_modules
# - vendor/bundle/
# - vendor/cache/
# - vendor/gems/
# - vendor/ruby/
############################################################
# Site configuration for the Jekyll 3 Pagination Gem
# The values here represent the defaults if nothing is set
pagination:
# Site-wide kill switch, disabled here it doesn't run at all
enabled: true
# Set to 'true' to enable pagination debugging. This can be enabled in the site config or only for individual pagination pages
debug: false
# The default document collection to paginate if nothing is specified ('posts' is default)
collection: 'posts'
# How many objects per paginated page, used to be `paginate` (default: 0, means all)
per_page: 5
# The permalink structure for the paginated pages (this can be any level deep)
permalink: '/page/:num/' # Pages are index.html inside this folder (default)
#permalink: '/page/:num.html' # Pages are simple html files
#permalink: '/page/:num' # Pages are html files, linked jekyll extensionless permalink style.
# Optional the title format for the paginated pages (supports :title for original page title, :num for pagination page number, :max for total number of pages)
title: ':title - page :num'
# Limit how many pagenated pages to create (default: 0, means all)
limit: 0
# Optional, defines the field that the posts should be sorted on (omit to default to 'date')
sort_field: 'date'
# Optional, sorts the posts in reverse order (omit to default decending or sort_reverse: true)
sort_reverse: true
# Optional, the default category to use, omit or just leave this as 'posts' to get a backwards-compatible behavior (all posts)
category: 'posts'
# Optional, the default tag to use, omit to disable
tag: ''
# Optional, the default locale to use, omit to disable (depends on a field 'locale' to be specified in the posts,
# in reality this can be any value, suggested are the Microsoft locale-codes (e.g. en_US, en_GB) or simply the ISO-639 language code )
locale: ''
# Optional,omit or set both before and after to zero to disable.
# Controls how the pagination trail for the paginated pages look like.
trail:
before: 2
after: 2
# Optional, the default file extension for generated pages (e.g html, json, xml).
# Internally this is set to html by default
extension: html
# Optional, the default name of the index file for generated pages (e.g. 'index.html')
# Without file extension
indexpage: 'index'
############################################################
First of all, use only relative basenames to import:
#import "variables";
// or if you've nested partials
#import "subdirectory/partial_name";
Secondly, if you're using sassc gem, ensure that you're using at least sassc-2.1.0 in your bundle. (Run bundle show to check). Or if you're using the deprecated sass gem, then continue using that until you can upgrade.
Lastly, ensure that your scss partial doesn't have unclosed parentheses.
UPDATE
Jekyll expects to find partials to import from in the configured sass_dir (which is _sass by default).
So, you've to ensure that the path _sass/variables.scss exists either at your source directory or within the theme-gem you're using.

How to generate a whole website in a variabilized sub-directory ? (Jekyll)

I've been playing around with Jekyll lately and recently discovered that S3 wouldn't allow me to have enough buckets to have one bucket per website.
So I'm struggling to figure out two things
1) How do I specify that I want a 'child' subdirectory to be created, and all the generated website's files to be in it ?
2) How do I use a variable as the 'child' subdirectory's name ? (since it will be different for each website)
The baseurl config option doesn't seem to do anything about that. Any idea will be welcome :-)
Thanks a lot, and have a great day !
I'm not sure about the variable option, however, for child sub-directories:
A) If you can put the content into "child" folders directly within the jekyll content, then use different configuration files to manage each site through build properties. See the examples under the example below.
B) If you just want to put the same content in different places, perhaps you could use different baseurl or destination properties in different config files? Use the same config file approach as below, but with different versions of those properties instead of/in combination with the exclude property (see https://jekyllrb.com/docs/configuration/#serve-command-options).
Example: Use different config files
Use the exclude config property to exclude folders (and all of that folder's contents) when running a build. You could also specify different output folder locations per site, base URLs, and so on. I'll focus on the exclude property, but you can find other useful properties in the documentation: https://jekyllrb.com/docs/configuration/#global-configuration
For example, you could have the following files/folders:
/siteA-folder/siteA-content/blah.html
/siteB-folder/siteB=content/meh.html
/siteC-folder/siteC=content/foo.html
config.yaml
config_buildA.yaml
config buildB.yaml
Use the build option --config FILE1[,FILE2...] (https://jekyllrb.com/docs/configuration/#build-command-options) to explicitly call your custom config file A or B, each of which has its own version of the exclude property.
Snippet from config_buildA.yaml:
exclude:
- /siteB-folder/ # While building A, you want to exclude the siteB folder and contents
- /siteC-folder/ # Similarly, exclude siteC contents
Snippet from config_buildB.yaml:
exclude:
- /siteA-folder/ # While building B, you want to exclude the siteA folder and contents
- /siteC-folder/ # Similarly, exclude siteC contents
Building A from the command line:
jekyll build --config config_buildA.yaml
Building B from the command line:
jekyll build --config config_buildB.yaml
By managing excludes in the config file, you can re-use the common templates and css, and keep everything together (using less disk space overall).
If there's shared content, you could also look into using a more advanced feature, includes (see https://jekyllrb.com/docs/includes/), to manage the shared content in the includes folder, referenced within the html or markdown files (but that's getting a little of the beaten track for your question, so I'll stop there...)
EDIT: I see you've edited the question specifying the baseurl property doesn't do what you're looking for.
I've used a combination of the url site property baseurl and destination similar to below. In my case, I have different destinations depending on whether it's an archive or latest content, but you could use this to build to different web folders if you wanted.
Ex: config for latest content
url: http://example.com
baseurl: "/latest/"
destination: /path/to/latest/output/
Ex: config for archived content
url: http://example.com
baseurl: "/archive/content/"
destination: /path/to/archive/output/
Then, using the multiple versions of the config file, I can just call whichever one applies.

Jekyll multiple Permalinks support

Does Jekyll support setting multiple permalinks?
For example, I currently have the following in my _config.yml:
permalink: /:categories/:title/
What I would like to have, is the following:
permalink:
- /:categories/:title/
- /:year/:month/:day/:title/
What I'm trying to achieve it that a single post will have multiple URLs. I'm well aware that I can use the "redirect_from" plugin (I'm hosting in GitHub Pages), but that would require me to manually update all my posts to include the redirect_from in the YAML
have you checked out jekyll-archives? https://github.com/jekyll/jekyll-archives
you can create other permalinks like
permalinks:
year: '/:year/'
month: '/:year/:month/'
day: '/:year/:month/:day/'
tag: '/tag/:name/'
category: '/category/:name/'
i don't think you can use :title though. it's an index page that lists posts.

Jekyll use config.yml values in the HTML

Is it possible to setup configuration values within the config.yml file and have them be printed within the HTML page within Jekyll? I would like to set the default title and description of my website within the config.yml file and have them printed out in the header of all my layouts.
Every template has a site variable, which contains the settings from _config.yml. For example, if you have something like my_setting: "string" in _config.yml, you can access the value in a template using {{ site.my_setting }}.
Note: if you are using jekyll serve, you will need to restart the process for changes to take place. Indeed, _config.yml is not reloaded with the watch option.