temp front page
This commit is contained in:
parent
a87fa7cc0e
commit
31166bff3b
|
@ -52,3 +52,10 @@ export const insert = async (userId: number, slug: string, title: string): Promi
|
|||
...data
|
||||
} 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)
|
||||
;
|
||||
|
|
27
src/index.ts
27
src/index.ts
|
@ -3,7 +3,7 @@ import bodyParser from "body-parser";
|
|||
import { toCollection as getOutbox } from "./outbox.js";
|
||||
import { getById as getUserById, getNickname, get as getUserByNickname, getId as getUserId, User } from "./user.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 { handleFollowerGet } from "./follower.js";
|
||||
import { handleWebfingerGet } from "./net.js";
|
||||
|
@ -22,6 +22,31 @@ app.use(
|
|||
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.get(Routes.followers, handleFollowerGet);
|
||||
|
||||
|
|
Loading…
Reference in New Issue