Changed post_url shortcode

Changed so it doesn't need a collection passed in. Should probably have a second option that does
This commit is contained in:
Robert McGovern 2023-02-20 02:43:09 +00:00
parent 61809329ec
commit 27b514e9bd
3 changed files with 16 additions and 10 deletions

View File

@ -105,8 +105,8 @@ module.exports = function (eleventyConfig) {
collection.getFilteredByGlob("./src/_pages/**/*") collection.getFilteredByGlob("./src/_pages/**/*")
); );
eleventyConfig.addCollection("posts", (collection) => eleventyConfig.addCollection("posts", (collection) => {
collection availablePages = collection
.getFilteredByGlob("./src/_posts/**/*") .getFilteredByGlob("./src/_posts/**/*")
.filter( .filter(
(item) => item.data.draft !== true && item.date <= new Date() (item) => item.data.draft !== true && item.date <= new Date()
@ -118,8 +118,10 @@ module.exports = function (eleventyConfig) {
prev: all[i + 1], prev: all[i + 1],
}; };
return cur; return cur;
}) });
);
return availablePages;
});
eleventyConfig.addCollection("projects", (collection) => eleventyConfig.addCollection("projects", (collection) =>
collection collection
@ -259,7 +261,11 @@ module.exports = function (eleventyConfig) {
eleventyConfig.addPassthroughCopy("src/assets"); eleventyConfig.addPassthroughCopy("src/assets");
// eleventyConfig.addPassthroughCopy({ "src/_sass": "assets/css" }); // eleventyConfig.addPassthroughCopy({ "src/_sass": "assets/css" });
eleventyConfig.addShortcode("post_url", (collection, slug) => { let availablePages = [];
eleventyConfig.addShortcode("post_url", (slug) => {
let collection = availablePages;
try { try {
if (collection.length < 1) { if (collection.length < 1) {
throw "Collection appears to be empty"; throw "Collection appears to be empty";
@ -279,7 +285,7 @@ module.exports = function (eleventyConfig) {
} }
} catch (e) { } catch (e) {
console.error( console.error(
`RMCG:An error occured while searching for the url to ${slug}. Details:`, `RMCG:An error occurred while searching for the url to ${slug}. Details:`,
e e
); );
} }

View File

@ -23,7 +23,7 @@ gallery:
title: DevOps Roadmap title: DevOps Roadmap
date: 2020-04-21 00:44:00 +01:00 date: 2020-04-21 00:44:00 +01:00
--- ---
I mentioned in the [goals post]({% post_url collections.posts, "goals" %}), one of the things I am aiming to do is to start learning web development. I mentioned in the [goals post]({% post_url "goals" %}), one of the things I am aiming to do is to start learning web development.
I was well aware that what falls under the banner of web development is massive, I just hadn't realised quite how large it was. I was well aware that what falls under the banner of web development is massive, I just hadn't realised quite how large it was.

View File

@ -7,9 +7,9 @@ pagination:
--- ---
{%- for post in pagination.items -%} {%- for post in pagination.items -%}
<h2><a href="{% post_url collections.posts, post.fileSlug %}">{{ post.data.title }}</a></h2> <h2><a href="{% post_url post.fileSlug %}">{{ post.data.title }}</a></h2>
<em>{{ post.data.date | toUTCString}}</em> <em>{{ post.data.date | toUTCString}}</em>
<p>{{ post.templateContent | description }} <a href="{% post_url collections.posts, post.fileSlug %}"><em>read more</em></a></p> <p>{{ post.templateContent | description }} <a href="{% post_url post.fileSlug %}"><em>read more</em></a></p>
{%- endfor -%} {%- endfor -%}
@ -45,4 +45,4 @@ pagination:
<a href="#" class="pagination disabled">{{ "Last" }}</a> <a href="#" class="pagination disabled">{{ "Last" }}</a>
{% endif %} {% endif %}
</li> </li>
</ul> </ul>