diff --git a/handlers/naddr.ts b/handlers/naddr.ts index b6716c5..cfd3ce7 100644 --- a/handlers/naddr.ts +++ b/handlers/naddr.ts @@ -1,11 +1,8 @@ import { Context } from "@oak/oak"; import { nip19 } from "@nostr/tools"; import { log } from "../log.ts"; -import { articleHtml } from "../html.ts" -import { - fetchReplaceableEvent, - fetchProfileEvent -} from "../nostr.ts"; +import { articleHtml } from "../html.ts"; +import { fetchProfileEvent, fetchReplaceableEvent } from "../nostr.ts"; const naddrHandler = async function (ctx: Context) { const { request } = ctx; @@ -13,7 +10,10 @@ const naddrHandler = async function (ctx: Context) { try { const r = nip19.decode(naddr); - const articleEvent = await fetchReplaceableEvent(r.data.pubkey, r.data.identifier); + const articleEvent = await fetchReplaceableEvent( + r.data.pubkey, + r.data.identifier, + ); const profileEvent = await fetchProfileEvent(r.data.pubkey); let profile; diff --git a/handlers/nprofile.ts b/handlers/nprofile.ts index 33703c2..5a889d9 100644 --- a/handlers/nprofile.ts +++ b/handlers/nprofile.ts @@ -3,7 +3,7 @@ import { nip19 } from "@nostr/tools"; import { log } from "../log.ts"; import { lookupUsernameByPubkey } from "../ldap.ts"; import { fetchProfileEvent } from "../nostr.ts"; -import { profilePageHtml } from "../html.ts" +import { profilePageHtml } from "../html.ts"; const nprofileHandler = async function (ctx: Context) { const { request } = ctx; diff --git a/handlers/npub.ts b/handlers/npub.ts index 19dcd22..9cb32f5 100644 --- a/handlers/npub.ts +++ b/handlers/npub.ts @@ -3,7 +3,7 @@ import { nip19 } from "@nostr/tools"; import { log } from "../log.ts"; import { lookupUsernameByPubkey } from "../ldap.ts"; import { fetchProfileEvent } from "../nostr.ts"; -import { profilePageHtml } from "../html.ts" +import { profilePageHtml } from "../html.ts"; const npubHandler = async function (ctx: Context) { const { request } = ctx; diff --git a/handlers/username.ts b/handlers/username.ts index c2581bb..f4d9f98 100644 --- a/handlers/username.ts +++ b/handlers/username.ts @@ -2,8 +2,8 @@ import { Context } from "@oak/oak"; import { nip19 } from "@nostr/tools"; import { log } from "../log.ts"; import { lookupPubkeyByUsername } from "../ldap.ts"; -import { fetchProfileEvent } from "../nostr.ts"; -import { profilePageHtml } from "../html.ts" +import { fetchArticlesByAuthor, fetchProfileEvent } from "../nostr.ts"; +import { profilePageHtml } from "../html.ts"; const usernameHandler = async function (ctx: Context) { const { request } = ctx; @@ -20,7 +20,8 @@ const usernameHandler = async function (ctx: Context) { const profileEvent = await fetchProfileEvent(pubkey); if (profileEvent) { - const html = profilePageHtml(profileEvent); + const articleEvents = await fetchArticlesByAuthor(pubkey); + const html = profilePageHtml(profileEvent, articleEvents); ctx.response.body = html; } else { diff --git a/html.ts b/html.ts index 05707a2..00165d1 100644 --- a/html.ts +++ b/html.ts @@ -1,4 +1,5 @@ import { render as renderMarkdown } from "@deno/gfm"; +import { nip19 } from "@nostr/tools"; import { log } from "./log.ts"; export function htmlLayout(title: string, body: string) { @@ -47,6 +48,7 @@ export function htmlLayout(title: string, body: string) { h2, h3, h4 { margin-top: 2em; margin-bottom: 2rem; + line-height: 1.6em; } h1, h2, h3, h4 { @@ -110,6 +112,14 @@ export function htmlLayout(title: string, body: string) { p.meta .date { color: #888; } + + .article-list .item { + margin-bottom: 3rem; + } + + .article-list .item h3 { + margin-bottom: 1rem; + }
@@ -120,7 +130,7 @@ export function htmlLayout(title: string, body: string) { } export function articleHtml(articleEvent: object, profile: object) { - const titleTag = articleEvent.tags.find(t => t[0] === "title"); + const titleTag = articleEvent.tags.find((t) => t[0] === "title"); const title = titleTag ? titleTag[1] : "Untitled"; const content = renderMarkdown(articleEvent.content); const date = new Date(articleEvent.created_at * 1000); @@ -149,16 +159,50 @@ export function articleHtml(articleEvent: object, profile: object) { return htmlLayout(title, body); } -export function profilePageHtml(profileEvent: object) { +function articleListItemHtml(articleEvent: object) { + const identifier = articleEvent.tags.find((t) => t[0] === "d")[1]; + const naddr = nip19.naddrEncode({ + identifier: identifier, + pubkey: articleEvent.pubkey, + kind: articleEvent.kind + }); + const titleTag = articleEvent.tags.find((t) => t[0] === "title"); + const title = titleTag ? titleTag[1] : "Untitled"; + const date = new Date(articleEvent.created_at * 1000); + const formattedDate = date.toLocaleDateString("en-US", { + year: "numeric", + month: "long", + day: "numeric", + }); + + return ` +${formattedDate}
+