My personal website!
0
fork

Configure Feed

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

Perchance fixed banners

Koehn c733d264 b5d26a9d

+29 -39
+15 -7
src/routes/post.ts
··· 4 4 import { createBanner, createFooter, createHead } from "../components"; 5 5 import sanitize from "sanitize-html"; 6 6 import * as marked from "marked"; 7 + import { banner, Banner, BannerItem } from "../utils/structs"; 7 8 8 9 export async function handlePost(req: Request, res: Response) { 9 10 const transformedSlug = req.params.slug as string; ··· 26 27 27 28 const markdown = sanitize(`${marked.parse(post.content.markdown)}`); 28 29 29 - const buttons = []; 30 + let buttons: BannerItem[] = []; 31 + const banners: Banner = [{ title: "plain text", link: `${post.path}.txt` }]; 30 32 31 - if (postIndex > 0) { 32 - buttons.push({ title: "prev", link: posts[postIndex - 1].path }); 33 - } 33 + if (posts.length > 1) { 34 + if (postIndex > 0) { 35 + buttons.push({ title: "prev", link: posts[postIndex - 1].path }); 36 + } 34 37 35 - if (posts.length > postIndex + 1) { 36 - buttons.push({ title: "next", link: posts[postIndex + 1].path }); 38 + if (posts.length > postIndex + 1) { 39 + buttons.push({ title: "next", link: posts[postIndex + 1].path }); 40 + } 41 + } else { 42 + buttons = []; 37 43 } 44 + 45 + if (buttons.length > 0) banners.unshift(buttons); 38 46 39 47 const body = ` 40 48 <!DOCTYPE html> ··· 52 60 ${markdown} 53 61 </article> 54 62 ${post.tags ? `<div>${post.tags?.map((t) => `#<a href="/tags/${t}">${t}</a>`).join(", ")}</div>` : ""} 55 - ${createBanner([buttons, { title: "plain text", link: `${post.path}.txt` }])} 63 + ${createBanner(banners)} 56 64 ${createFooter()} 57 65 </html> 58 66 `;
+14 -32
src/utils/structs.ts
··· 47 47 cursor: z.string(), 48 48 }); 49 49 50 - export const banner = z.array( 51 - z.union([ 52 - z 53 - .object({ 54 - link: z.string(), 55 - title: z.string(), 56 - }) 57 - .transform((item) => 58 - item.link === "infer" 59 - ? { 60 - ...item, 61 - link: `/${item.title.toLowerCase().replace(/\s+/g, "-")}`, 62 - } 63 - : item, 64 - ), 65 - z.array( 66 - z 67 - .object({ 68 - link: z.string(), 69 - title: z.string(), 70 - }) 71 - .transform((item) => 72 - item.link === "infer" 73 - ? { 74 - ...item, 75 - link: `/${item.title.toLowerCase().replace(/\s+/g, "-")}`, 76 - } 77 - : item, 78 - ), 79 - ), 80 - ]), 81 - ); 50 + export const bannerItem = z 51 + .object({ link: z.string(), title: z.string() }) 52 + .transform((item) => 53 + item.link === "infer" 54 + ? { 55 + ...item, 56 + link: `/${item.title.toLowerCase().replace(/\s+/g, "-")}`, 57 + } 58 + : item, 59 + ); 60 + 61 + export const banner = z.array(z.union([bannerItem, z.array(bannerItem)])); 82 62 83 63 export type StandardDocument = z.infer<typeof standardDocument>; 64 + export type Banner = z.infer<typeof banner>; 65 + export type BannerItem = z.infer<typeof bannerItem>;