on master help sign in
ecosystem, index: match featured content to posts
commit63bf68957d9f486e4acb098b9dce73a791f99ec3 authorMatilde Park <matilde.park@urbit.org> dateMon 25 Jul 2022, 16:12 (4 years ago) parent23c3a08
2 files changed+67−10
pages/ecosystem/index.js+18−9 pages/index.js+49−1
pages/ecosystem/index.js+18−9
@@ -316,15 +316,6 @@ export async function getStaticProps({}) {
316316 "ecosystem/spotlight",
317317 "date"
318318 )[0];
319− ["featured-1", "featured-2", "featured-3"].forEach((feat) => {
320− if (post?.[feat]) {
321− post[feat].content = JSON.stringify(
322− Markdown.parse({
323− post: { content: post[feat].content },
324− })
325− );
326− }
327− });
328319 const marketplaces = getAllPosts(["title", "image", "slug"], "marketplaces");
329320 const podcasts = getAllPosts(
330321 ["title", "image", "date", "podcast", "slug"],
@@ -355,6 +346,24 @@ export async function getStaticProps({}) {
355346 return nameA < nameB ? -1 : 1;
356347 });
357348
349+ ["featured-1", "featured-2", "featured-3"].forEach((feat) => {
350+ if (post?.[feat]) {
351+ const matchedPost = [
352+ ...applications.map((e) => ({ ...e, type: "Application" })),
353+ ...organizations.map((e) => ({ ...e, type: "Organization" })),
354+ ...podcasts.map((e) => ({ ...e, type: "Podcast" })),
355+ ...marketplaces.map((e) => ({ ...e, type: "Marketplace" })),
356+ ].filter((e) => e.title === post[feat].title)?.[0];
357+ post[feat].image = post[feat].image || matchedPost?.image;
358+ post[feat].type = matchedPost?.type || "Podcast";
359+ post[feat].content = JSON.stringify(
360+ Markdown.parse({
361+ post: { content: post[feat].content },
362+ })
363+ );
364+ }
365+ });
366+
358367 return {
359368 props: { posts, post, applications, marketplaces, podcasts, organizations },
360369 };
pages/index.js+49−1
@@ -17,6 +17,8 @@ import TwoUp from "../components/TwoUp";
1717import { getAllPosts, getAllEvents, generateRealtimeDate } from "../lib/lib";
1818import { eventKeys } from "../lib/constants";
1919import IndexCard from "../components/ecosystem/IndexCard";
20+import fs from "fs";
21+import path from "path";
2022
2123export default function Home({
2224 posts,
@@ -264,20 +266,64 @@ export default function Home({
264266}
265267
266268export async function getStaticProps() {
269+ // Latest blog posts
267270 const posts = getAllPosts(
268271 ["title", "slug", "date", "description", "extra"],
269272 "blog",
270273 "date"
271274 );
272275
276+ // Pull all latest ecosystem information
273277 const ecosystem = getAllPosts(
274278 ["featured-1", "featured-2", "featured-3"],
275279 "ecosystem/spotlight",
276280 "date"
277281 )[0];
278282
279− const events = getAllEvents(eventKeys, "events");
283+ const marketplaces = getAllPosts(["title", "image", "slug"], "marketplaces");
284+ const podcasts = getAllPosts(
285+ ["title", "image", "date", "podcast", "slug"],
286+ "podcasts",
287+ "date"
288+ );
289+ const organizations = getAllPosts(
290+ ["title", "image", "slug"],
291+ "organizations"
292+ );
293+ const applications = fs
294+ .readdirSync(path.join(process.cwd(), "content/applications"), {
295+ withFileTypes: true,
296+ })
297+ .filter((f) => f.isDirectory())
298+ .map((dir) =>
299+ getAllPosts(
300+ ["title", "bgColor", "image", "slug", "description"],
301+ `applications/${dir.name}`
302+ )
303+ .map((e) => ({ ...e, ship: dir.name }))
304+ .flat()
305+ )
306+ .flat()
307+ .sort((a, b) => {
308+ const nameA = a.title.toLowerCase();
309+ const nameB = b.title.toLowerCase();
310+ return nameA < nameB ? -1 : 1;
311+ });
280312
313+ ["featured-1", "featured-2", "featured-3"].forEach((feat) => {
314+ if (ecosystem?.[feat]) {
315+ const matchedPost = [
316+ ...applications.map((e) => ({ ...e, type: "Application" })),
317+ ...organizations.map((e) => ({ ...e, type: "Organization" })),
318+ ...podcasts.map((e) => ({ ...e, type: "Podcast" })),
319+ ...marketplaces.map((e) => ({ ...e, type: "Marketplace" })),
320+ ].filter((e) => e.title === ecosystem[feat].title)?.[0];
321+ ecosystem[feat].image = ecosystem[feat].image || matchedPost?.image;
322+ ecosystem[feat].type = matchedPost?.type || "Podcast";
323+ }
324+ });
325+
326+ // Latest grants
281327 const grants = getAllPosts(["extra", "taxonomies"], "grants", "date");
282328
283329 const grantNumbers = {
@@ -300,6 +346,8 @@ export async function getStaticProps() {
300346 ).length,
301347 };
302348
349+ // Latest events
350+ const events = getAllEvents(eventKeys, "events");
303351 const now = DateTime.now();
304352
305353 const pastEvents = events.filter((event) => {