Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion worker/handlers/handleRead.ts
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ export async function handleGet(request: Request, env: Env, ctx: ExecutionContex

// handle article (render as markdown)
if (role === "a") {
return new Response(shouldGetPasteContent ? makeMarkdown(await decodeMaybeStream(item.paste)) : null, {
return new Response(shouldGetPasteContent ? makeMarkdown(await decodeMaybeStream(item.paste), url.href) : null, {
headers: {
"Content-Type": `text/html;charset=UTF-8`,
...pasteCacheHeader(env),
Expand Down
5 changes: 4 additions & 1 deletion worker/pages/markdown.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ const mathInlineExt = {
},
}

export function makeMarkdown(content: string): string {
export function makeMarkdown(content: string, sourceUrl?: string): string {
const metadata: DocMetadata = { title: defaultTitle, description: "", toc: [] }
const slugger = new GithubSlugger()

Expand Down Expand Up @@ -352,6 +352,7 @@ export function makeMarkdown(content: string): string {
const tocHtml = renderToc(metadata.toc)
const hasToc = tocHtml.length > 0
const { jsFile, cssPaths } = getAssetPaths(manifest, "pages/render/markdown.ts")
const escapedSourceUrl = sourceUrl ? escapeHtml(sourceUrl) : ""

return `<!DOCTYPE html>
<html lang='en' class='light'>
Expand All @@ -360,6 +361,8 @@ export function makeMarkdown(content: string): string {
<meta name='viewport' content='width=device-width, initial-scale=1, shrink-to-fit=no'>
<title>${metadata.title}</title>
${metadata.description.length > 0 ? `<meta name='description' content='${metadata.description}'>` : ""}
${escapedSourceUrl ? `<link rel='canonical' href='${escapedSourceUrl}'>` : ""}
${escapedSourceUrl ? `<meta property='og:url' content='${escapedSourceUrl}'>` : ""}
<link rel='stylesheet' href='https://pages.github.com/assets/css/style.css'>
${renderCssLinks(cssPaths)}
<style>${sidebarStyles}</style>
Expand Down