From db54ca40c6de5c491ed36c0d8dda723e1acd204a Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Fri, 5 Jan 2024 13:36:37 +0000 Subject: [PATCH] More work on the archive. Start rendering conversations --- config/filters/index.js | 1 + config/filters/notes.js | 14 ++++++++++++++ config/plugins/markdown.js | 1 + src/_data/notes.js | 14 +++++++++++--- src/_includes/note.njk | 18 ++++++++++++++++++ src/index.html | 11 +++++++++++ src/styles/main.css | 39 ++++++++++++++++++++++++++++++++++++-- 7 files changed, 93 insertions(+), 5 deletions(-) create mode 100644 config/filters/notes.js diff --git a/config/filters/index.js b/config/filters/index.js index 501b5ab..2094522 100644 --- a/config/filters/index.js +++ b/config/filters/index.js @@ -1,3 +1,4 @@ module.exports = function(eleventyConfig) { eleventyConfig.addPlugin(require('./dates')); + eleventyConfig.addPlugin(require('./notes')); } \ No newline at end of file diff --git a/config/filters/notes.js b/config/filters/notes.js new file mode 100644 index 0000000..06dc731 --- /dev/null +++ b/config/filters/notes.js @@ -0,0 +1,14 @@ +function conversationLength(note) { + return note.replies.reduce((total, reply) => { + return total + conversationLength(reply); + }, 1); +} + +module.exports = function (eleventyConfig) { + // Filter out notes so that it's only notes that aren't replying to a post + eleventyConfig.addFilter('topLevelNotes', function (notes) { + return notes.filter(note => !note.replyId); + }); + + eleventyConfig.addFilter('conversationLength', conversationLength); +} \ No newline at end of file diff --git a/config/plugins/markdown.js b/config/plugins/markdown.js index 3b68d62..ef69b6d 100644 --- a/config/plugins/markdown.js +++ b/config/plugins/markdown.js @@ -21,4 +21,5 @@ const markdownLib = markdownIt({ module.exports = function (eleventyConfig) { eleventyConfig.setLibrary('md', markdownLib); + eleventyConfig.addFilter('md', content => content ? markdownLib.render(content) : ""); } \ No newline at end of file diff --git a/src/_data/notes.js b/src/_data/notes.js index d127025..f60b137 100644 --- a/src/_data/notes.js +++ b/src/_data/notes.js @@ -10,12 +10,20 @@ const formatMentions = text => { module.exports = function() { const notes = JSON.parse(fs.readFileSync('./src/_data/_notes.json', 'utf-8')) - .filter(note => note.text !== null) + .filter(note => note.text !== null && note.visibility === "public") .map(note => ({ ...note, text: formatMentions(note.text), - createdAt: new Date(note.createdAt) + createdAt: new Date(note.createdAt), + replies: [] })); - + + notes.forEach(note => { + if (note.replyId) { + notes.find(replied => replied.id === note.replyId)?.replies.push(note); + } + }); + + console.log(JSON.stringify(notes.filter(note => note.replies.length && note.replies.find(reply => reply.replies.length)), null, 2)); return notes; } \ No newline at end of file diff --git a/src/_includes/note.njk b/src/_includes/note.njk index 9e0f113..407a7b2 100644 --- a/src/_includes/note.njk +++ b/src/_includes/note.njk @@ -11,5 +11,23 @@ layout: "base.njk" {{ content | safe }} +
{{ note.replies | dump }}
+ + + {# #} \ No newline at end of file diff --git a/src/index.html b/src/index.html index e69de29..2799234 100644 --- a/src/index.html +++ b/src/index.html @@ -0,0 +1,11 @@ +--- +title: Firefish Archive +--- + + \ No newline at end of file diff --git a/src/styles/main.css b/src/styles/main.css index 3affcf2..180eb1d 100644 --- a/src/styles/main.css +++ b/src/styles/main.css @@ -1,6 +1,41 @@ +:root { + --space-size-4xs: clamp(0.125rem, calc(0.12rem + 0.03vw), 0.21rem); + --space-size-3xs: clamp(0.25rem, calc(0.24rem + 0.06vw), 0.31rem); + --space-size-2xs: clamp(0.5rem, calc(0.48rem + 0.13vw), 0.63rem); + --space-size-xs: clamp(0.75rem, calc(0.71rem + 0.19vw), 0.94rem); + --space-size-s: clamp(1rem, calc(0.95rem + 0.25vw), 1.25rem); + --space-size-m: clamp(1.5rem, calc(1.43rem + 0.38vw), 1.88rem); + --space-size-l: clamp(2rem, calc(1.9rem + 0.5vw), 2.5rem); + --space-size-xl: clamp(3rem, calc(2.85rem + 0.75vw), 3.75rem); + --space-size-2xl: clamp(4rem, calc(3.8rem + 1vw), 5rem); + --space-size-3xl: clamp(6rem, calc(5.7rem + 1.5vw), 7.5rem); + --text-size-2xs: clamp(0.56rem, calc(0.72rem + -0.14vw), 0.69rem); + --text-size-xs: clamp(0.83rem, calc(0.83rem + 0vw), 0.83rem); + --text-size-s: clamp(1rem, calc(0.95rem + 0.25vw), 1.25rem); + --text-size-m: clamp(1.2rem, calc(1.07rem + 0.68vw), 1.88rem); + --text-size-l: clamp(1.44rem, calc(1.17rem + 1.37vw), 2.81rem); + --text-size-xl: clamp(1.73rem, calc(1.23rem + 2.49vw), 4.22rem); + --text-size-2xl: clamp(2.07rem, calc(1.22rem + 4.25vw), 6.33rem); + --text-size-3xl: clamp(2.49rem, calc(1.09rem + 7vw), 9.49rem); + --font-family-sans: ui-sans-serif, system-ui, -apple-system, + BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans", + sans-serif, "Apple Color Emoji", "Segoe UI Emoji", "Segoe UI Symbol", + "Noto Color Emoji"; + --font-family-mono: "Space Grotesk", ui-monospace, SFMono-Regular, Menlo, + Monaco, Consolas, "Liberation Mono", "Courier New", monospace; + --screen-sm: 640px; + --screen-md: 768px; + --screen-lg: 1024px; + --screen-xl: 1280px; + --screen-2xl: 1536px; + --screen-3xl: 1920px; +} + body { display: flex; flex-direction: column; + font-family: var(--font-family-sans); + font-size: var(--text-size-s); margin: 0; } @@ -16,8 +51,8 @@ main[data-for="note"] { } article { - max-width: 40rem; - padding: 1rem; + max-width: var(--screen-lg); + padding: var(--space-size-s); border-radius: 5px; box-shadow: 0px 10px 15px -3px rgba(0,0,0,0.1); } \ No newline at end of file