feat: add authorName and editorName attributes to Strapi blog schema for dynamic author display
This commit is contained in:
+10
-2
@@ -81,9 +81,17 @@ export async function getStrapiBlogs() {
|
||||
date: dateStr,
|
||||
image: coverUrl,
|
||||
slug: b.slug,
|
||||
author: typeof b.author === 'string' ? b.author : (b.author?.firstname ? `${b.author.firstname} ${b.author.lastname || ''}`.trim() : (b.author?.username || 'Dr. Arvindh Ramachandran')),
|
||||
author: (typeof b.authorName === 'string' && b.authorName.trim())
|
||||
? b.authorName.trim()
|
||||
: (typeof b.author === 'string' && b.author.trim()
|
||||
? b.author.trim()
|
||||
: (b.author?.firstname ? `${b.author.firstname} ${b.author.lastname || ''}`.trim() : (b.author?.username || 'Cavin Editorial Team'))),
|
||||
authorDesignation: b.authorDesignation || 'Chief AI Architect & Head of Data Engineering',
|
||||
editor: typeof b.editor === 'string' ? b.editor : (b.editor?.firstname ? `${b.editor.firstname} ${b.editor.lastname || ''}`.trim() : (b.editor?.username || null)),
|
||||
editor: (typeof b.editorName === 'string' && b.editorName.trim())
|
||||
? b.editorName.trim()
|
||||
: (typeof b.editor === 'string' && b.editor.trim()
|
||||
? b.editor.trim()
|
||||
: (b.editor?.firstname ? `${b.editor.firstname} ${b.editor.lastname || ''}`.trim() : (b.editor?.username || null))),
|
||||
editorDesignation: b.editorDesignation || null,
|
||||
tags: b.tags || [],
|
||||
metaTitle: b.metaTitle || null,
|
||||
|
||||
@@ -145,7 +145,11 @@ export default function BlogDetailPage({ blog, allBlogs = [], isMobile, onNaviga
|
||||
const bgPatternUrl = assetUrl('/assets/Background pattern About Us Hero section.svg');
|
||||
const spotlightUrl = assetUrl('/assets/Spotlight vector.svg');
|
||||
|
||||
const authorName = typeof blog.author === 'string' ? blog.author : (blog.author?.firstname ? `${blog.author.firstname} ${blog.author.lastname || ''}`.trim() : 'Purushothaman Gopalan');
|
||||
const authorName = (typeof blog.authorName === 'string' && blog.authorName.trim())
|
||||
? blog.authorName.trim()
|
||||
: (typeof blog.author === 'string' && blog.author.trim()
|
||||
? blog.author.trim()
|
||||
: (blog.author?.firstname ? `${blog.author.firstname} ${blog.author.lastname || ''}`.trim() : 'Cavin Editorial Team'));
|
||||
const authorRole = typeof blog.authorDesignation === 'string' ? blog.authorDesignation : 'Chief AI Architect & Head of Data Engineering';
|
||||
const authorAvatar = '/assets/arvindh_agentic_ai.jpg';
|
||||
const relatedArticles = allBlogs.filter(b => b.id !== blog.id).slice(0, 2);
|
||||
|
||||
@@ -14,12 +14,12 @@ export default {
|
||||
const user = ctx?.state?.user;
|
||||
|
||||
if (user) {
|
||||
// Auto-fill author relation if not explicitly set by user
|
||||
if (!data.author) {
|
||||
data.author = user.id;
|
||||
}
|
||||
|
||||
// Auto-fill author designation based on logged-in account
|
||||
if (!data.authorName) {
|
||||
data.authorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username || user.email;
|
||||
}
|
||||
if (!data.authorDesignation && user.email) {
|
||||
data.authorDesignation = designationMap[user.email] || `${user.firstname || ''} ${user.lastname || ''}`.trim();
|
||||
}
|
||||
@@ -32,22 +32,24 @@ export default {
|
||||
const user = ctx?.state?.user;
|
||||
|
||||
if (user && data) {
|
||||
// Auto-fill author relation if empty
|
||||
if (!data.author) {
|
||||
data.author = user.id;
|
||||
}
|
||||
|
||||
// Auto-fill author designation if empty
|
||||
if (!data.authorName && user) {
|
||||
data.authorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username || user.email;
|
||||
}
|
||||
if (!data.authorDesignation && user.email) {
|
||||
data.authorDesignation = designationMap[user.email] || `${user.firstname || ''} ${user.lastname || ''}`.trim();
|
||||
}
|
||||
|
||||
// Auto-fill editor details if an Editor/Admin edits or approves
|
||||
const isEditor = user.roles?.some((r: any) => r.code === 'strapi-editor' || r.code === 'strapi-super-admin');
|
||||
if (isEditor) {
|
||||
if (!data.editor) {
|
||||
data.editor = user.id;
|
||||
}
|
||||
if (!data.editorName && user) {
|
||||
data.editorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username;
|
||||
}
|
||||
if (!data.editorDesignation && user.email) {
|
||||
data.editorDesignation = designationMap[user.email] || 'Senior Editor';
|
||||
}
|
||||
|
||||
@@ -60,6 +60,9 @@
|
||||
"default": "Draft",
|
||||
"required": true
|
||||
},
|
||||
"authorName": {
|
||||
"type": "string"
|
||||
},
|
||||
"author": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
@@ -68,6 +71,9 @@
|
||||
"authorDesignation": {
|
||||
"type": "string"
|
||||
},
|
||||
"editorName": {
|
||||
"type": "string"
|
||||
},
|
||||
"editor": {
|
||||
"type": "relation",
|
||||
"relation": "oneToOne",
|
||||
|
||||
Reference in New Issue
Block a user