feat: enhance image handling and layout adjustments
- Added image quality settings and device sizes in next.config.ts for better image optimization. - Updated package dependencies, including cheerio and baseline-browser-mapping. - Improved global styles for blog content images to ensure responsiveness. - Refactored button components for consistent sizing and styling across the application. - Enhanced blog post card layout with new variants and improved author name formatting. - Adjusted hero section and content layout for better visual appeal and user experience.
This commit is contained in:
+30
-1
@@ -3,9 +3,21 @@ import {
|
||||
mergeHeadingIdsIntoContentSegments,
|
||||
type ContentSegment,
|
||||
} from "@/lib/blog-blocks";
|
||||
import { getFullSizeWpImageUrl } from "@/lib/wp-api";
|
||||
|
||||
export type { ContentSegment } from "@/lib/blog-blocks";
|
||||
|
||||
const AUTHOR_NAME_OVERRIDES: Record<string, string> = {
|
||||
adm: "احمدرضا بدیعی",
|
||||
};
|
||||
|
||||
/** Maps WordPress author display names to site-facing labels. */
|
||||
export function formatAuthorName(name: string | null | undefined): string | null {
|
||||
if (!name?.trim()) return null;
|
||||
const normalized = name.trim().toLowerCase();
|
||||
return AUTHOR_NAME_OVERRIDES[normalized] ?? name.trim();
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a URL-safe slug from heading text (strip HTML, normalize, Persian-friendly).
|
||||
*/
|
||||
@@ -43,7 +55,9 @@ export function parseContentHeadings(html: string): {
|
||||
toc: TocItem[];
|
||||
segments: ContentSegment[];
|
||||
} {
|
||||
const { htmlWithPlaceholders, segments: rawSegments } = discoverBlocks(html);
|
||||
const { htmlWithPlaceholders, segments: rawSegments } = discoverBlocks(
|
||||
enhanceContentImages(html)
|
||||
);
|
||||
|
||||
usedIds.clear();
|
||||
const toc: TocItem[] = [];
|
||||
@@ -94,3 +108,18 @@ export function getReadingTimeMinutes(html: string): number {
|
||||
return Math.max(1, Math.ceil(wordCount / WPM));
|
||||
}
|
||||
|
||||
/** Use full-size WordPress uploads and drop responsive srcset that picks smaller variants. */
|
||||
export function enhanceContentImages(html: string): string {
|
||||
return html.replace(/<img\b([^>]*)>/gi, (tag, attrs: string) => {
|
||||
let next = attrs
|
||||
.replace(/\s+srcset=(["'])[^"']*\1/gi, "")
|
||||
.replace(/\s+sizes=(["'])[^"']*\1/gi, "")
|
||||
.replace(/\s+src=(["'])([^"']+)\1/gi, (_m, quote: string, src: string) => {
|
||||
return ` src=${quote}${getFullSizeWpImageUrl(src)}${quote}`;
|
||||
});
|
||||
if (!/\bloading=/i.test(next)) next += ' loading="lazy"';
|
||||
if (!/\bdecoding=/i.test(next)) next += ' decoding="async"';
|
||||
return `<img${next}>`;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user