2import { join, parse } from "path";
3import matter from "gray-matter";
4import toml from "@iarna/toml";
5import { DateTime } from "luxon";
6import { getPostBySlug, getPostSlugs } from "@urbit/foundation-design-system";
8// NB Gavin: This could be much simpler if we converted everything to a more common standard, like YAML
11 toml: toml.parse.bind(toml),
17const directories = (dir) => {
20 return join(process.cwd(), "content/blog");
22 return join(process.cwd(), "content/events");
24 return join(process.cwd(), "content/docs");
26 return join(process.cwd(), "content/grants");
28 return join(process.cwd(), "content/media");
30 return join(process.cwd(), "content/updates");
32 return join(process.cwd(), "content");
34 return join(process.cwd(), `content/${dir}`);
38export function getAllPosts(fields = [], key, sort = "") {
39 const slugs = getPostSlugs(key);
41 .map((slug) => getPostBySlug(slug, fields, key))
42 // sort posts by date in descending order
43 .sort((post1, post2) => {
44 if (sort === "date") {
45 return DateTime.fromISO(post1.date) > DateTime.fromISO(post2.date)
48 } else if (sort === "weight") {
49 return post1.weight > post2.weight ? -1 : 1;
55export function getAllEvents(fields = [], key) {
56 const slugs = getPostSlugs(key);
58 .map((slug) => getPostBySlug(slug, fields, key))
59 // sort posts by date in descending order
60 .sort((post1, post2) =>
61 DateTime.fromISO(post1.starts) > DateTime.fromISO(post2.starts) ? -1 : 1
66function getAllPaths(dirPath, arrayOfFiles) {
67 let files = fs.readdirSync(dirPath);
69 arrayOfFiles = arrayOfFiles || [];
71 files.forEach(function (file) {
72 if (fs.statSync(dirPath + "/" + file).isDirectory()) {
73 arrayOfFiles = getAllPaths(dirPath + "/" + file, arrayOfFiles);
75 arrayOfFiles.push(join(dirPath, "/", file));
82export function getDocsPaths() {
83 return getAllPaths(directories("docs"), []);
86export function formatDateWithTime(d) {
87 const date = DateTime.fromISO(d, {
89 }).toLocaleString(DateTime.DATETIME_FULL);
93// Formats a DateTime object to something like "July 15, 2021, 5:00 PM"
94export function formatDateAndTime(dateTimeObject) {
95 return dateTimeObject.toLocaleString(DateTime.DATETIME_HUGE);
98// Returns an array of unique grants categories
99export function getGrantsCategories() {
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))
106 .reduce((acc, metadata) => {
107 return [...acc, ...metadata.data.taxonomies.grant_category]
110 return uniqueCategories;
113// Returns an array of unique grants types
115export function getGrantsTypes() {
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))
122 .reduce((acc, metadata) => {
123 return [...acc, ...metadata.data.taxonomies.grant_type]
129// Groups arrays into an array of arrays with 2 members
130export const pair = (arr) =>
131 arr.reduce(function (rows, key, index) {
133 (index % 2 == 0 ? rows.push([key]) : rows[rows.length - 1].push(key)) &&
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list