Something went wrong. Try again.
🌿 Collaborative wiki on ATProto forked from juprodh.me/lichen.wiki
Something went wrong. Try again.
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172import type { WikiRequestContext } from "../../lib/access.ts";import { KATEX_STYLESHEETS, VIZ_SCRIPTS } from "../../lib/assets.ts";import { t } from "../../lib/i18n/index.ts";import { renderMarkdown } from "../../lib/markdown.ts";import { htmlResponse } from "../../lib/response.ts";import { noteUrl, resolvePublicUrl } from "../../lib/urls.ts";import { resolveBookmarkHtml } from "../../views/bookmark.ts";import { notePage } from "../../views/note.ts";import { shareMenu } from "../../views/share.ts";import { atCanonicalOption, wikiIdentity, wikiLayoutOptions,} from "../../views/view-options.ts";
interface NoteRenderInput { ctx: WikiRequestContext; request: Request; noteSlug: string; noteTitle: string; content: string; sidebarNotes: { slug: string; title: string }[]; ogTitle?: string; // The record this URL is the page for — the note, or the wiki on its home page. canonicalRecord: { at_uri: string; did: string };}
export function renderNoteResponse(input: NoteRenderInput): Response { const { ctx, request, noteSlug, noteTitle, content, sidebarNotes } = input; const handle = ctx.ownerHandle; const { html, hasViz, hasMath } = renderMarkdown( content, ctx.wiki.slug, handle, ); const msg = t(ctx.locale); const bmHtml = resolveBookmarkHtml(ctx.did, ctx.wiki.at_uri, msg); const publicUrl = resolvePublicUrl(request); const canonicalUrl = `${publicUrl}${noteUrl(handle, ctx.wiki.slug, noteSlug)}`; const shareHtml = shareMenu(noteTitle, canonicalUrl, msg); const ogImage = `${publicUrl}/og/@${handle}/${ctx.wiki.slug}`; const ogDescription = ctx.wiki.description ? { ogDescription: ctx.wiki.description } : {}; const cacheable = !ctx.session && ctx.wiki.visibility === "public" ? 60 : 0;
return htmlResponse( notePage( wikiIdentity(ctx), noteTitle, html, { ...wikiLayoutOptions(ctx), ...(hasViz && { scripts: VIZ_SCRIPTS }), ...(hasMath && { stylesheets: KATEX_STYLESHEETS }), sidebarNotes, sidebarMarkdown: ctx.wiki.sidebar, currentNoteSlug: noteSlug, bookmarkHtml: bmHtml, shareHtml, ogTitle: input.ogTitle ?? `${noteTitle} - ${ctx.wiki.name}`, ogUrl: canonicalUrl, ogImage, ...ogDescription, ...atCanonicalOption(ctx.wiki, input.canonicalRecord), }, ctx.wiki.language, ), { edgeCacheSeconds: cacheable }, );}