From 3616eb0d9542985a9ee681cb414e0a690619df10 Mon Sep 17 00:00:00 2001 From: Lewis Dale Date: Sat, 6 Jan 2024 22:11:43 +0000 Subject: [PATCH] Extract hashtags into separate list, some more styling --- config/filters/dates.js | 7 +++++-- src/_data/notes.js | 41 ++++++++++++++++++++++++++++++++--------- src/index.html | 2 +- src/note.md | 2 +- src/styles/main.css | 15 ++++++++++++++- 5 files changed, 53 insertions(+), 14 deletions(-) diff --git a/config/filters/dates.js b/config/filters/dates.js index e540c96..eed362b 100644 --- a/config/filters/dates.js +++ b/config/filters/dates.js @@ -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' })); } \ No newline at end of file diff --git a/src/_data/notes.js b/src/_data/notes.js index f60b137..6c3f9d4 100644 --- a/src/_data/notes.js +++ b/src/_data/notes.js @@ -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 + }; } \ No newline at end of file diff --git a/src/index.html b/src/index.html index 2799234..ef9d444 100644 --- a/src/index.html +++ b/src/index.html @@ -3,7 +3,7 @@ title: Firefish Archive ---