on master help sign in
pages: ecosystem per-slug page
commitcdaf6310df7a2dc8d6fdac78815bdb0a269fb5ca authorMatilde Park <matilde.park@urbit.org> dateTue 19 Jul 2022, 18:25 (4 years ago) parent75ef508
1 file changed+77
pages/ecosystem/spotlight/[slug].js+77
pages/ecosystem/spotlight/[slug].jsnew file+77
@@ -0,0 +1,77 @@
1+import { useRouter } from "next/router";
2+import Head from "next/head";
3+import Meta from "../../../components/Meta";
4+import ErrorPage from "../../../pages/404";
5+import {
6+ Container,
7+ SingleColumn,
8+ Section,
9+ Markdown,
10+ IntraNav,
11+} from "foundation-design-system";
12+import Header from "../../../components/Header";
13+import Footer from "../../../components/Footer";
14+import Post from "../../../components/ecosystem/Post";
15+import { getAllPosts, getPostBySlug } from "../../../lib/lib";
16+
17+export default function BasicPage({ post, markdown, search, index = false }) {
18+ const router = useRouter();
19+ if (!router.isFallback && !post?.slug) {
20+ return <ErrorPage />;
21+ }
22+ return (
23+ <Container>
24+ <Head>
25+ <title>Urbit • {post.title}</title>
26+ {Meta(post)}
27+ </Head>
28+ <IntraNav ourSite="https://urbit.org" search={search} />
29+ <SingleColumn>
30+ <Header />
31+ <Section narrow>
32+ <h1>Ecosystem Spotlight - {post.title}</h1>
33+ </Section>
34+ <Section narrow>
35+ <Post post={post} />
36+ </Section>
37+ </SingleColumn>
38+ <Footer />
39+ </Container>
40+ );
41+}
42+
43+export async function getStaticProps({ params }) {
44+ const post = getPostBySlug(
45+ params.slug,
46+ ["title", "slug", "date", "featured-1", "featured-2", "featured-3"],
47+ "ecosystem/spotlight"
48+ );
49+ ["featured-1", "featured-2", "featured-3"].forEach((feat) => {
50+ if (post?.[feat]) {
51+ post[feat].content = JSON.stringify(
52+ Markdown.parse({
53+ post: { content: post[feat].content },
54+ })
55+ );
56+ }
57+ });
58+
59+ return {
60+ props: { post },
61+ };
62+}
63+
64+export async function getStaticPaths() {
65+ const posts = getAllPosts(["slug", "date"], "ecosystem/spotlight", "date");
66+
67+ return {
68+ paths: posts.map((post) => {
69+ return {
70+ params: {
71+ slug: post.slug,
72+ },
73+ };
74+ }),
75+ fallback: false,
76+ };
77+}