From 8d4aa024e3ebf0503d953da0cd3dce17b18cebe5 Mon Sep 17 00:00:00 2001 From: JOYCEQL <1449239013@qq.com> Date: Thu, 12 Mar 2026 00:52:18 +0800 Subject: [PATCH] style: education preview --- .../classic/sections/EducationSection.tsx | 6 +++--- .../creative/sections/EducationSection.tsx | 6 +++--- .../elegant/sections/EducationSection.tsx | 6 +++--- .../left-right/sections/EducationSection.tsx | 6 +++--- .../minimalist/sections/EducationSection.tsx | 6 +++--- .../modern/sections/EducationSection.tsx | 4 ++-- .../timeline/sections/EducationSection.tsx | 6 +++--- src/lib/richText.ts | 20 +++++++++++++++++++ 8 files changed, 40 insertions(+), 20 deletions(-) diff --git a/src/components/templates/classic/sections/EducationSection.tsx b/src/components/templates/classic/sections/EducationSection.tsx index b750788..563431a 100644 --- a/src/components/templates/classic/sections/EducationSection.tsx +++ b/src/components/templates/classic/sections/EducationSection.tsx @@ -3,7 +3,7 @@ import { Education, GlobalSettings } from "@/types/resume"; import SectionTitle from "./SectionTitle"; import SectionWrapper from "../../shared/SectionWrapper"; import { useLocale } from "@/i18n/compat/client"; -import { normalizeRichTextContent } from "@/lib/richText"; +import { hasMeaningfulRichTextContent, normalizeRichTextContent } from "@/lib/richText"; import { formatDateString } from "@/lib/utils"; interface EducationSectionProps { @@ -25,7 +25,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {visibleEducation?.map((edu) => ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( ( -
+
{edu.school}
{centerSubtitle && ( @@ -45,7 +45,7 @@ const EducationSection = ({ education, globalSettings, showTitle = true }: Educa {edu.gpa && ` · GPA ${edu.gpa}`} )} - {edu.description && ( + {hasMeaningfulRichTextContent(edu.description) && ( /i; const EMPTY_PARAGRAPH_REGEX = /

(?:\s| |)*<\/p>/gi; +const HTML_BREAK_REGEX = //gi; +const HTML_ANY_TAG_REGEX = /<\/?[^>]+>/g; +const INVISIBLE_WHITESPACE_REGEX = /[\s\u200B-\u200D\uFEFF]/g; const escapeHtml = (text: string) => text @@ -23,3 +26,20 @@ export const normalizeRichTextContent = (content?: string) => { return normalized.replace(EMPTY_PARAGRAPH_REGEX, "


"); }; + +export const hasMeaningfulRichTextContent = (content?: string) => { + if (!content) return false; + + if (!HTML_TAG_REGEX.test(content)) { + return content.replace(INVISIBLE_WHITESPACE_REGEX, "").length > 0; + } + + const plainText = content + .replace(EMPTY_PARAGRAPH_REGEX, "") + .replace(HTML_BREAK_REGEX, "") + .replace(/ /gi, " ") + .replace(HTML_ANY_TAG_REGEX, "") + .replace(INVISIBLE_WHITESPACE_REGEX, ""); + + return plainText.length > 0; +};