diff --git a/.eleventy.js b/.eleventy.js index d001d75..04e8291 100644 --- a/.eleventy.js +++ b/.eleventy.js @@ -7,7 +7,7 @@ module.exports = function(eleventyConfig) { else throw 'Unrecognized data format' } catch(e) { - console.log(`Could not convert "${value}"`, e) + console.error(`Could not convert "${value}"`, e) return value; } }); @@ -19,7 +19,7 @@ module.exports = function(eleventyConfig) { else throw 'Unrecognized data format' } catch(e) { - console.log(`Could not convert "${value}"`, e) + console.error(`Could not convert "${value}"`, e) return value; } }); @@ -28,9 +28,66 @@ module.exports = function(eleventyConfig) { return collectionApi.getFilteredByGlob("_content/notes/*.md").reverse(); }); + eleventyConfig.addCollection("feed", function(collectionApi) { + return collectionApi.getAllSorted().reverse().filter(item => { + let showInFeed = false; + //if(!item.data.published) return false + if(item.filePathStem.startsWith('/notes/')){ + if(item.data['like-of']) item.data.postType = "like" + else if(item.data['in-reply-to']) item.data.postType = "reply" + else if(item.data['repost-of']) item.data.postType = "boost" + else if(item.data['read-of']) item.data.postType = "read" + else if(item.data['watch-of']) item.data.postType = "watch" + else item.data.postType = "note"; + showInFeed = true; + } + else if(item.filePathStem.startsWith('/articles/')){ + item.data.postType = "article"; + showInFeed = true; + } + else if (item.filePathStem.startsWith('/bookmarks/')){ + item.data.postType = "bookmark"; + showInFeed = true; + } + else if (item.filePathStem.startsWith('/likes/')){ + item.data.postType = "like"; + showInFeed = true; + } + else if (item.filePathStem.startsWith('/rsvp/')){ + item.data.postType = "rsvp"; + showInFeed = true; + } + else if (item.filePathStem.startsWith('/watched/')){ + item.data.postType = "watched"; + showInFeed = true; + } + + // if(showInFeed) { + // item.data.author = + // } + + return showInFeed; + }); + }); + + eleventyConfig.addNunjucksShortcode("getVar", function(varString) { + return this.ctx[varString]; + }); + + eleventyConfig.addShortcode('renderlayoutblock', function(name) { + return (this.page.layoutblock || {})[name] || ''; + }); + + eleventyConfig.addPairedShortcode('layoutblock', function(content, name) { + if (!this.page.layoutblock) this.page.layoutblock = {}; + this.page.layoutblock[name] = content; + return ''; + }); + eleventyConfig.addPassthroughCopy({"img":"assets/img"}); eleventyConfig.addPassthroughCopy({"js":"assets/js"}); eleventyConfig.addPassthroughCopy("css"); + eleventyConfig.addPassthroughCopy("CNAME"); // Return your Object options: return { @@ -38,6 +95,7 @@ module.exports = function(eleventyConfig) { input: "_content", output: "pub" }, + htmlTemplateEngine: "njk", templateFormats: ["md","html"] } }; \ No newline at end of file diff --git a/.gitignore b/.gitignore index 843f7a9..0a9ed5a 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ node_modules +pub \ No newline at end of file diff --git a/_content/_data/author.js b/_content/_data/author.js new file mode 100644 index 0000000..1a4d61c --- /dev/null +++ b/_content/_data/author.js @@ -0,0 +1,57 @@ +const EleventyFetch = require("@11ty/eleventy-fetch"); + +module.exports = async function() { + // set these default options + let author = { + "handle": "@death.au@death.id.au", + "display_name": "death.au", + "url": "https://death.id.au", // this is the domain your webfinger is on + "avatar": "/assets/img/avatar-tt.svg" // avatar to use by default + } + + try { + // options for the cached fetch request + const options = { + duration: "1d", // 1 day + type: "json", // also supports "text" or "buffer" + fetchOptions: { + headers: { + 'Content-Type': 'application/activity+json' + } + } + } + + // get the webfinger + handle = author.handle.startsWith('@') ? author.handle.substring(1) : author.handle; + let webfinger = await EleventyFetch(`${author.url}/.well-known/webfinger?resource=acct:${handle}`, options); + + // get the canonical uri as well + let canonical_uri = webfinger?.links?.find(link => link.rel == "canonical_uri") + if(canonical_uri) author.canonical_uri = canonical_uri.href + + // get the rel="self" link from the webfinger + let self = webfinger?.links?.find(link => link.rel == "self"); + + if(self) { + // fetch the profile information + if(self.type) options.fetchOptions.headers['Content-Type'] = self.type; + json = await EleventyFetch(self.href, options); + + // apply the supplied author information to the result + json.handle = author.handle + json.avatar = author.avatar + json.display_name = author.display_name || json.preferredUsername + json.canonical_uri = author.canonical_uri || json.url[0] + + // this is now the author object + author = json + } + else throw 'Could not find rel="self" link in webfinger' + + return author + } + catch(e) { + console.error("Failed to get webfinger info ", e); + return author + } +}; \ No newline at end of file diff --git a/_content/_data/layout.js b/_content/_data/layout.js new file mode 100644 index 0000000..c98ebc5 --- /dev/null +++ b/_content/_data/layout.js @@ -0,0 +1 @@ +module.exports = "layout-default.njk" \ No newline at end of file diff --git a/_content/_includes/layout-default.njk b/_content/_includes/layout-default.njk new file mode 100644 index 0000000..1e31049 --- /dev/null +++ b/_content/_includes/layout-default.njk @@ -0,0 +1,13 @@ +---js +{ + layout: "layout-main.njk", + ctx: function() { return this.ctx } +} +--- +{% from "macro-entry.njk" import entryMacro %} + +{{ entryMacro(ctx(), url, content) }} + +{% layoutblock 'foot' %} + +{% endlayoutblock %} diff --git a/_content/_includes/layout-feed.njk b/_content/_includes/layout-feed.njk new file mode 100644 index 0000000..9977d86 --- /dev/null +++ b/_content/_includes/layout-feed.njk @@ -0,0 +1,15 @@ +--- +title: Feed +layout: layout-main.njk +scripts_foot: '' +--- +