mirror of github:amycatgirl/amycatgirl.github.io
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

chore: support multiple nsids temporarily as leaflet migrates

Amy d734a130 e0a42053

+57 -23
+28 -6
index.html
··· 38 38 <div id="atproto-leaflet"> 39 39 <noscript> 40 40 <div class="entry"> 41 + <a class="base-anchor" href="https://amybunny.leaflet.pub/3md2f4slp5c23"><h3 class="title">TIL: Finesse faults</h3></a> 42 + <p class="description">nil</p> 43 + <div class="metadata"> 44 + <time datetime="2026-01-22T23:55:10.383Z" class="published-at">22/01/2026, 19:55</time> 45 + </div> 46 + </div> 47 + <div class="entry"> 41 48 <a class="base-anchor" href="https://amybunny.leaflet.pub/3mbqvkp6l6c27"><h3 class="title">my 2026 bucket list</h3></a> 42 49 <p class="description">things that i want to do this year</p> 43 50 <div class="metadata"> ··· 130 137 131 138 padding: 5px 10px; 132 139 border: 1px solid black; 140 + &:not(:first-child) { margin-top: .5rem; } 133 141 134 142 & .base-anchor { 135 143 position: static; ··· 200 208 } 201 209 202 210 // Configuration options 203 - const COLLECTION_NSID = "pub.leaflet.document"; 211 + const COLLECTION_NSIDS = ["pub.leaflet.document", "site.standard.document"]; 204 212 const USER_DID = "did:plc:gijpvbkdbr56kazbdjhfvb3d"; 205 213 const USER_PDS = "https://porcini.us-east.host.bsky.network"; 206 214 const MAX_LATEST_POSTS = 5; ··· 231 239 } 232 240 233 241 /** 242 + * @param {string} nsid 234 243 * @returns {Promise<object>} 235 244 */ 236 - async function getLatestPosts() { 237 - const { records } = await (await fetch(`${USER_PDS}/xrpc/com.atproto.repo.listRecords?repo=${USER_DID}&collection=${COLLECTION_NSID}&limit=${MAX_LATEST_POSTS}`)).json() 245 + async function getLatestPosts(nsid) { 246 + const { records } = await (await fetch(`${USER_PDS}/xrpc/com.atproto.repo.listRecords?repo=${USER_DID}&collection=${nsid}&limit=${MAX_LATEST_POSTS}`)).json() 238 247 239 - return records 248 + return records.toReversed() 240 249 } 241 250 242 251 // HTML 243 252 const leaflet_container = document.getElementById("atproto-leaflet"); 244 253 245 - const posts = await getLatestPosts() 254 + const posts = (await Promise.all(COLLECTION_NSIDS.map(async (nsid) => await getLatestPosts(nsid)))) 255 + .flat(1) 256 + .sort((entry_a, entry_b) => { 257 + const date_a = new Date(entry_a.value.publishedAt) 258 + const date_b = new Date(entry_b.value.publishedAt) 259 + 260 + console.log(date_a) 261 + console.log(date_b) 262 + 263 + return date_b - date_a 264 + }); 265 + 246 266 for (const document of posts) { 247 267 const { title, description, publication, publishedAt } = document.value; 248 - 268 + 269 + // TODO: make platform agnostic 249 270 leaflet_container.append(buildEntry({ 250 271 title: document.value.title, 251 272 description: document.value.description, ··· 253 274 date: new Date(publishedAt) 254 275 })) 255 276 } 277 + 256 278 </script> 257 279 </body> 258 280
+29 -17
leaflet-fallback.el
··· 1 1 ;; -*- lexical-binding: t; -*- 2 - (defconst atproto-collection-nsid "pub.leaflet.document") 2 + (defconst atproto-collection-nsids '("pub.leaflet.document" "site.standard.document")) 3 3 (defconst atproto-user-did "did:plc:gijpvbkdbr56kazbdjhfvb3d") 4 4 (defconst atproto-pds "https://porcini.us-east.host.bsky.network") 5 5 (defconst max-entries 5) ··· 13 13 (defun build-leaflet-html-entry (title description date date-humanreadable url) 14 14 (format "<div class=\"entry\">\n<a class=\"base-anchor\" href=\"https://amybunny.leaflet.pub/%s\"><h3 class=\"title\">%s</h3></a>\n<p class=\"description\">%s</p>\n<div class=\"metadata\">\n<time datetime=%S class=\"published-at\">%s</time>\n</div>\n</div>" url title description date date-humanreadable)) 15 15 16 - (defun fetch-latest-entries () 16 + (defun fetch-latest-entries (nsid) 17 17 (let ((url-request-method "GET") 18 - (endpoint (concat atproto-pds "/xrpc/com.atproto.repo.listRecords?repo=" atproto-user-did "&collection=" atproto-collection-nsid "&limit=" (number-to-string max-entries)))) 18 + (endpoint (concat atproto-pds "/xrpc/com.atproto.repo.listRecords?repo=" atproto-user-did "&collection=" nsid "&limit=" (number-to-string max-entries)))) 19 19 (with-current-buffer (url-retrieve-synchronously endpoint) 20 20 (goto-char 0) 21 - (search-forward "\n\n") 22 - (gethash "records" (json-parse-string (buffer-substring (point) (point-max))))))) 21 + (search-forward "\n\n") 22 + (gethash "records" (json-parse-string (buffer-substring (point) (point-max))))))) 23 23 24 24 (defun build-elements-from-entries (seq) 25 25 (mapcar (lambda (rec) ··· 33 33 url))) 34 34 seq)) 35 35 36 - (with-current-buffer "index.html" 37 - (save-excursion 38 - (goto-char 0) 39 - (let ((block-start (search-forward "<noscript>" nil t)) 40 - (block-end (- (search-forward "</noscript>" nil t) 11))) 41 - (delete-region block-start block-end) 42 - (goto-char (- (point) 11)) 43 - (insert "\n") 44 - (dolist (element (build-elements-from-entries (fetch-latest-entries))) 45 - (insert (concat element "\n"))) 46 - (indent-region block-start (search-forward "</noscript>" nil t)))) 47 - (save-buffer)) 36 + (defun sort-entries-by-date (entries) 37 + (sort entries 38 + :key (lambda (e) 39 + (let* ((doc-value (gethash "value" e)) 40 + (datetime (gethash "publishedAt" doc-value))) 41 + (at-datetime->timestamp datetime))) 42 + :lessp #'time-less-p 43 + :reverse t)) 44 + 45 + (let ((entries (sort-entries-by-date (flatten-list (mapcar (lambda (nsid) 46 + (append (fetch-latest-entries nsid) nil)) 47 + atproto-collection-nsids))))) 48 + (with-current-buffer "index.html" 49 + (save-excursion 50 + (goto-char 0) 51 + (let ((block-start (search-forward "<noscript>" nil t)) 52 + (block-end (- (search-forward "</noscript>" nil t) 11))) 53 + (delete-region block-start block-end) 54 + (goto-char (- (point) 11)) 55 + (insert "\n") 56 + (dolist (element (build-elements-from-entries entries)) 57 + (insert (concat element "\n"))) 58 + (indent-region block-start (search-forward "</noscript>" nil t)))) 59 + (save-buffer))) 48 60