proc canonical url

This commit is contained in:
Moon Man 2024-01-01 08:17:44 -05:00
parent 532787a77b
commit 38c26c07cd
2 changed files with 7 additions and 4 deletions

View File

@ -1,6 +1,6 @@
import { readFileSync } from "node:fs"; import { readFileSync } from "node:fs";
import markdownit from "markdown-it"; 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 { User, getByActor } from "./user.js";
import { fillRoute, reverseRoute } from "./router.js"; import { fillRoute, reverseRoute } from "./router.js";
import { streamToString, hashDigest } from "./util.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) => { export const deleteArticleActivity = (article: Article, user: User) => {
const actor = fillRoute("actor", user.nickname); 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 context = fillRoute("context", article.id);
const objectId = fillRoute("object", 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<string, any> = { const activity: Record<string, any> = {
id: fillRoute("activity", article.id) + "/delete", id: fillRoute("activity", article.id) + "/delete",
@ -201,7 +201,7 @@ export const createArticleObject = (article: Article, nickname: string) => {
const context = fillRoute("context", article.id); const context = fillRoute("context", article.id);
const objectId = fillRoute("object", 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") + ` const content = readFileSync(article.file as string, "utf-8") + `
[Read on site](${canonicalUrl}) [Read on site](${canonicalUrl})

View File

@ -63,3 +63,6 @@ export const getAll = async (count: number, lastId = Number.MAX_SAFE_INTEGER) =>
.limit(count) .limit(count)
.then((articles) => articles.map((a) => fixDates<Article>(a))) .then((articles) => articles.map((a) => fixDates<Article>(a)))
; ;
export const buildCanonicalUrl = (article: Article) =>
`https://${process.env.blog_host}/${article.slug}.html`;