Skip to content

Commit 387a649

Browse files
committed
Initial commit
0 parents  commit 387a649

23 files changed

+622
-0
lines changed

.eleventy.js

Lines changed: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
1+
2+
module.exports = function (eleventyConfig) {
3+
4+
// SIGHTS - custom collections
5+
const nowsights = new Date();
6+
const sightslivePosts = (post) => post.date <= nowsights;
7+
eleventyConfig.addCollection("sights", (collection) => {
8+
return [
9+
...collection.getFilteredByGlob("./sights/*.njk").filter(sightslivePosts),
10+
].reverse();
11+
});
12+
13+
// SOUNDS - custom collections
14+
const nowsounds = new Date();
15+
const soundslivePosts = (post) => post.date <= nowsounds;
16+
eleventyConfig.addCollection("sounds", (collection) => {
17+
return [
18+
...collection.getFilteredByGlob("./sounds/*.njk").filter(soundslivePosts),
19+
].reverse();
20+
});
21+
22+
// generate a list of all tags collections
23+
// with alphabetical sorting - had to invert to "b, a" because it was sorting upside down
24+
eleventyConfig.addCollection('tagsList', (collectionApi) => {
25+
const tagsSet = new Set()
26+
collectionApi.getAll().forEach((item) => {
27+
if (!item.data.tags) return
28+
item.data.tags.forEach((tag) => tagsSet.add(tag))
29+
})
30+
return [...tagsSet].sort((b, a) => b.localeCompare(a))
31+
});
32+
33+
34+
// https://www.11ty.dev/docs/copy/#manual-passthrough-file-copy-(faster)
35+
eleventyConfig.addPassthroughCopy('assets');
36+
eleventyConfig.addPassthroughCopy('sitemap.xml');
37+
eleventyConfig.addPassthroughCopy('robots.txt');
38+
39+
40+
// format dates on SIGHTS and SOUNDS Articles
41+
const dateformat = require('./lib/filters/dateformat');
42+
eleventyConfig.addFilter('datefriendly', dateformat.friendly);
43+
eleventyConfig.addFilter('dateymd', dateformat.ymd);
44+
45+
46+
// "return" in order to keep the previously entered configuration values
47+
// taken from: https://github.com/11ty/eleventy-base-blog/blob/master/.eleventy.js
48+
return {
49+
// Control which files Eleventy will process
50+
// e.g.: *.md, *.njk, *.html, *.liquid
51+
templateFormats: [
52+
"md",
53+
"njk",
54+
"html",
55+
"liquid"
56+
],
57+
58+
// added
59+
passthroughFileCopy: true,
60+
61+
// -----------------------------------------------------------------
62+
// If your site deploys to a subdirectory, change `pathPrefix`.
63+
// Don’t worry about leading and trailing slashes, we normalize these.
64+
65+
// If you don’t have a subdirectory, use "" or "/" (they do the same thing)
66+
// This is only used for link URLs (it does not affect your file structure)
67+
// Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/
68+
69+
// You can also pass this in on the command line using `--pathprefix`
70+
71+
// Optional (default is shown)
72+
pathPrefix: "/",
73+
// -----------------------------------------------------------------
74+
75+
// Pre-process *.md files with: (default: `liquid`)
76+
markdownTemplateEngine: "njk",
77+
78+
// Pre-process *.html files with: (default: `liquid`)
79+
htmlTemplateEngine: "njk",
80+
81+
// Opt-out of pre-processing global data JSON files: (default: `liquid`)
82+
dataTemplateEngine: false,
83+
84+
// These are all optional (defaults are shown):
85+
dir: {
86+
input: ".",
87+
includes: "_includes",
88+
data: "_data",
89+
output: "_site"
90+
}
91+
};
92+
};

.gitattributes

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
# Auto detect text files and perform LF normalization
2+
* text=auto

_includes/_head.njk

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
<meta charset="UTF-8">
2+
<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=2.0">
3+
<title>{{ meta_title }}</title>

_includes/_navbar.njk

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
2+
<ul>
3+
4+
<li><a href="/sights/">sights</a></li>
5+
<li><a href="/sounds/">sounds</a></li>
6+
7+
</ul>

