UNPKG

@ai-growth/nextjs

Version:

Seamlessly integrate Sanity CMS with Next.js applications for automated blog routing and rendering

109 lines (108 loc) 6.23 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.AuthorInfo = void 0; const jsx_runtime_1 = require("react/jsx-runtime"); const OptimizedImage_1 = require("./OptimizedImage"); const DefaultTemplate_module_css_1 = __importDefault(require("./DefaultTemplate.module.css")); /** * AuthorInfo component for displaying author information */ const AuthorInfo = ({ author, showBio = true, showImage = true, className = '', }) => { // Don't render if no author data if (!author) { return null; } const getAuthorName = () => { if (typeof author === 'string') { return author; } return author.name || author.title || 'Unknown Author'; }; const getAuthorBio = () => { if (typeof author === 'string') { return ''; } return author.bio || author.description || ''; }; const getAuthorImage = () => { if (typeof author === 'string') { return null; } // Handle different image field structures if (author.image) { // Sanity image object if (typeof author.image === 'object' && author.image.asset) { return typeof author.image.asset === 'string' ? author.image.asset : author.image.asset.url; } // Direct image URL if (typeof author.image === 'string') { return author.image; } } // Try alternative field names if (author.avatar) { return typeof author.avatar === 'string' ? author.avatar : author.avatar.url; } if (author.photo) { return typeof author.photo === 'string' ? author.photo : author.photo.url; } return null; }; const getAuthorInitials = (name) => { return name .split(' ') .map(word => word.charAt(0)) .join('') .toUpperCase() .slice(0, 2); }; const getAuthorSlug = () => { if (typeof author === 'string') { return null; } if (author.slug) { return typeof author.slug === 'string' ? author.slug : author.slug.current || author.slug._ref; } return null; }; const authorName = getAuthorName(); const authorBio = getAuthorBio(); const authorImage = getAuthorImage(); const authorSlug = getAuthorSlug(); const renderAuthorImage = () => { if (!showImage) { return null; } if (authorImage) { return ((0, jsx_runtime_1.jsx)(OptimizedImage_1.AvatarImage, { image: authorImage, alt: `${authorName} avatar`, className: DefaultTemplate_module_css_1.default.authorAvatar, size: "md", onError: () => { // Fallback will be handled by the AvatarImage component itself console.log(`Failed to load avatar for ${authorName}`); } })); } return null; }; const renderAuthorPlaceholder = () => { if (!showImage || authorImage) { return null; } return ((0, jsx_runtime_1.jsx)("div", { className: DefaultTemplate_module_css_1.default.authorAvatarPlaceholder, children: getAuthorInitials(authorName) })); }; const renderAuthorName = () => { if (authorSlug) { // If we have a slug, we could potentially link to author page // For now, just render as text - linking would require router context return ((0, jsx_runtime_1.jsx)("h3", { className: DefaultTemplate_module_css_1.default.authorName, children: authorName })); } return ((0, jsx_runtime_1.jsx)("h3", { className: DefaultTemplate_module_css_1.default.authorName, children: authorName })); }; return ((0, jsx_runtime_1.jsxs)("div", { className: `${DefaultTemplate_module_css_1.default.authorInfo} ${className}`, children: [showImage && ((0, jsx_runtime_1.jsxs)("div", { className: DefaultTemplate_module_css_1.default.authorImageContainer, children: [renderAuthorImage(), renderAuthorPlaceholder(), authorImage && ((0, jsx_runtime_1.jsx)("div", { className: DefaultTemplate_module_css_1.default.authorAvatarPlaceholder, style: { display: 'none' }, children: getAuthorInitials(authorName) }))] })), (0, jsx_runtime_1.jsxs)("div", { className: DefaultTemplate_module_css_1.default.authorDetails, children: [renderAuthorName(), showBio && authorBio && ((0, jsx_runtime_1.jsx)("p", { className: DefaultTemplate_module_css_1.default.authorBio, children: authorBio })), typeof author === 'object' && ((0, jsx_runtime_1.jsxs)(jsx_runtime_1.Fragment, { children: [author.title && author.title !== authorName && ((0, jsx_runtime_1.jsx)("p", { className: DefaultTemplate_module_css_1.default.authorTitle, children: author.title })), author.company && ((0, jsx_runtime_1.jsx)("p", { className: DefaultTemplate_module_css_1.default.authorCompany, children: author.company })), author.social && ((0, jsx_runtime_1.jsxs)("div", { className: DefaultTemplate_module_css_1.default.authorSocial, children: [author.social.twitter && ((0, jsx_runtime_1.jsx)("a", { href: `https://twitter.com/${author.social.twitter.replace('@', '')}`, target: "_blank", rel: "noopener noreferrer", className: DefaultTemplate_module_css_1.default.socialLink, "aria-label": `${authorName} on Twitter`, children: "Twitter" })), author.social.linkedin && ((0, jsx_runtime_1.jsx)("a", { href: author.social.linkedin, target: "_blank", rel: "noopener noreferrer", className: DefaultTemplate_module_css_1.default.socialLink, "aria-label": `${authorName} on LinkedIn`, children: "LinkedIn" })), author.social.website && ((0, jsx_runtime_1.jsx)("a", { href: author.social.website, target: "_blank", rel: "noopener noreferrer", className: DefaultTemplate_module_css_1.default.socialLink, "aria-label": `${authorName}'s website`, children: "Website" }))] }))] }))] })] })); }; exports.AuthorInfo = AuthorInfo; exports.default = exports.AuthorInfo;