diff --git a/docs/src/pages/blog/index.astro b/docs/src/pages/blog/index.astro new file mode 100644 index 0000000..eaf236e --- /dev/null +++ b/docs/src/pages/blog/index.astro @@ -0,0 +1,207 @@ +--- +import Base from "@/layouts/Base.astro"; +import CallToAction from "@/partials/CallToAction.astro"; +import config from "@/config/config.json"; +import { dateFormat } from "@/lib/utils/dateFormat"; + +interface WordPressPost { + slug: string; + title: { rendered: string }; + modified: string; + excerpt?: { rendered?: string }; + yoast_head_json?: { + og_description?: string; + description?: string; + }; +} + +const blogBaseUrl = config.blog.base_url; +const { + site: { base_url }, +} = config; + +let posts: WordPressPost[] = []; + +try { + const res = await fetch( + `${blogBaseUrl}/wp-json/wp/v2/posts?_embed&per_page=100`, + ); + posts = (await res.json()) as WordPressPost[]; +} catch (e) { + throw new Error( + `Failed to fetch blog posts from "${blogBaseUrl}/wp-json/wp/v2/posts": ${e instanceof Error ? e.message : String(e)}`, + ); +} + +const items = posts + .map((post) => { + const yoast = post.yoast_head_json || {}; + const rawDescription = + yoast.og_description || yoast.description || post.excerpt?.rendered || ""; + const description = rawDescription.replace(/<[^>]+>/g, "").trim(); + + return { + slug: post.slug, + title: post.title.rendered, + modified: post.modified, + description, + }; + }) + .sort( + (a, b) => new Date(b.modified).getTime() - new Date(a.modified).getTime(), + ); + +const [featured, ...rest] = items; + +const seo = { + title: "Blog - RocketSim", + description: + "Tips, guides, and deep dives for iOS developers who want to move faster.", + canonical: `${base_url}/blog/`, +}; + +const structuredData = { + type: "static" as const, +}; +--- + + + + + + + Developer Resources + + + The RocketSim Blog + + + Tips, guides, and deep dives for iOS developers who want to move + faster. + + + + + + + + + { + featured && ( + + + + + + + Latest + + + Featured + + + + + + {featured.description && ( + + {featured.description} + + )} + + + + Last updated {dateFormat(featured.modified, "MMM dd, yyyy")} + + + + + + + + + + + ) + } + + { + rest.length > 0 && ( + + {rest.map((post, index) => ( + + + + + {dateFormat(post.modified, "MMM dd, yyyy")} + + + + + {post.description && ( + + {post.description} + + )} + + ))} + + ) + } + + + + + + + +
+ Tips, guides, and deep dives for iOS developers who want to move + faster. +
+ {featured.description} +
+ {post.description} +