How to access static files in a collection? - jekyll

How do I access static files in a collection?
I have (I think) followed the instructions at
https://jekyllrb.com/docs/collections/
I created a dir ./_test and static files ./_test/a and ./_test/b and added a corresponding collection entry in _config.yml:
collections:
- test
After this I cannot use site.test.files to get an array containing the files ./_test/a and ./_test/b (as should be possible, per my interpretation of the above Jekyll documentation).
(I use the Jekyll version provided by GitHub-Pages.)

Say you have both, some files with yaml front matter and static files witch are not processed by jekyll. These files can be accessed as follows:
files with front matter:
{% assign test_docs = site.test %}
{{ test_docs }}
static files:
{% assign test_coll = site.collections | where: "label", "test" | first %}
{{ test_coll.files }}
As you asked explicitly for static files, in the code above {{ test_coll.files }} contains the array with both files /_test/a and /_test/b. But, only if these files do not have a yaml front matter.

Related

Github profile or repo card on websites made on Jekyll

How to set up/embed github profile or github repository cards on your Jekyll personal website?
I am expecting to embed my personal projects from github in the form of widgets on my personal website.
I don't see a direct way to include data in static Jekyll HTML files.
But there are options:
GitHub offers a JSON API for repos and users. Not sure what profile information you're looking for.
Jekyll has data files in YAML where you can store this data and read information from.
My initial idea is to get data in JSON and convert it to YAML, manually or programmatically. Then, you can build a Jekyll site that reads the information from the YAML files.
You can try out the manual way:
Read data from https://api.github.com/users/cadamini/repos using https://reqbin.com/
Convert the resulting JSON file using https://www.json2yaml.com/
Put the resulting YAML file in your Jekyll instance, e.g in _data/github/repos.yml (exclude the hyphens).
Extract:
- id: 540417594
node_id: R_kgDOIDYeOg
name: add-theme-github-pages-demo
full_name: cadamini/add-theme-github-pages-demo
private: false
Use the following code/syntax to access the information:
{% for item in data.github.repos %}
{{ item.name }}
{% endfor %}

Getting a template partial from parent folders

My project is separated into many modules.
Each module has its own /templates folder that contains its own relevant template files.
There are common components (header, nav) inside these template files that I wish to extract into 'partials' which are then included inside the each module's template files (ie: {% include 'nav.html' %}
The Question
How can I set up my template environment in such a way that allows for the module's template files to reach into a shared folder that contains these partials?
My Current Environment Setup
template_dir = os.path.join(os.path.dirname(__file__), 'views')
env = jinja2.Environment(
loader=jinja2.FileSystemLoader(template_dir),
autoescape=True)
self.render('some_template.html', env=env) # render function
This current configuration only allows me to reach into the /templates folder within each module. However, the templates files (inside the /templates dir) should also have access to the partial files that are outside of each module's directory.
Ideally, the app directory would look like this:
app/
shared/
header.html <-- templates within modules need to access these
nav.html
modules/
module_a/
handler.py
templates/
my_template.html <-- needs access to partials from 'shared/'
module_b/
module_c/

Exclude Jekyll posts from output (don't output individual HTML files)

Since I list all my posts in one page called fotos.html I don't need the individual posts to appear as HTML files in the _site output directory. How can I tell Jekyll to not output the .md posts in the _posts directory as individual HTML files?
[
E.g. The contents of Firmwochenende.html are present in fotos.html with properly formatted title and date. Firmwochenende.html includes only photos and nothing else, which is not useful at all.
I build using build exec jekyll serve and host on Github Pages: https://github.com/junge-pfarre/junge-pfarre.github.io
These are the relevant parts of _config.yml:
defaults:
- scope:
path: ""
values:
layout: "default"
- scope:
path: "assets/flyer"
values:
flyer: true
markdown: kramdown
permalink: :title
A simple post has these contents:
---
title: Jugendandacht Gründonnerstag
---
![Altar der Josefskapelle in der Pfarrkirche Baden St. Stephan][1]
[1]: {{ site.baseurl }}{% link /assets/fotos/Jugendandacht2018.jpg %}
You'll need to use a custom collection rather than the default as the _posts collection is, by design, always going to output individual files. If you create a new collection, you can specify output: false for that collection in your config file while still being able to iterate through it and display the content. From the Jekyll documentation:
# Config file
collections:
your_collection_name:
output: false
However, I saw that you mentioned pagination in the comments. I don't believe GitHub currently supports a gem that has pagination functionality for collections other than _posts (like jekyll-paginate-v2, though they're in talks on merging this in eventually). In the meantime, it looks like there are some solutions out there to help with this limitation.

How do I provide files for download?

I have written a post and would like to provide a file as attachment for download.
So far I have
created a link [Download files][download-file]
declared the link as [download-file]: download.zip
put download.zip in the _posts folder
However, the file does not get copied to the correct location.
I have
read about data files
read about directory structure
read about static files, which IMHO was the closest hit. Unfortunately, no example is provided.
So neither page gave me an answer on how to provide files for download.
I don't know where to put static files in the directory structure. Once I knew that, it seems I could use some Liquid like {{ site.static_files }}, but even then I'd still need to specify a file name.
Here is my solution. I have a "myname".github.io, I created a folder /download inside the myname.github.io and inside this download folder I uploaded the files I want to include in my posts.
In the single post then I created the following code:
some text and [here is possible to download the file in PDF][1]
[1]:{{ site.url }}/download/file.pdf
You can place your download.zip file in the root of your project, and it will get copied over to {{ site.url }}/download.zip. If you'd like it contained in a folder, you can create any folder, eg download/, and any file will be able to accessed via {{ site.url }}/download/*.
Every other directory and file except for [the Jekyll files]—such as css and images folders, favicon.ico files, and so forth—will be copied verbatim to the generated site.
from the Jekyll Docs

CouchDB templating system: extend with separate footer & header

I'm using couchdb\couchapp to host a web application.
I comes from Django, and with jinja2 I'm able to extend templates in two ways:
{% include "header.html" %}
or
{% extends "base.html" %} <<<---- preferred
I'm looking for a way to do the same with CouchDB, now I have header and footer code written in every single page and, obv, it doesn't look as best practice.
Thank you in advance.
Couch db supports common js modules which means that you can export the mustache/or other templating library as a string and then require it in your show function. More explanation on this mail archive
If you want to use JavaScript on the server side, you'll need to store it as a
property on your design doc. So in a "lib" folder (outside of _attachments)
with the 'couchapp' it will get included like:
couchapp folder
_id file
|_ _attachments folder
|_ ...clientside media...
|_ lib folder
|_ mustache.js
<---->
{_id:"", _attachments: {...}, lib:{mustache:""}}
Then you would use it in a _show/_list/_update function with var Mustache =
require('lib/mustache'). When I do need a library both server and clientside
with 'couchapp', I tend to symlink it so it appears in both _attachments and
other properties.
hope this helps,
-natevw