_includes/_pages-layout.njk

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
<!DOCTYPE html>
2+
<html lang="{{ local }}">
3+
4+
<head>
5+
{% include "_head.njk" %}
6+
</head>
7+
8+
<body>
9+
10+
<header>
11+
{% include "_navbar.njk" %}
12+
</header>
13+
14+
<main>
15+
{{ content | safe }}
16+
</main>
17+
18+
</body>
19+
</html>

_includes/layouts/base.njk

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<!DOCTYPE html>
2+
<html lang="{{ local }}">
3+
4+
<head>
5+
{% include "_head.njk" %}
6+
</head>
7+
8+
<body>
9+
10+
<header>
11+
{% include "_navbar.njk" %}
12+
</header>
13+
14+
<main>
15+
16+
<div>{% block content %} {% endblock content %}</div>
17+
18+
<!-- base layout for articles -->
19+
20+
</main>
21+
22+
</body>
23+
</html>

_includes/layouts/post.njk

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
{% extends 'layouts/base.njk' %}
3+
4+
{% block content %}
5+
6+
{{ content | safe }}
7+
8+
<!-- layout for each article - with extends to base layout -->
9+
10+
{% endblock %}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
{% if pagination.href.previous or pagination.href.next %}
2+
<br>
3+
4+
{% if pagination.href.previous %}
5+
<a href="{{ pagination.href.previous }}" data-direction="backwards">
6+
Previous page
7+
</a>
8+
{% endif %}
9+
{% if pagination.href.next %}
10+
<a href="{{ pagination.href.next }}" data-direction="forwards">
11+
Next page
12+
</a>
13+
<!-- just the pagination previous and next -->
14+
{% endif %}
15+
{% endif %}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
{% if postListItems.length %}
3+
4+
{% for item in postListItems %}
5+
6+
7+
<!-- this is a list of posts which serves the pagination and tag overview pages -->
8+
9+
10+
<!-- START articles -->
11+
<article>
12+
<div>
13+
<a href="{{ item.url }}">
14+
<p>{% if item.data.date %}<time datetime="{{ item.data.date | dateymd }}">{{ item.data.date | datefriendly }}</time>{% endif %}</p>
15+
<h2>{{ item.data.title }}</h2>
16+
<p>{{ item.data.details }}</p></a>
17+
</div>
18+
</article>
19+
<!-- END articles -->
20+
21+
{% endfor %}
22+
23+
{% endif %}

index.njk

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
---
2+
eleventyExcludeFromCollections: true
3+
layout: _pages-layout.njk
4+
local: en
5+
---
6+
7+
<h1>HOMEPAGE</h1>
8+
9+
<!--
10+
11+
TO DO
12+
13+
Here I want to FILTER RECENT POSTS
14+
respectively for categories SIGHTS + SOUNDS with the latest 4 posts for each category
15+
16+
I think that I have to create 2 custom sorted collections (one for SIGHTS and one for SOUNDS)
17+
and slice array to filter the number of recent posts on each collection
18+
19+
Maybe I can try as follows:
20+
21+
// eleventy.js
22+
eleventyConfig.addCollection("latestSights", function(collection) {
23+
return collection.getAllSorted().reverse().slice(0, 4);
24+
});
25+
eleventyConfig.addCollection("LatestSounds", function(collection) {
26+
return collection.getAllSorted().reverse().slice(0, 4);
27+
});
28+
29+
and something like this here on homepage:
30+
31+
{% set postslist = collections.latestSights | head(-4) %}
32+
{% set postslistCounter = collections.latestSights | length %}
33+
{% include "partials/components/post-list.njk" %}
34+
35+
{% set postslist = collections.latestSounds | head(-4) %}
36+
{% set postslistCounter = collections.latestSounds | length %}
37+
{% include "partials/components/post-list.njk" %}
38+
39+
N.B. Maybe I will have also to put this in front matter
40+
as explained here: https://github.com/11ty/eleventy/issues/503 ( pdkaizer commented on 25 Apr 2019 )
41+
42+
pagination:
43+
data: collections... // the problem here is that I can specify only 1 collection and I have two of them to output on this page: how to solve this?
44+
size: 4
45+
reverse: true
46+
47+
-->

0 commit comments

Comments
 (0)