temp front page

This commit is contained in:
Moon Man 2023-12-31 11:30:03 -05:00
parent a87fa7cc0e
commit 31166bff3b
2 changed files with 35 additions and 3 deletions

View File

@ -52,3 +52,10 @@ export const insert = async (userId: number, slug: string, title: string): Promi
...data ...data
} as Article)) } as Article))
}; };
export const getAll = async (count: number, lastId = Number.MAX_SAFE_INTEGER) =>
db<Article>("articles")
.where("id", "<", lastId)
.orderBy("created_at", "desc")
.limit(count)
;

View File

@ -3,7 +3,7 @@ import bodyParser from "body-parser";
import { toCollection as getOutbox } from "./outbox.js"; import { toCollection as getOutbox } from "./outbox.js";
import { getById as getUserById, getNickname, get as getUserByNickname, getId as getUserId, User } from "./user.js"; import { getById as getUserById, getNickname, get as getUserByNickname, getId as getUserId, User } from "./user.js";
import { Routes } from "./router.js"; import { Routes } from "./router.js";
import { getBySlug as getArticleBySlug, getById, getByUserId } from "./article.js"; import { getBySlug as getArticleBySlug, getById, getByUserId, getAll as getAllArticles } from "./article.js";
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";
@ -22,6 +22,31 @@ app.use(
bodyParser.text({ type: "*/*" }) bodyParser.text({ type: "*/*" })
); );
/**
* Temporary until better templating is in.
*/
app.get("/", async (req, res) => {
const last = typeof req.query.last === "number" ? parseInt(req.query.last) : Number.MAX_SAFE_INTEGER;
const articles = await getAllArticles(8, last);
const renderedArticles = articles.map((a) => `
<li>
<a href="/${a.slug}.html">${escapeHtml(a.title)} - ${a.created_at.toDateString()}</a>
</li>
`).join("\n");
const payload = `<!DOCTYPE html>
<html>
<body>
<h1>${escapeHtml(process.env.blog_title || "")}</h1>
<ul>
${renderedArticles}
</ul>
`;
});
app.post(Routes.inbox, handleInboxPost); app.post(Routes.inbox, handleInboxPost);
app.get(Routes.followers, handleFollowerGet); app.get(Routes.followers, handleFollowerGet);