blog/.eleventy.js

47 lines
1.3 KiB
JavaScript
Raw Normal View History

2022-05-19 22:08:42 -04:00
require("dotenv").config();
const GhostContentAPI = require("@tryghost/content-api");
2022-05-10 21:41:47 -04:00
const pluginNavigation = require("@11ty/eleventy-navigation");
const pluginRss = require("@11ty/eleventy-plugin-rss");
2022-05-19 22:08:42 -04:00
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, "");
};
2022-05-10 21:41:47 -04:00
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(pluginNavigation);
eleventyConfig.addPlugin(pluginRss);
eleventyConfig.addPassthroughCopy("css");
2022-05-19 22:08:42 -04:00
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;
});
2022-05-10 21:41:47 -04:00
}