I'm using a Jekyll collections to render a group of pages using:
collections:
mycoll:
output: true
permalink: /:collection/:path/
And a set of files:
_mycoll/
el1.md
el2.md
el3.md
...
But I need to avoid the generation of some pages of this collection, just like post drafts.
Is it possible?
Under jekyll 2.x, use _config.yml exclude array :
exclude:
- _mycoll/el2.md
With Jekyll 3.x, use post/collection item published front matter variable
---
title: toto
published: false
---
content
Related
i'm kinda new to jekyll. in my project i have few .md files(each file relate to a portfolio project). some of those need to generate separate .html files when built(which jekyll already does). but i want to exclude some files from being creating separate html files.
But the important thing is, even though i want to exclude those .md files from creating seperate .html files i still want to use the front matter of those files.(as i'm using a for loop to generate a list of all the portfolio projects)
i tryied adding those .md files to the _config.yml under exclude. but that will stop parsing the front matter as well.
is there a way in jekyll which i can achieve this.
edit:
project1.md
---
title: project1
display: true
category: portfolioProjects
---
This is a test content
project2.md
---
title: project2
display: false
category: portfolioProjects
---
if i have 2 files like above, i would like to render project1.md as a .html file(as it has a content to be shown in a page) and not generate project2.md as a separate file.But i still want to access front matters of both files to make a list of projects like,
{% for project in site.projects %}
{{project.title}}
{% endfor %}
I believe i can use 2 types of collections and set output to true
for one type of collection and false to other type of collection.
But I'm wondering whether there is a much cleaner way like conditionally setting output to true or false depending on a front matter value.
eg. output : (display)? true : false
There are many questions similar to mine, but most of them arise from not using baseurl correctly. My website, however, does not even use a baseurl. It uses the root Github page. I essentially forked my website off of the Airspace theme ported by luminousrubyist, whose website displays correctly, so somewhere down the line I made a change that stopped it from displaying correctly. Therefore I would appreciate it if someone else could figure out what's wrong; I have been trying to figure it out for hours.
My Github page
My _config.yml file:
title: "My Portfolio"
subtitle: "My portfolio, detailing my experience"
# Base URL of site. It should always start with a slash,
# and never end with a slash. Set it to a blank value if hosting at the
# root of your server.
# baseurl: "/" # the subpath of your site
url: "http://austinstover.github.io" # the base hostname & protocol for your site
cover: "/assets/cover.png"
logo: "/assets/logo.png"
# Build settings
markdown: kramdown
# Google analytics
ga_tracking_id: "UA-90009514-1"
# Category descriptions (for archive pages)
descriptions:
- cat: jekyll
desc: "Posts describing Jekyll setup techniques."
- cat: dummy
desc: "Just some placeholder posts, lorem ipsum and the rest."
exclude:
- "/vendor/"
- "Gemfile"
- "Gemfile.lock"
- "README.md"
- "LICENSE.md"
- "*.gemspec"
keep_files:
- "CNAME"
- ".git"
- ".gitignore"
try to set baseurl in your _config.yml:
baseurl: "" #if not used.
btw, your index.html use page.html layout (from _layouts), that use default.html layout which include head.html (from _includes). this one call {{ site.baseurl }} but it's undefined .
I'd like to preview my drafts in my templates, but the views depend on posts having a category assigned. I've tried setting the front-matter defaults for the _drafts folder, but this doesn't seem to work.
How can I have default frontmatter added to my drafts when I run jekyll s -D?
Try
defaults:
-
scope:
path: ""
type: "drafts"
values:
layout: "default"
Edit: Reading jekyll's it this is supposed to work but it doesn't because drafts are merged in posts collection. So when it comes to retrieve defaults only type: posts is applied and never drafts. See Jekyll::Document.
A trick it to put your drafts in /drafts/_drafts folder.
And to set your default like this :
-
scope:
path: "drafts"
values:
layout: "default"
The only drawback is that this will add a draft category to the post.categories array.
I do know that collections is an experimental feature in Jekyll, but since GitHub tutted the feature, I guess I could start using it.
I have a file structure like this:
site root
├─ _portfolio
│ ├─ project_1.md
│ └─ project_2.md
└─ /* rest of the Jekyll folders and contents */
This is what it looks like in Windows Explorer:
This is the content for marble-run.md:
---
layout: project
title: Marble Run
---
This is Marble Run. All tests copyrighted.
And this is the content for pokemon-walking.md:
---
layout: project
title: Pokémon Walking
---
This is Pokémon Walking.
I have set _portfolio as a collection in the _config.yml, and have the output set to true.
collections:
- portfolio:
output: true
I used the following code to display the portfolio page:
---
layout: default
---
<div class="portfolio_main">
{% for project in site.portfolio %}
<div class="projects_container">
Testing this.
<div>
{{ project.content }}
</div>
</div>
{% endfor %}
</div>
{{ site.portfolio }}{{ project.url }} gives /portfolio/{ title of the project }/. As in, /portfolio/marble-run/ for marble-run.md.
I expected to see two Testing this. links in the webpage, but I'm only seeing one.
My purpose is to create a collection folder that allows me to generate new contents whenever I put new Markdown files inside, just like what Jekyll does to _posts folder.
What am I doing wrong? Thanks in advance.
Okay, been tackling this problem for at least 6 hours.
Collections do work normally in GitHub Pages.
To set them up:
In _config.yml, add this at the very bottom:
collections:
- my_collections
Where my_collections are to be replaced with your collection folder name.
Do everything normally, according to the official Jekyll documentation.
The only caveat is, you need to put the permalinks correctly, or you won't be able to reference the items in the _my_collections folder (after doing what the docs told you to do).
That's all I know.
I would like to use Jekyll to create a site. not a blog. Is there a way to avoid to have the creation date specified in the url and in the page's file name?
I think that the idea behind Jekyll is brilliant, but it seems too tied to blog generation content while it could be useful also in a more general use case.
In the _config file you can change the permalink to anything you like, for example mine is
permalink: /blog/:title
As for the date you can choose your own date using the YAML front matter, again in mine i have
title: example
date: you can pick what ever date you want
What the docs say:
You configure permalinks in your _config.yml file like this:
permalink: /:categories/:year/:month/:day/:title.html
If you don’t specify any permalink setting, Jekyll uses the above pattern as the default. The permalink can also be set using a built-in permalink style:
permalink: date
Although you can specify a custom permalink pattern using template variables, Jekyll also provides the following built-in styles for convenience.
date = /:categories/:year/:month/:day/:title.html
pretty = /:categories/:year/:month/:day/:title/
ordinal = /:categories/:year/:y_day/:title.html
none = /:categories/:title.html
Source: https://jekyllrb.com/docs/permalinks/
This is the basic setting I use:
permalink: pretty
This sets pages to the pretty permalink style. Thus '/contact.md' will become '/contact/'.
How I use it for blog posts:
permalink: /blog/:title/
This makes sure the path contains the (sluggified) title.
How I use it for collections:
permalink: /desiredpath/:name/
This makes sure the path contains the filename.
If you aren't producing blog pages, you can create files in the directory structure mapping to certain URLs. Running on localhost, if your directory has the structure
- _layouts/
- config.yml
- index.html
- some_other_page.html
- some_directory/
- index.html
- some_sub_page.html
You'll have content at the following locations after jekyll has processed the files:
0.0.0.0:4000 (index.html)
0.0.0.0:4000/some_other_page.html (some_other_page.html)
0.0.0.0:4000/some_directory (some_directory/index.html)
0.0.0.0:4000/some_directory/some_sub_page.html (some_directory/some_sub_page.html)
You can also use the permalink attribute on each post to set one manually, or set a different default in config.yml Permalinks only have a small subset of variables available to use and need to be defined in every single file you want to put in a non-standard location.
This directory structure will automatically categorize your posts too. So you can have:
- some_category (defined in the yaml front matter or the _config.yml
- index.html
- _posts/
- some_post.md
- some_other_post.md
And posts will automatically have the category 'some category', and index.html will appear at 0.0.0.0:4000/some-category, with the default permalink format. The category variable is available as :category in the permalink format string.
I came across this old question while looking for a way to organize jekyll pages in a _pages directory, similarly to _posts. then access this pages without displaying the whole path in the url.
The approach that worked better for me, is to use jekyll collections as follows:
1 - Add a pages collection in _config.yml :
collections:
pages:
output: true
permalink: /:path/
2 - create a new directory named _pages (it should have the same collection name, prefixed by _)
3 - add the pages in the _pages folder, as .md or .html files starting with YAML Front Matter.
eg. /_pages/about.md will looks like:
---
layout: page
---
<!-- about page content -->
after building that, the URL of the about page will be <your-web-site>/about .
Alternatively, to display a collection name, you have to define its permalink as:
permalink: /:collection/:path/