fix html, add footer to note

This commit is contained in:
Moon Man 2023-12-31 12:40:15 -05:00
parent c380a178f0
commit 4524a66c49
4 changed files with 32 additions and 12 deletions

View File

@ -153,7 +153,11 @@ export const createArticleActivity = (article: Article, user: User) => {
}; };
const objectId = fillRoute("object", article.id); 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 = { activity.object = {
id: objectId, id: objectId,
actor, actor,
@ -179,9 +183,15 @@ export const createArticleObject = (article: Article, nickname: string) => {
const actor = fillRoute("actor", nickname); const actor = fillRoute("actor", nickname);
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 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 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 followers = fillRoute("followers", nickname);
const obj: Record<string, any> = { const obj: Record<string, any> = {
@ -197,7 +207,7 @@ export const createArticleObject = (article: Article, nickname: string) => {
mediaType: "text/html", mediaType: "text/html",
source: { source: {
mediaType: "text/markdown", mediaType: "text/markdown",
content content: content
}, },
published published
} }

View File

@ -46,7 +46,15 @@ else if (c === "new-article") {
const htmlFilename = `pages/${slug}.html`; const htmlFilename = `pages/${slug}.html`;
const markdown = fs.readFileSync(filename, "utf-8"); const markdown = fs.readFileSync(filename, "utf-8");
const html = md.render(markdown); const rendered = md.render(markdown);
const html = `<!DOCTYPE html>
<html>
<head>
<title>${title}</title>
</head>
<body>
${rendered}
`;
fs.writeFileSync(htmlFilename, html); fs.writeFileSync(htmlFilename, html);
const article = await insertArticle(user.id, slug, title); const article = await insertArticle(user.id, slug, title);

View File

@ -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 { userToPerson, TYPE as ACTIVITYPUB_TYPE, handleInboxPost, createArticleObject, CONTEXT, createArticleActivity } from "./activity.js";
import { handleFollowerGet } from "./follower.js"; import { handleFollowerGet } from "./follower.js";
import { handleWebfingerGet } from "./net.js"; import { handleWebfingerGet } from "./net.js";
import { escapeHtml } from "./util.js";
const escapeHtml = (unsafe: string) => unsafe
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll("\"", "&quot;")
.replace("'", "&#039;");
const port = parseInt(process.env.port || "8080"); const port = parseInt(process.env.port || "8080");
const app = express(); const app = express();

View File

@ -18,3 +18,11 @@ export const fixDates = <T>(record: Record<string, any>, columns: string[] = ["c
}); });
return record as T; return record as T;
}; };
export const escapeHtml = (unsafe: string) => unsafe
.replaceAll("&", "&amp;")
.replaceAll("<", "&lt;")
.replaceAll(">", "&gt;")
.replaceAll("\"", "&quot;")
.replace("'", "&#039;")
;