✨ Activity feed
This commit is contained in:
		| @@ -1,7 +1,10 @@ | ||||
| <template> | ||||
|   <v-container class="content-container mx-auto"> | ||||
|     <div class="my-3 mx-[3.5ch]"> | ||||
|       <h1 class="text-2xl">{{ t("navActivity") }}</h1> | ||||
|       <div class="flex gap-1"> | ||||
|         <h1 class="text-2xl">{{ t("navActivity") }}</h1> | ||||
|         <v-btn size="x-small" variant="text" icon="mdi-rss" slim to="/activity/feed" /> | ||||
|       </div> | ||||
|       <span>{{ t("navActivityCaption") }}</span> | ||||
|     </div> | ||||
|  | ||||
|   | ||||
							
								
								
									
										79
									
								
								server/routes/activity/feed.ts
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										79
									
								
								server/routes/activity/feed.ts
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,79 @@ | ||||
| import { Feed } from "feed" | ||||
| import { unified } from "unified" | ||||
| import rehypeSanitize from "rehype-sanitize" | ||||
| import rehypeStringify from "rehype-stringify" | ||||
| import remarkParse from "remark-parse" | ||||
| import remarkRehype from "remark-rehype" | ||||
|  | ||||
| export default defineEventHandler(async (event) => { | ||||
|   const config = useRuntimeConfig() | ||||
|  | ||||
|   const feed = new Feed({ | ||||
|     title: "Solar Network", | ||||
|     description: "Content all over solar network", | ||||
|     id: "https://solsynth.dev", | ||||
|     copyright: "All rights reserved © 2024 Solsynth LLC", | ||||
|     generator: "Solar Network Development Activities", | ||||
|     feedLinks: { | ||||
|       atom: "https://solsynth.dev/activity/feed", | ||||
|     }, | ||||
|   }) | ||||
|  | ||||
|   const queries = getQuery<{ | ||||
|     take?: number, | ||||
|     offset?: number, | ||||
|     type?: "atom" | "json" | "rss", | ||||
|     author?: string, | ||||
|   }>(event) | ||||
|  | ||||
|   const searchQuery = new URLSearchParams({ | ||||
|     "take": (queries.take ?? 50).toString(), | ||||
|     "offset": (queries.offset ?? 0).toString(), | ||||
|     "realm": config.public.solarRealm, | ||||
|   }) | ||||
|  | ||||
|   if (queries.author) { | ||||
|     searchQuery.set("author", queries.author) | ||||
|   } | ||||
|  | ||||
|   const res = await fetch(`${config.public.solarNetworkApi}/cgi/co/posts?` + searchQuery) | ||||
|   const posts: any[] = (await res.json())["data"] | ||||
|  | ||||
|   for (const post of posts) { | ||||
|     const content = await unified() | ||||
|       .use(remarkParse) | ||||
|       .use(remarkRehype) | ||||
|       .use(rehypeSanitize) | ||||
|       .use(rehypeStringify) | ||||
|       .process(post.body.content) | ||||
|  | ||||
|     const slug = post.alias ? `/posts/${post.area_alias}/${post.alias}` : `/posts/${post.id}` | ||||
|  | ||||
|     feed.addItem({ | ||||
|       date: new Date(post.published_at), | ||||
|       link: `https://solsynth.dev/${slug}`, | ||||
|       title: post.body.title ?? `Devlog #${post.id}`, | ||||
|       description: post.body.description, | ||||
|       content: String(content), | ||||
|       author: [ | ||||
|         { | ||||
|           name: post.author.nick, | ||||
|           link: `https://solsynth.dev/@${post.author.name}`, | ||||
|         }, | ||||
|       ], | ||||
|       image: post.body.thumbnail ? `${config.public.solarNetworkApi}/cgi/uc/attachments/${post.body.thumbnail}` : void 0, | ||||
|     }) | ||||
|   } | ||||
|  | ||||
|   switch (queries.type) { | ||||
|     case "json": | ||||
|       setResponseHeader(event, "Content-Type", "application/json; charset=utf-8") | ||||
|       return feed.json1() | ||||
|     case "rss": | ||||
|       setResponseHeader(event, "Content-Type", "application/rss+xml; charset=utf-8") | ||||
|       return feed.rss2() | ||||
|     default: | ||||
|       setResponseHeader(event, "Content-Type", "application/rss+xml; charset=utf-8") | ||||
|       return feed.atom1() | ||||
|   } | ||||
| }) | ||||
		Reference in New Issue
	
	Block a user