Files
indiekit-endpoint-activitypub/lib/controllers/followers.js
Ricardo 0cf49e037c fix: remove duplicate page headings across all AP templates
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.
2026-02-21 21:32:56 +01:00

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,
};
}