Add basic author information to topic data (#12202)

* feat: add author metadata to topics

* docs: add author object to OpenAPI definition

* docs: add remaining author properties to openapi definition

* docs: mark optional properties optional

* docs: properly set required properties
This commit is contained in:
Opliko
2023-12-01 15:08:50 +01:00
committed by GitHub
parent b41c7f2a8a
commit 2d8026ebb7
2 changed files with 17 additions and 2 deletions

View File

@@ -408,6 +408,20 @@ get:
type: string
postIndex:
type: number
author:
type: object
required: [username, uid]
properties:
username:
type: string
userslug:
type: string
uid:
type: number
fullname:
type: string
displayname:
type: string
- type: object
description: Optional properties that may or may not be present (except for `tid`, which is always present, and is only here as a hack to pass validation)
properties:

View File

@@ -114,7 +114,8 @@ topicsController.get = async function getTopic(req, res, next) {
topicData.postIndex = postIndex;
await Promise.all([
const [author] = await Promise.all([
user.getUserFields(topicData.uid, ['username', 'userslug']),
buildBreadcrumbs(topicData),
addOldCategory(topicData, userPrivileges),
addTags(topicData, req, res, currentPage),
@@ -123,12 +124,12 @@ topicsController.get = async function getTopic(req, res, next) {
analytics.increment([`pageviews:byCid:${topicData.category.cid}`]),
]);
topicData.author = author;
topicData.pagination = pagination.create(currentPage, pageCount, req.query);
topicData.pagination.rel.forEach((rel) => {
rel.href = `${url}/topic/${topicData.slug}${rel.href}`;
res.locals.linkTags.push(rel);
});
res.render('topic', topicData);
};