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 @@