Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
143 changes: 73 additions & 70 deletions .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@

module.exports = function (eleventyConfig) {

// SIGHTS - custom collections
const nowsights = new Date();
const sightslivePosts = (post) => post.date <= nowsights;
Expand All @@ -10,6 +8,19 @@ module.exports = function (eleventyConfig) {
].reverse();
});

eleventyConfig.addFilter("head", (arr = [], idx = 0) => {
if (idx < 0) {
return arr.slice(idx);
}
return arr.slice(0, idx);
});
Comment on lines +11 to +16
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can probably ignore this. I think it was from the index.njk and was throwing errors saying there wasn't a "head" filter, so I took a random guess. But then ended up using Nunjucks comments to comment out those code blocks anyways.


eleventyConfig.addFilter("tagsList", (arr = []) => {
const tagsSet = new Set();
arr.forEach((item) => item.data.tags?.forEach((tag) => tagsSet.add(tag)));
return [...tagsSet].sort((b, a) => b.localeCompare(a));
});
Comment on lines +18 to +22
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is basically the same logic as your custom collection, except for as a filter; so now you can pass a custom collection.


// SOUNDS - custom collections
const nowsounds = new Date();
const soundslivePosts = (post) => post.date <= nowsounds;
Expand All @@ -21,72 +32,64 @@ module.exports = function (eleventyConfig) {

// generate a list of all tags collections
// with alphabetical sorting - had to invert to "b, a" because it was sorting upside down
eleventyConfig.addCollection('tagsList', (collectionApi) => {
const tagsSet = new Set()
collectionApi.getAll().forEach((item) => {
if (!item.data.tags) return
item.data.tags.forEach((tag) => tagsSet.add(tag))
})
return [...tagsSet].sort((b, a) => b.localeCompare(a))
});


// https://www.11ty.dev/docs/copy/#manual-passthrough-file-copy-(faster)
eleventyConfig.addPassthroughCopy('assets');
eleventyConfig.addPassthroughCopy('sitemap.xml');
eleventyConfig.addPassthroughCopy('robots.txt');


// format dates on SIGHTS and SOUNDS Articles
const dateformat = require('./lib/filters/dateformat');
eleventyConfig.addFilter('datefriendly', dateformat.friendly);
eleventyConfig.addFilter('dateymd', dateformat.ymd);


// "return" in order to keep the previously entered configuration values
// taken from: https://github.com/11ty/eleventy-base-blog/blob/master/.eleventy.js
return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: [
"md",
"njk",
"html",
"liquid"
],

// added
passthroughFileCopy: true,

// -----------------------------------------------------------------
// If your site deploys to a subdirectory, change `pathPrefix`.
// Don’t worry about leading and trailing slashes, we normalize these.

// If you don’t have a subdirectory, use "" or "/" (they do the same thing)
// This is only used for link URLs (it does not affect your file structure)
// Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/

// You can also pass this in on the command line using `--pathprefix`

// Optional (default is shown)
pathPrefix: "/",
// -----------------------------------------------------------------

// Pre-process *.md files with: (default: `liquid`)
markdownTemplateEngine: "njk",

// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: "njk",

// Opt-out of pre-processing global data JSON files: (default: `liquid`)
dataTemplateEngine: false,

// These are all optional (defaults are shown):
dir: {
input: ".",
includes: "_includes",
data: "_data",
output: "_site"
}
};
// eleventyConfig.addCollection('tagsList', (collectionApi) => {
// const tagsSet = new Set()
// collectionApi.getAll().forEach((item) => {
// if (!item.data.tags) return
// item.data.tags.forEach((tag) => tagsSet.add(tag))
// })
// return [...tagsSet].sort((b, a) => b.localeCompare(a))
// });

// https://www.11ty.dev/docs/copy/#manual-passthrough-file-copy-(faster)
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can ignore all these changes below. I think I ran prettier against the input/output and it probably fixed the indenting here.

eleventyConfig.addPassthroughCopy("assets");
eleventyConfig.addPassthroughCopy("sitemap.xml");
eleventyConfig.addPassthroughCopy("robots.txt");

