@@ -23,6 +23,7 @@ import ob from "urbit-ob";
2323import { DateTime } from "luxon";
2424import fs from 'fs';
2525import path, { join } from 'path';
26+import { getGrantYear } from "../../lib/lib";
2627
2728export default function Grant({ post, markdown, match, search }) {
2829 const router = useRouter();
@@ -202,12 +203,7 @@ export default function Grant({ post, markdown, match, search }) {
202203
203204export async function getStaticProps({ params }) {
204205 // Gets post in any year folder sharing the slug name in the param
205− const basePath = join(process.cwd(), 'content/grants')
206− const years = fs.readdirSync(basePath, { 'withFileTypes': true }).filter((f) => f.isDirectory());
207− const dir = years.find((year) => {
208− const yearDir = fs.readdirSync(join(basePath, year.name), { 'withFileTypes': true });
209− return yearDir.some((file) => file.name === `${params.slug}.md`)
210− });
206+ const dir = getGrantYear(params.slug);
211207 const post = getPostBySlug(
212208 params.slug,
213209 ["title", "slug", "date", "description", "content", "extra", "taxonomies"],
@@ -236,6 +232,7 @@ export async function getStaticProps({ params }) {
236232}
237233
238234export async function getStaticPaths() {
235+ // Flatten all year subfolders into a flat array of slugs
239236 const basePath = join(process.cwd(), 'content/grants')
240237 const years = fs.readdirSync(basePath, { 'withFileTypes': true });
241238 const posts = years.filter((year) => year.isDirectory()).map((year) => {