From 4524a66c49e1c2f1aac0ffca877f0bff0603aff1 Mon Sep 17 00:00:00 2001 From: Moon Man Date: Sun, 31 Dec 2023 12:40:15 -0500 Subject: [PATCH] fix html, add footer to note --- src/activity.ts | 18 ++++++++++++++---- src/command.ts | 10 +++++++++- src/index.ts | 8 +------- src/util.ts | 8 ++++++++ 4 files changed, 32 insertions(+), 12 deletions(-) diff --git a/src/activity.ts b/src/activity.ts index 9b1024e..db9985b 100644 --- a/src/activity.ts +++ b/src/activity.ts @@ -153,7 +153,11 @@ export const createArticleActivity = (article: Article, user: User) => { }; const objectId = fillRoute("object", article.id); - const content = readFileSync(article.file as string, "utf-8"); + const content = readFileSync(article.file as string, "utf-8") + ` + +[Read on site](${canonicalUrl}) + `; + activity.object = { id: objectId, actor, @@ -179,9 +183,15 @@ export const createArticleObject = (article: Article, nickname: string) => { const actor = fillRoute("actor", nickname); const context = fillRoute("context", article.id); const objectId = fillRoute("object", article.id); - const content = readFileSync(article.file as string, "utf-8"); - const published = typeof article.created_at === "number" ? new Date(article.created_at) : article.created_at; + const canonicalUrl = `https://${process.env.blog_host}/${article.slug}.html`; + const content = readFileSync(article.file as string, "utf-8") + ` + +[Read on site](${canonicalUrl}) + `; + + const published = typeof article.created_at === "number" ? new Date(article.created_at) : article.created_at; + const followers = fillRoute("followers", nickname); const obj: Record = { @@ -197,7 +207,7 @@ export const createArticleObject = (article: Article, nickname: string) => { mediaType: "text/html", source: { mediaType: "text/markdown", - content + content: content }, published } diff --git a/src/command.ts b/src/command.ts index 456c3f8..09c68a3 100644 --- a/src/command.ts +++ b/src/command.ts @@ -46,7 +46,15 @@ else if (c === "new-article") { const htmlFilename = `pages/${slug}.html`; const markdown = fs.readFileSync(filename, "utf-8"); - const html = md.render(markdown); + const rendered = md.render(markdown); + const html = ` + + +${title} + + +${rendered} +`; fs.writeFileSync(htmlFilename, html); const article = await insertArticle(user.id, slug, title); diff --git a/src/index.ts b/src/index.ts index 8958367..27747a5 100644 --- a/src/index.ts +++ b/src/index.ts @@ -7,13 +7,7 @@ import { getBySlug as getArticleBySlug, getById, getByUserId, getAll as getAllAr import { userToPerson, TYPE as ACTIVITYPUB_TYPE, handleInboxPost, createArticleObject, CONTEXT, createArticleActivity } from "./activity.js"; import { handleFollowerGet } from "./follower.js"; import { handleWebfingerGet } from "./net.js"; - -const escapeHtml = (unsafe: string) => unsafe - .replaceAll("&", "&") - .replaceAll("<", "<") - .replaceAll(">", ">") - .replaceAll("\"", """) - .replace("'", "'"); +import { escapeHtml } from "./util.js"; const port = parseInt(process.env.port || "8080"); const app = express(); diff --git a/src/util.ts b/src/util.ts index 60e4f19..4239292 100644 --- a/src/util.ts +++ b/src/util.ts @@ -18,3 +18,11 @@ export const fixDates = (record: Record, columns: string[] = ["c }); return record as T; }; + +export const escapeHtml = (unsafe: string) => unsafe + .replaceAll("&", "&") + .replaceAll("<", "<") + .replaceAll(">", ">") + .replaceAll("\"", """) + .replace("'", "'") + ; \ No newline at end of file