From 883ff0104e53bf5b8fda39d85662d29bedf0add9 Mon Sep 17 00:00:00 2001 From: Max Litruv Boonzaayer Date: Mon, 2 Dec 2024 12:39:02 +1100 Subject: [PATCH] misc --- index.html | 7 ++-- main.js | 101 +---------------------------------------------------- 2 files changed, 3 insertions(+), 105 deletions(-) diff --git a/index.html b/index.html index ce27036..e8a9d3a 100644 --- a/index.html +++ b/index.html @@ -30,13 +30,14 @@ + Litruv - Dev/Tech Artist
- Avatar + Avatar

Litruv

Dev/Tech Artist @MatesMedia @@ -63,9 +64,5 @@
- - - - diff --git a/main.js b/main.js index 125f02c..2abcb6f 100644 --- a/main.js +++ b/main.js @@ -1,100 +1 @@ -function formatDate(dateString) { - return new Date(dateString).toLocaleDateString('en-US', { - month: 'short', - day: 'numeric', - hour: '2-digit', - minute: '2-digit' - }); -} - -function getRandomRotation() { - return Math.random() * 3 - 1.5 -} - -function createPost(post) { - const article = document.createElement('div'); - article.className = 'post'; - article.style.transform = `rotate(${getRandomRotation()}deg)`; - - const postLink = document.createElement('a'); - postLink.href = post.url; - postLink.target = "_blank"; - postLink.style.textDecoration = "none"; - - const imageHTML = post.embed.length > 0 - ? post.embed.map(img => ` - - ${img.alt || 'Image'} - - `).join('') - : ''; - - const formattedText = post.text.replace(/\n/g, '
'); - - article.innerHTML = ` -
-
- ${post.author} -
-
-
${post.author} (@${post.handle})
-
- ${formatDate(post.createdAt)} -
-
-
-
${formattedText}
- ${imageHTML} -
- - -
- `; - - postLink.href = post.url; - postLink.appendChild(article); - - return postLink; -} - -function filterOriginalPosts(feed) { - return feed.filter((item) => { - const isRepost = item?.reason?.$type === 'app.bsky.feed.defs#reasonRepost'; - const isReply = item?.post?.record?.reply; - return !isRepost && !isReply; - }); -} - -async function fetchPosts() { - try { - const response = await fetch("https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=lit.mates.dev&limit=20&filter=posts_no_replies"); - if (!response.ok) { - throw new Error('Failed to fetch posts'); - } - const data = await response.json(); - const filteredFeed = filterOriginalPosts(data.feed); - const posts = filteredFeed.map(item => ({ - author: item.post.author.displayName, - handle: item.post.author.handle, - avatar: item.post.author.avatar, - createdAt: item.post.record.createdAt, - text: item.post.record.text, - likes: item.post.likeCount || 0, - reposts: item.post.repostCount || 0, - url: `https://bsky.app/profile/${item.post.author.handle}/post/${item.post.uri.split('/').pop()}`, - embed: item.post.embed?.images?.map(img => ({ - url: img.thumb, - alt: img.alt || '' - })) || [] - })); - const postsContainer = document.getElementById('posts'); - postsContainer.innerHTML = ''; - posts.forEach(post => { - postsContainer.appendChild(createPost(post)); - }); - } catch (error) { - console.error('Error fetching posts:', error); - } -} - -fetchPosts(); +function formatDate(t){return new Date(t).toLocaleDateString("en-US",{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"})}function getRandomRotation(){return 3*Math.random()-1.5}function createPost(t){const e=document.createElement("div");e.className="post",e.style.transform=`rotate(${getRandomRotation()}deg)`;const o=document.createElement("a");o.href=t.url,o.target="_blank",o.style.textDecoration="none";const n=t.embed.length>0?t.embed.map((t=>`\n \n ${t.alt||\n \n `)).join(""):"",a=t.text.replace(/\n/g,"
");return e.innerHTML=`\n
\n
\n ${t.author}\n
\n
\n
${t.author} (@${t.handle})
\n
\n ${formatDate(t.createdAt)}\n
\n
\n
\n
${a}
\n ${n}\n
\n \n \n
\n `,o.href=t.url,o.appendChild(e),o}function filterOriginalPosts(t){return t.filter((t=>{const e="app.bsky.feed.defs#reasonRepost"===t?.reason?.$type,o=t?.post?.record?.reply;return!e&&!o}))}async function fetchPosts(){try{const t=await fetch("https://public.api.bsky.app/xrpc/app.bsky.feed.getAuthorFeed?actor=lit.mates.dev&limit=20&filter=posts_no_replies");if(!t.ok)throw new Error("Failed to fetch posts");const e=await t.json(),o=filterOriginalPosts(e.feed).map((t=>({author:t.post.author.displayName,handle:t.post.author.handle,avatar:t.post.author.avatar,createdAt:t.post.record.createdAt,text:t.post.record.text,likes:t.post.likeCount||0,reposts:t.post.repostCount||0,url:`https://bsky.app/profile/${t.post.author.handle}/post/${t.post.uri.split("/").pop()}`,embed:t.post.embed?.images?.map((t=>({url:t.thumb,alt:t.alt||""})))||[]}))),n=document.getElementById("posts");n.innerHTML="",o.forEach((t=>{n.appendChild(createPost(t))}))}catch(t){console.error("Error fetching posts:",t)}}fetchPosts(); \ No newline at end of file