diff --git a/.eleventy.js b/.eleventy.js index 29c2339..b971437 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -1,9 +1,47 @@ +require("dotenv").config(); + +const GhostContentAPI = require("@tryghost/content-api"); const pluginNavigation = require("@11ty/eleventy-navigation"); const pluginRss = require("@11ty/eleventy-plugin-rss"); +const api = new GhostContentAPI({ + url: process.env.GHOST_API_URL, + key: process.env.GHOST_CONTENT_API_KEY, + version: "v3.0" +}); + +const stripDomain = url => { + return url.replace(process.env.GHOST_API_URL, ""); +}; + module.exports = function(eleventyConfig) { eleventyConfig.addPlugin(pluginNavigation); eleventyConfig.addPlugin(pluginRss); eleventyConfig.addPassthroughCopy("css"); + + eleventyConfig.addCollection("posts", async function (collection) { + collection = await api.posts + .browse({ + include: "tags,authors", + limit: "all", + }) + .catch((err) => { + console.error(err); + }); + + collection.forEach((post) => { + console.log(post, "post") + post.url = stripDomain(post.url); + post.primary_author.url = stripDomain(post.primary_author.url); + + // Convert publish date into a Date object + post.date = new Date(post.published_at); + }); + + // Bring featured post to the top of the list + collection.sort((post, nextPost) => nextPost.featured - post.featured); + + return collection; + }); } \ No newline at end of file diff --git a/.gitignore b/.gitignore index 4879021..1df8868 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ /node_modules /_site +/.env \ No newline at end of file diff --git a/_data/metadata.json b/_data/metadata.json index 83b24ca..1fafb93 100644 --- a/_data/metadata.json +++ b/_data/metadata.json @@ -1,6 +1,6 @@ { "title": "walkah", - "url": "https://walkah.net/", + "url": "https://walkah.blog/", "description": "It's a new blog, just like the old blog.", "feed": { "filename": "feed.xml", diff --git a/_includes/layouts/base.njk b/_includes/layouts/default.njk similarity index 95% rename from _includes/layouts/base.njk rename to _includes/layouts/default.njk index 8489bf3..0e0e4d0 100644 --- a/_includes/layouts/base.njk +++ b/_includes/layouts/default.njk @@ -24,7 +24,8 @@
- {{ content | safe }} + {% block content %} + {% endblock content %}