Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 23 additions & 3 deletions scripts/dao-proposals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import fs from 'fs/promises'
import path from 'path'
import { SidebarItem } from 'vocs'

import { getFirstHeadingToken } from './utils'

// Generate a JSON file for each DAO proposal to be used in the sidebar
export async function daoProposalsSidebar() {
const sidebar = new Array<SidebarItem>()
Expand All @@ -14,6 +16,7 @@ export async function daoProposalsSidebar() {
filename: string
term: number
proposal: number
title: string
}>()

for (const file of files) {
Expand All @@ -26,8 +29,25 @@ export async function daoProposalsSidebar() {
const term = Number(filenameParts[0])
const proposal = Number(filenameParts.slice(1).join('.'))

// Extract markdown title from the file
const markdown = await fs.readFile(
path.join(__dirname, '..', 'src/pages/dao/proposals', file),
'utf8'
)
const title = getFirstHeadingToken(markdown)?.text

// Sanity check. This should never happen
if (!title) {
throw new Error(`No title found for ${file}`)
}

terms.add(term)
parsedFiles.push({ filename: filenameWithoutExtension, term, proposal })
parsedFiles.push({
filename: filenameWithoutExtension,
term,
proposal,
title,
})
}

const reversedTerms = Array.from(terms).reverse()
Expand All @@ -37,8 +57,8 @@ export async function daoProposalsSidebar() {
items: parsedFiles
.filter(({ term: t }) => t === term)
.sort((a, b) => b.proposal - a.proposal)
.map(({ filename }) => ({
text: `EP ${filename}`,
.map(({ filename, title }) => ({
text: title,
link: `/dao/proposals/${filename}`,
})),
})
Expand Down
10 changes: 2 additions & 8 deletions scripts/ensips.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from 'fs/promises'
import matter from 'gray-matter'
import { Tokens, marked } from 'marked'
import path from 'path'
import { SidebarItem } from 'vocs'

import { getFirstHeadingToken } from './utils'

type DirectoryContents = {
name: string
download_url: string
Expand Down Expand Up @@ -105,13 +106,6 @@ export async function ensips() {
}
}

function getFirstHeadingToken(description: string) {
const tokens = marked.lexer(description)
return tokens.find(
(token) => token.type === 'heading' && token.depth === 1
) as Tokens.Heading | undefined
}

function parseDate(date: Date | string) {
return new Intl.DateTimeFormat('en-US', {
year: 'numeric',
Expand Down
8 changes: 8 additions & 0 deletions scripts/utils.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Tokens, marked } from 'marked'

export function getFirstHeadingToken(description: string) {
const tokens = marked.lexer(description)
return tokens.find(
(token) => token.type === 'heading' && token.depth === 1
) as Tokens.Heading | undefined
}