From 38c26c07cd757feb99c494c739b76a42b8975c62 Mon Sep 17 00:00:00 2001 From: Moon Man Date: Mon, 1 Jan 2024 08:17:44 -0500 Subject: [PATCH] proc canonical url --- src/activity.ts | 8 ++++---- src/article.ts | 3 +++ 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/src/activity.ts b/src/activity.ts index 14b22d0..58ca89e 100644 --- a/src/activity.ts +++ b/src/activity.ts @@ -1,6 +1,6 @@ import { readFileSync } from "node:fs"; import markdownit from "markdown-it"; -import { Article, getById as getArticleById } from "./article.js"; +import { Article, buildCanonicalUrl, getById as getArticleById } from "./article.js"; import { User, getByActor } from "./user.js"; import { fillRoute, reverseRoute } from "./router.js"; import { streamToString, hashDigest } from "./util.js"; @@ -155,10 +155,10 @@ export const handleInboxPost = async (req: Request, res: Response) => { export const deleteArticleActivity = (article: Article, user: User) => { const actor = fillRoute("actor", user.nickname); - const published = typeof article.updated_at === "number" ? new Date(article.updated_at) : article.updated_at; + const published = article.updated_at; const context = fillRoute("context", article.id); const objectId = fillRoute("object", article.id); - const canonicalUrl = `https://${process.env.blog_host}/${article.slug}.html`; + const canonicalUrl = buildCanonicalUrl(article); const activity: Record = { id: fillRoute("activity", article.id) + "/delete", @@ -201,7 +201,7 @@ export const createArticleObject = (article: Article, nickname: string) => { const context = fillRoute("context", article.id); const objectId = fillRoute("object", article.id); - const canonicalUrl = `https://${process.env.blog_host}/${article.slug}.html`; + const canonicalUrl = buildCanonicalUrl(article); const content = readFileSync(article.file as string, "utf-8") + ` [Read on site](${canonicalUrl}) diff --git a/src/article.ts b/src/article.ts index 80d0953..4660dfc 100644 --- a/src/article.ts +++ b/src/article.ts @@ -63,3 +63,6 @@ export const getAll = async (count: number, lastId = Number.MAX_SAFE_INTEGER) => .limit(count) .then((articles) => articles.map((a) => fixDates
(a))) ; + +export const buildCanonicalUrl = (article: Article) => + `https://${process.env.blog_host}/${article.slug}.html`; \ No newline at end of file