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,
|
date: dateStr,
|
||||||
image: coverUrl,
|
image: coverUrl,
|
||||||
slug: b.slug,
|
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',
|
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,
|
editorDesignation: b.editorDesignation || null,
|
||||||
tags: b.tags || [],
|
tags: b.tags || [],
|
||||||
metaTitle: b.metaTitle || null,
|
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 bgPatternUrl = assetUrl('/assets/Background pattern About Us Hero section.svg');
|
||||||
const spotlightUrl = assetUrl('/assets/Spotlight vector.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 authorRole = typeof blog.authorDesignation === 'string' ? blog.authorDesignation : 'Chief AI Architect & Head of Data Engineering';
|
||||||
const authorAvatar = '/assets/arvindh_agentic_ai.jpg';
|
const authorAvatar = '/assets/arvindh_agentic_ai.jpg';
|
||||||
const relatedArticles = allBlogs.filter(b => b.id !== blog.id).slice(0, 2);
|
const relatedArticles = allBlogs.filter(b => b.id !== blog.id).slice(0, 2);
|
||||||
|
|||||||
@@ -14,12 +14,12 @@ export default {
|
|||||||
const user = ctx?.state?.user;
|
const user = ctx?.state?.user;
|
||||||
|
|
||||||
if (user) {
|
if (user) {
|
||||||
// Auto-fill author relation if not explicitly set by user
|
|
||||||
if (!data.author) {
|
if (!data.author) {
|
||||||
data.author = user.id;
|
data.author = user.id;
|
||||||
}
|
}
|
||||||
|
if (!data.authorName) {
|
||||||
// Auto-fill author designation based on logged-in account
|
data.authorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username || user.email;
|
||||||
|
}
|
||||||
if (!data.authorDesignation && user.email) {
|
if (!data.authorDesignation && user.email) {
|
||||||
data.authorDesignation = designationMap[user.email] || `${user.firstname || ''} ${user.lastname || ''}`.trim();
|
data.authorDesignation = designationMap[user.email] || `${user.firstname || ''} ${user.lastname || ''}`.trim();
|
||||||
}
|
}
|
||||||
@@ -32,22 +32,24 @@ export default {
|
|||||||
const user = ctx?.state?.user;
|
const user = ctx?.state?.user;
|
||||||
|
|
||||||
if (user && data) {
|
if (user && data) {
|
||||||
// Auto-fill author relation if empty
|
|
||||||
if (!data.author) {
|
if (!data.author) {
|
||||||
data.author = user.id;
|
data.author = user.id;
|
||||||
}
|
}
|
||||||
|
if (!data.authorName && user) {
|
||||||
// Auto-fill author designation if empty
|
data.authorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username || user.email;
|
||||||
|
}
|
||||||
if (!data.authorDesignation && user.email) {
|
if (!data.authorDesignation && user.email) {
|
||||||
data.authorDesignation = designationMap[user.email] || `${user.firstname || ''} ${user.lastname || ''}`.trim();
|
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');
|
const isEditor = user.roles?.some((r: any) => r.code === 'strapi-editor' || r.code === 'strapi-super-admin');
|
||||||
if (isEditor) {
|
if (isEditor) {
|
||||||
if (!data.editor) {
|
if (!data.editor) {
|
||||||
data.editor = user.id;
|
data.editor = user.id;
|
||||||
}
|
}
|
||||||
|
if (!data.editorName && user) {
|
||||||
|
data.editorName = `${user.firstname || ''} ${user.lastname || ''}`.trim() || user.username;
|
||||||
|
}
|
||||||
if (!data.editorDesignation && user.email) {
|
if (!data.editorDesignation && user.email) {
|
||||||
data.editorDesignation = designationMap[user.email] || 'Senior Editor';
|
data.editorDesignation = designationMap[user.email] || 'Senior Editor';
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,9 @@
|
|||||||
"default": "Draft",
|
"default": "Draft",
|
||||||
"required": true
|
"required": true
|
||||||
},
|
},
|
||||||
|
"authorName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"author": {
|
"author": {
|
||||||
"type": "relation",
|
"type": "relation",
|
||||||
"relation": "oneToOne",
|
"relation": "oneToOne",
|
||||||
@@ -68,6 +71,9 @@
|
|||||||
"authorDesignation": {
|
"authorDesignation": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
},
|
},
|
||||||
|
"editorName": {
|
||||||
|
"type": "string"
|
||||||
|
},
|
||||||
"editor": {
|
"editor": {
|
||||||
"type": "relation",
|
"type": "relation",
|
||||||
"relation": "oneToOne",
|
"relation": "oneToOne",
|
||||||
|
|||||||
Reference in New Issue
Block a user