More work on the archive. Start rendering conversations

This commit is contained in:
Lewis Dale 2024-01-05 13:36:37 +00:00
parent 493d1932f8
commit db54ca40c6
7 changed files with 93 additions and 5 deletions

View File

@ -1,3 +1,4 @@
module.exports = function(eleventyConfig) { module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(require('./dates')); eleventyConfig.addPlugin(require('./dates'));
eleventyConfig.addPlugin(require('./notes'));
} }

14
config/filters/notes.js Normal file
View File

@ -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);
}

View File

@ -21,4 +21,5 @@ const markdownLib = markdownIt({
module.exports = function (eleventyConfig) { module.exports = function (eleventyConfig) {
eleventyConfig.setLibrary('md', markdownLib); eleventyConfig.setLibrary('md', markdownLib);
eleventyConfig.addFilter('md', content => content ? markdownLib.render(content) : "");
} }

View File

@ -10,12 +10,20 @@ const formatMentions = text => {
module.exports = function() { module.exports = function() {
const notes = JSON.parse(fs.readFileSync('./src/_data/_notes.json', 'utf-8')) 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 => ({ .map(note => ({
...note, ...note,
text: formatMentions(note.text), 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; return notes;
} }

View File

@ -11,5 +11,23 @@ layout: "base.njk"
<time class="dt-published" datetime="{{ note.createdAt | dateToRfc3339 }}">{{ note.createdAt | dateTimeDisplay }}</time> <time class="dt-published" datetime="{{ note.createdAt | dateToRfc3339 }}">{{ note.createdAt | dateTimeDisplay }}</time>
</div> </div>
{{ content | safe }} {{ content | safe }}
<pre>{{ note.replies | dump }}</pre>
<ul>
{% for reply in note.replies %}
<li>{{ reply.text | md | safe }}</li>
{% endfor %}
</ul>
{# <ul>
{% for reply in note.replies %}
<li>
<div>
<time class="dt-published" datetime="{{ reply.createdAt | dateToRfc3339 }}">{{ reply.createdAt | dateTimeDisplay }}</time>
{{ reply.text | md | safe }}
</div>
</li>
{% endfor %}
</ul> #}
</article> </article>
</main> </main>

View File

@ -0,0 +1,11 @@
---
title: Firefish Archive
---
<ul>
{% for note in notes | topLevelNotes %}
<li>
<a href="/notes/{{ note.id }}">{{ note.id }} ({{ note | conversationLength }} replies)</a>
</li>
{% endfor %}
</ul>

View File

@ -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 { body {
display: flex; display: flex;
flex-direction: column; flex-direction: column;
font-family: var(--font-family-sans);
font-size: var(--text-size-s);
margin: 0; margin: 0;
} }
@ -16,8 +51,8 @@ main[data-for="note"] {
} }
article { article {
max-width: 40rem; max-width: var(--screen-lg);
padding: 1rem; padding: var(--space-size-s);
border-radius: 5px; border-radius: 5px;
box-shadow: 0px 10px 15px -3px rgba(0,0,0,0.1); box-shadow: 0px 10px 15px -3px rgba(0,0,0,0.1);
} }