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 {
return `
${title}
${body}
`;
}
export function articleHtml(article: Article, profile: Profile): string {
const publishedAtFormatted = localizeDate(article.publishedAt);
const body = `
${article.html}
${openWithNostrAppHtml(article.naddr)}
`;
return htmlLayout(article.title, body, profile);
}
function articleListItemHtml(article: Article): string {
const formattedDate = localizeDate(article.publishedAt);
return `
`;
}
export function articleListHtml(articles: Article[]): string {
if (articles.length === 0) return "";
let html = "";
for (const article of articles) {
html += articleListItemHtml(article);
}
return `
Articles
${html}
`;
}
export function profilePageHtml(profile: Profile, articles: Article[]): string {
const title = `${profile.name} on Nostr`;
const body = `
${profile.name}
${profile.about}
${articleListHtml(articles)}
`;
return htmlLayout(title, body, profile);
}
function openWithNostrAppHtml(bech32Id): string {
let linksHtml = "";
const links = [
{ title: "Nostr Link", href: `nostr:${bech32Id}` },
{ 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 links) {
linksHtml += `${link.title} `;
}
return `
Open with Nostr app
${linksHtml}
`;
}