From 49a806203fe92d807c3acb81e04d309d466839cf Mon Sep 17 00:00:00 2001 From: James Walker Date: Thu, 8 Dec 2022 18:07:41 -0500 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20add=20relativePath=20filter?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #2 --- .eleventy.js | 9 +++++++++ _includes/layouts/default.njk | 10 +++++----- _includes/layouts/post.njk | 2 +- index.njk | 4 ++-- 4 files changed, 17 insertions(+), 8 deletions(-) diff --git a/.eleventy.js b/.eleventy.js index 1ef0d19..64098b8 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -4,6 +4,7 @@ const GhostContentAPI = require("@tryghost/content-api"); const pluginNavigation = require("@11ty/eleventy-navigation"); const pluginRss = require("@11ty/eleventy-plugin-rss"); const localImages = require('eleventy-plugin-local-images'); +const path = require("path"); const api = new GhostContentAPI({ url: process.env.GHOST_API_URL, @@ -33,6 +34,14 @@ module.exports = function (eleventyConfig) { return new Date(dateObj).toISOString().split("T")[0]; }); + eleventyConfig.addFilter("relativePath", (pathToFilter, page) => { + if (!pathToFilter.startsWith("/")) { + return pathToFilter; + } + + return path.relative(page.url, pathToFilter); + }) + eleventyConfig.addCollection("posts", async function (collection) { collection = await api.posts .browse({ diff --git a/_includes/layouts/default.njk b/_includes/layouts/default.njk index b97945e..aedc323 100644 --- a/_includes/layouts/default.njk +++ b/_includes/layouts/default.njk @@ -5,17 +5,17 @@ {{ title or metadata.title }} - - - + + +
diff --git a/_includes/layouts/post.njk b/_includes/layouts/post.njk index 58f15ff..8a18264 100644 --- a/_includes/layouts/post.njk +++ b/_includes/layouts/post.njk @@ -25,7 +25,7 @@