From b710163eabf5d6768091eb44109b1fe07afc71e4 Mon Sep 17 00:00:00 2001 From: Greg Skriloff <35093316+gskril@users.noreply.github.com> Date: Tue, 17 Jun 2025 14:34:52 -0400 Subject: [PATCH] Show DAO proposal titles in sidebar --- scripts/dao-proposals.ts | 26 +++++++++++++++++++++++--- scripts/ensips.ts | 10 ++-------- scripts/utils.ts | 8 ++++++++ 3 files changed, 33 insertions(+), 11 deletions(-) create mode 100644 scripts/utils.ts diff --git a/scripts/dao-proposals.ts b/scripts/dao-proposals.ts index 45cc2f8e..e29b4f53 100644 --- a/scripts/dao-proposals.ts +++ b/scripts/dao-proposals.ts @@ -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() @@ -14,6 +16,7 @@ export async function daoProposalsSidebar() { filename: string term: number proposal: number + title: string }>() for (const file of files) { @@ -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() @@ -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}`, })), }) diff --git a/scripts/ensips.ts b/scripts/ensips.ts index 161098a6..fa161d7e 100644 --- a/scripts/ensips.ts +++ b/scripts/ensips.ts @@ -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 @@ -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', diff --git a/scripts/utils.ts b/scripts/utils.ts new file mode 100644 index 00000000..81291512 --- /dev/null +++ b/scripts/utils.ts @@ -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 +}