// format dates on SIGHTS and SOUNDS Articles
const dateformat = require("./lib/filters/dateformat");
eleventyConfig.addFilter("datefriendly", dateformat.friendly);
eleventyConfig.addFilter("dateymd", dateformat.ymd);

// "return" in order to keep the previously entered configuration values
// taken from: https://github.com/11ty/eleventy-base-blog/blob/master/.eleventy.js
return {
// Control which files Eleventy will process
// e.g.: *.md, *.njk, *.html, *.liquid
templateFormats: ["md", "njk", "html", "liquid"],

// added
passthroughFileCopy: true,

// -----------------------------------------------------------------
// If your site deploys to a subdirectory, change `pathPrefix`.
// Don’t worry about leading and trailing slashes, we normalize these.

// If you don’t have a subdirectory, use "" or "/" (they do the same thing)
// This is only used for link URLs (it does not affect your file structure)
// Best paired with the `url` filter: https://www.11ty.dev/docs/filters/url/

// You can also pass this in on the command line using `--pathprefix`

// Optional (default is shown)
pathPrefix: "/",
// -----------------------------------------------------------------

// Pre-process *.md files with: (default: `liquid`)
markdownTemplateEngine: "njk",

// Pre-process *.html files with: (default: `liquid`)
htmlTemplateEngine: "njk",

// Opt-out of pre-processing global data JSON files: (default: `liquid`)
dataTemplateEngine: false,

// These are all optional (defaults are shown):
dir: {
input: ".",
includes: "_includes",
data: "_data",
output: "_site",
},
};
};
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules
7 changes: 2 additions & 5 deletions index.njk
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,7 @@ local: en

<h1>HOMEPAGE</h1>

<!--

TO DO
{# TO DO
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Used a Nunjucks comment so that it wouldnt try compiling the code below (see previous note about missing head filter).


Here I want to FILTER RECENT POSTS
respectively for categories SIGHTS + SOUNDS with the latest 4 posts for each category
Expand Down Expand Up @@ -42,6 +40,5 @@ as explained here: https://github.com/11ty/eleventy/issues/503 ( pdkaizer commen
pagination:
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?
size: 4
reverse: true
reverse: true #}

-->
4 changes: 2 additions & 2 deletions sights/tags.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pagination:
- sounds
- tagsList
addAllPagesToCollections: true
permalink: /sights/tags/{{ tag | slug }}/
permalink: "/sights/tags/{{ tag | slug }}/"
---
<!-- this should be tag archive for SIGHTS category only -->
<!-- This will create a page for every tag -->
Expand All @@ -33,7 +33,7 @@ permalink: /sights/tags/{{ tag | slug }}/
<p>
<!-- PROBLEM -->
<!-- outputs tags. Should be all tags for collection.sights only, but outputs also all collections.sounds tags - I don't want this to happen and I have to find a solution -->
{% for tag in collections.tagsList %}
{% for tag in collections.sights | tagsList %}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So instead of using collections.tagsList (which uses .getAll() and getting sights+sounds) I can use the new custom tagsList filter to just generate a tag list for the "sights" collection specifically.

<a href="/sights/tags/{{ tag | slug }}" class="tags">{{tag}}</a>
{% endfor %}
</p>
Expand Down
4 changes: 2 additions & 2 deletions sounds/tags.njk
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ pagination:
- sounds
- tagsList
addAllPagesToCollections: true
permalink: /sounds/tags/{{ tag | slug }}/
permalink: "/sounds/tags/{{ tag | slug }}/"
---
<!-- this should be tag archive for SOUNDS category only -->
<!-- This will create a page for every tag -->
Expand All @@ -33,7 +33,7 @@ permalink: /sounds/tags/{{ tag | slug }}/
<p>
<!-- PROBLEM -->
<!-- outputs tags. Should be all tags for collection.sounds only, but outputs also all collections.sights tags - I don't want this to happen and I have to find a solution -->
{% for tag in collections.tagsList %}
{% for tag in collections.sounds | tagsList %}
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See comment above re "collections.sights" and custom tagsList filter.

<a href="/sounds/tags/{{ tag | slug }}" class="tags">{{tag}}</a>
{% endfor %}
</p>
Expand Down