Extract hashtags into separate list, some more styling

This commit is contained in:
Lewis Dale 2024-01-06 22:11:43 +00:00
parent d0542271a0
commit 3616eb0d95
5 changed files with 53 additions and 14 deletions

View File

@ -1,10 +1,13 @@
const locale = 'en-GB'; // change this to your locale if you want a different date/time format
module.exports = function (eleventyConfig) {
eleventyConfig.addFilter('dateDisplay', date => new Date(date).toLocaleDateString('en-GB', {
eleventyConfig.addFilter('dateDisplay', date => new Date(date).toLocaleDateString(locale, {
"dateStyle": "short"
}));
eleventyConfig.addFilter('dateTimeDisplay', date => new Date(date).toLocaleString('en-GB', {
eleventyConfig.addFilter('dateTimeDisplay', date => new Date(date).toLocaleString(locale, {
'dateStyle': 'short',
'timeStyle': 'short',
'hourCycle': 'h12'
}));
}

View File

@ -5,18 +5,39 @@ const formatMentions = text => {
return text.replace(matcher, (match, username, domain) => {
return `[${match}](https://${domain}/@${username})`;
});
}
const extractAndFormatHashtags = note => {
const matcher = /#(\w+)/gm;
const hashtags = new Set();
note.text = note.text.replace(matcher, (match, hashtag) => {
hashtags.add(hashtag);
return `[${match}](/tags/${hashtag})`;
});
return Array.from(hashtags);
}
module.exports = function() {
const hashtags = {};
const notes = JSON.parse(fs.readFileSync('./src/_data/_notes.json', 'utf-8'))
.filter(note => note.text !== null && note.visibility === "public")
.map(note => ({
...note,
text: formatMentions(note.text),
createdAt: new Date(note.createdAt),
replies: []
}));
.map(note => {
extractAndFormatHashtags(note).forEach(hashtag => {
if (!hashtags[hashtag]) {
hashtags[hashtag] = [];
}
hashtags[hashtag].push(note);
});
return {
...note,
text: formatMentions(note.text),
createdAt: new Date(note.createdAt),
replies: []
}
});
notes.forEach(note => {
if (note.replyId) {
@ -24,6 +45,8 @@ module.exports = function() {
}
});
console.log(JSON.stringify(notes.filter(note => note.replies.length && note.replies.find(reply => reply.replies.length)), null, 2));
return notes;
return {
notes,
hashtags
};
}

View File

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

View File

@ -1,7 +1,7 @@
---
layout: "note.njk"
pagination:
data: notes
data: notes.notes
size: 1
alias: note
eleventyComputed:

View File

@ -41,6 +41,7 @@ body {
main {
height: 100%;
padding: var(--space-size-m);
}
main[data-for="note"] {
@ -51,8 +52,20 @@ main[data-for="note"] {
}
article {
max-width: var(--screen-lg);
max-width: 80ch;
padding: var(--space-size-s);
border: 1px solid #e2e8f0;
border-radius: 5px;
box-shadow: 0px 10px 15px -3px rgba(0,0,0,0.1);
}
.p-author {
display: flex;
flex-direction: column;
gap: var(--space-size-3xs);
}
.p-author .p-name {
font-weight: bold;
font-size: var(--text-size-m);
}