mirror of
https://github.com/svemagie/indiekit-endpoint-activitypub.git
synced 2026-04-02 15:44:58 +02:00
document.njk already renders title as h1 via the heading macro. All 14 AP templates were also calling heading() with level 1 inside their content block, producing two h1 elements per page. Removed the redundant calls and moved dynamic count prefixes into the title variable in followers/following controllers.
59 lines
1.6 KiB
JavaScript
59 lines
1.6 KiB
JavaScript
/**
|
|
* Followers list controller — paginated list of accounts following this actor.
|
|
*/
|
|
const PAGE_SIZE = 20;
|
|
|
|
export function followersController(mountPath) {
|
|
return async (request, response, next) => {
|
|
try {
|
|
const { application } = request.app.locals;
|
|
const collection = application?.collections?.get("ap_followers");
|
|
|
|
if (!collection) {
|
|
return response.render("activitypub-followers", {
|
|
title: response.locals.__("activitypub.followers"),
|
|
followers: [],
|
|
followerCount: 0,
|
|
mountPath,
|
|
});
|
|
}
|
|
|
|
const page = Math.max(1, Number.parseInt(request.query.page, 10) || 1);
|
|
const totalCount = await collection.countDocuments();
|
|
const totalPages = Math.ceil(totalCount / PAGE_SIZE);
|
|
|
|
const followers = await collection
|
|
.find()
|
|
.sort({ followedAt: -1 })
|
|
.skip((page - 1) * PAGE_SIZE)
|
|
.limit(PAGE_SIZE)
|
|
.toArray();
|
|
|
|
const cursor = buildCursor(page, totalPages, mountPath + "/admin/followers");
|
|
|
|
response.render("activitypub-followers", {
|
|
title: `${totalCount} ${response.locals.__("activitypub.followers")}`,
|
|
followers,
|
|
followerCount: totalCount,
|
|
mountPath,
|
|
cursor,
|
|
});
|
|
} catch (error) {
|
|
next(error);
|
|
}
|
|
};
|
|
}
|
|
|
|
function buildCursor(page, totalPages, basePath) {
|
|
if (totalPages <= 1) return null;
|
|
|
|
return {
|
|
previous: page > 1
|
|
? { href: `${basePath}?page=${page - 1}` }
|
|
: undefined,
|
|
next: page < totalPages
|
|
? { href: `${basePath}?page=${page + 1}` }
|
|
: undefined,
|
|
};
|
|
}
|