@@ -14,6 +14,8 @@ const directories = {
1414 blog: join(process.cwd(), "content/blog"),
1515 events: join(process.cwd(), "content/events"),
1616 docs: join(process.cwd(), "content/docs"),
17+ grants: join(process.cwd(), "content/grants"),
18+ media: join(process.cwd(), "content/media"),
1719};
1820
1921export function getPostSlugs(key) {
@@ -195,3 +197,80 @@ export const getPage = (path) => {
195197 }
196198 }
197199};
200+
201+// Returns an array of unique grants categories
202+export function getGrantsCategories() {
203+ const paths = fs.readdirSync(directories.grants);
204+ const uniqueCategories = paths
205+ // Get only markdown files
206+ .filter((path) => parse(path).ext === ".md")
207+ // Parse frontmatter
208+ .map((path) =>
209+ matter(fs.readFileSync(join(directories.grants, path)), options)
210+ )
211+ // Each markdown file has an array of categories. Collapse these arrays into one array.
212+ .reduce((acc, metadata) => {
213+ return [...acc, ...metadata.data.taxonomies.grant_category];
214+ }, [])
215+ // Deduplicate single array of categories such that the output is an array where each category is represented only once.
216+ .reduce((acc, uniqueItem) => {
217+ if (acc.includes(uniqueItem)) {
218+ return acc;
219+ }
220+ return [...acc, uniqueItem];
221+ }, []);
222+ return uniqueCategories;
223+}
224+
225+// Returns an array of unique grants types
226+export function getGrantsTypes() {
227+ const paths = fs.readdirSync(directories.grants);
228+ const uniqueTypes = paths
229+ // Get only markdown files
230+ .filter((path) => parse(path).ext === ".md")
231+ // Parse frontmatter
232+ .map((path) =>
233+ matter(fs.readFileSync(join(directories.grants, path)), options)
234+ )
235+ // Each markdown file has an array of categories. Collapse these arrays into one array.
236+ .reduce((acc, metadata) => {
237+ return [...acc, ...metadata.data.taxonomies.grant_type];
238+ }, [])
239+ // Deduplicate single array of categories such that the output is an array where each category is represented only once.
240+ .reduce((acc, uniqueItem) => {
241+ if (acc.includes(uniqueItem)) {
242+ return acc;
243+ }
244+ return [...acc, uniqueItem];
245+ }, []);
246+ return uniqueTypes;
247+}
248+
249+export function getOpenGrantsCount() {
250+ const paths = fs.readdirSync(directories.grants);
251+ const count = paths
252+ // Get only markdown files
253+ .filter((path) => parse(path).ext === ".md")
254+ // Parse frontmatter
255+ .map((path) =>
256+ matter(fs.readFileSync(join(directories.grants, path)), options)
257+ )
258+ // Count non-completed grants
259+ .reduce((acc, metadata) => {
260+ if (metadata.data.extra.completed) {
261+ return acc;
262+ }
263+ return acc + 1;
264+ }, 0);
265+ return count;
266+}
267+
268+/*
269+ * types = an array of strings
270+ */
271+export function getGrantsByCategories(types) {}
272+
273+/*
274+ * types = an array of strings
275+ */
276+export function getGrantsByTypes(types) {}