56 lines
1.5 KiB
JavaScript
56 lines
1.5 KiB
JavaScript
require("dotenv").config();
|
|
|
|
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 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.addPassthroughCopy("images");
|
|
|
|
eleventyConfig.addPlugin(localImages, {
|
|
distPath: '_site',
|
|
assetPath: '/assets/images',
|
|
selector: 'img',
|
|
verbose: false
|
|
});
|
|
|
|
eleventyConfig.addCollection("posts", async function (collection) {
|
|
collection = await api.posts
|
|
.browse({
|
|
include: "tags,authors",
|
|
limit: "all",
|
|
})
|
|
.catch((err) => {
|
|
console.error(err);
|
|
});
|
|
|
|
collection.forEach((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);
|
|
|
|
console.log(collection);
|
|
return collection;
|
|
});
|
|
} |