@@ -97,76 +97,35 @@ export function formatDateAndTime(dateTimeObject) {
9797
9898// Returns an array of unique grants categories
9999export function getGrantsCategories() {
100− const paths = fs.readdirSync(directories("grants"));
101− const uniqueCategories = paths
102− // Get only markdown files
103− .filter((path) => parse(path).ext === ".md")
104− // Parse frontmatter
105− .map((path) =>
106− matter(fs.readFileSync(join(directories("grants"), path)), options)
107− )
108− // Each markdown file has an array of categories. Collapse these arrays into one array.
109− .reduce((acc, metadata) => {
110− return [...acc, ...metadata.data.taxonomies.grant_category];
111− }, [])
112− // Deduplicate single array of categories such that the output is an array where each category is represented only once.
113− .reduce((acc, uniqueItem) => {
114− if (acc.includes(uniqueItem)) {
115− return acc;
116− }
117− return [...acc, uniqueItem];
118− }, []);
100+ const years = fs.readdirSync(directories("grants"), { withFileTypes: true }).filter((f) => f.isDirectory());
101+ const uniqueCategories = Array.from(new Set(years.map((yearDir) => {
102+ return fs.readdirSync(join(directories("grants"), yearDir.name), { withFileTypes: true })
103+ .filter((path) => parse(path.name).ext === ".md")
104+ .map((path) => matter(fs.readFileSync(join(directories("grants"), yearDir.name, path.name)), options))
105+ .flat()
106+ .reduce((acc, metadata) => {
107+ return [...acc, ...metadata.data.taxonomies.grant_category]
108+ }, [])
109+ }).flat()));
119110 return uniqueCategories;
120111}
121112
122113// Returns an array of unique grants types
114+
123115export function getGrantsTypes() {
124− const paths = fs.readdirSync(directories("grants"));
125− const uniqueTypes = paths
126− // Get only markdown files
127− .filter((path) => parse(path).ext === ".md")
128− // Parse frontmatter to JSON
129− .map((path) =>
130− matter(fs.readFileSync(join(directories("grants"), path)), options)
131− )
132− // Each markdown file has an array of types. Collapse these arrays into one array.
133− .reduce((acc, metadata) => {
134− return [...acc, ...metadata.data.taxonomies.grant_type];
135− }, [])
136− // Deduplicate single array of types such that the output is an array where each type is represented only once.
137− .reduce((acc, uniqueItem) => {
138− if (acc.includes(uniqueItem)) {
139− return acc;
140− }
141− return [...acc, uniqueItem];
142− }, []);
116+ const years = fs.readdirSync(directories("grants"), { withFileTypes: true }).filter((f) => f.isDirectory());
117+ const uniqueTypes = Array.from(new Set(years.map((yearDir) => {
118+ return fs.readdirSync(join(directories("grants"), yearDir.name), { withFileTypes: true })
119+ .filter((path) => parse(path.name).ext === ".md")
120+ .map((path) => matter(fs.readFileSync(join(directories("grants"), yearDir.name, path.name)), options))
121+ .flat()
122+ .reduce((acc, metadata) => {
123+ return [...acc, ...metadata.data.taxonomies.grant_type]
124+ }, [])
125+ }).flat()));
143126 return uniqueTypes;
144127}
145128
146−// Returns a number which represents how many grants are open, or uncompleted
147−export function getOpenGrantsCount() {
148− const paths = fs.readdirSync(directories("grants"));
149− const count = paths
150− // Get only markdown files
151− .filter((path) => parse(path).ext === ".md")
152− // Parse frontmatter to JSON
153− .map((path) =>
154− matter(fs.readFileSync(join(directories("grants"), path)), options)
155− )
156− // Count grants which are both uncompleted and not assigned
157− .reduce((acc, metadata) => {
158− if (
159− !metadata.data.extra.completed &&
160− !metadata.data.extra.canceled &&
161− metadata.data.extra.assignee?.[0] === ""
162− ) {
163− return acc + 1;
164− }
165− return acc;
166− }, 0);
167− return count;
168−}
169−
170129// Groups arrays into an array of arrays with 2 members
171130export const pair = (arr) =>
172131 arr.reduce(function (rows, key, index) {