import { localizeDate } from "./dates.ts"; import Article from "./models/article.ts"; import Profile from "./models/profile.ts"; function htmlLayout(title: string, body: string, profile?: Profile): string { let feedLinksHtml = ""; if (profile) { feedLinksHtml = ``; } return ` ${title} ${feedLinksHtml} ${body} `; } export function errorPageHtml(statusCode: number, title: string): string { const body = `

${statusCode} - ${title}

`; return htmlLayout(title, body); } export function articleHtml(article: Article, profile: Profile): string { const publishedAtFormatted = localizeDate(article.publishedAt); const pageTitle = article.isDraft ? `Draft: ${article.title}` : article.title; let draftLabel = ``; if (article.isDraft) { draftLabel = `

Draft version

`; } const body = `
${draftLabel}

${article.title}

User Avatar
${profile.name} ${publishedAtFormatted}
${article.html}
`; return htmlLayout(pageTitle, body, profile); } function articleListItemHtml(article: Article): string { const formattedDate = localizeDate(article.publishedAt); return `

${article.title}

${formattedDate}

`; } export function articleListHtml(articles: Article[]): string { if (articles.length === 0) return ""; const sortedArticles = articles.sort((a, b) => b.publishedAt - a.publishedAt); let html = ""; for (const article of sortedArticles) { html += articleListItemHtml(article); } return `

Articles

${html}
`; } export function profilePageHtml(profile: Profile, articles: Article[]): string { const title = `${profile.name} on Nostr`; const body = `
User Avatar

${profile.name}

${profile.about}

Public key
${profile.npub}
${articleListHtml(articles)}
`; return htmlLayout(title, body, profile); } function openWithNostrAppHtml(bech32Id): string { let appLinksHtml = ""; const appLinks = [ { title: "Habla", href: `https://habla.news/a/${bech32Id}` }, { title: "noStrudel", href: `https://nostrudel.ninja/#/articles/${bech32Id}`, }, { title: "Coracle", href: `https://coracle.social/${bech32Id}` }, ]; for (const link of appLinks) { appLinksHtml += `${link.title}`; } return ` `; }