diff --git a/_data/recentComments.js b/_data/recentComments.js new file mode 100644 index 0000000..bdd1ede --- /dev/null +++ b/_data/recentComments.js @@ -0,0 +1,24 @@ +/** + * Recent Comments Data + * Fetches the 5 most recent comments at build time for the sidebar widget. + */ + +import EleventyFetch from "@11ty/eleventy-fetch"; + +const INDIEKIT_URL = process.env.SITE_URL || "https://example.com"; + +export default async function () { + try { + const url = `${INDIEKIT_URL}/comments/api/comments?limit=5`; + console.log(`[recentComments] Fetching: ${url}`); + const data = await EleventyFetch(url, { + duration: "15m", + type: "json", + }); + console.log(`[recentComments] Got ${(data.children || []).length} comments`); + return data.children || []; + } catch (error) { + console.log(`[recentComments] Unavailable: ${error.message}`); + return []; + } +} diff --git a/_includes/components/blog-sidebar.njk b/_includes/components/blog-sidebar.njk index 799b5aa..2ac1d85 100644 --- a/_includes/components/blog-sidebar.njk +++ b/_includes/components/blog-sidebar.njk @@ -32,6 +32,8 @@ {% include "components/widgets/feedland.njk" %} {% elif widget.type == "categories" %} {% include "components/widgets/categories.njk" %} + {% elif widget.type == "recent-comments" %} + {% include "components/widgets/recent-comments.njk" %} {% elif widget.type == "search" %}