diff --git a/src/langs/fa.json b/src/langs/fa.json index b8b00d0..29a38d5 100644 --- a/src/langs/fa.json +++ b/src/langs/fa.json @@ -73,7 +73,7 @@ }, "setting": { "title": "تنظیمات", - "personality": "شخصی سازی", + "personality": "قالب", "mail_server": "تنظیمات میل سرور", "domain": "تنظیمات دامنه", "address": "نشانی ها", diff --git a/src/pages/setting/personality/utils/ExportHTML.ts b/src/pages/setting/personality/utils/ExportHTML.ts index c1e9f20..f6e0a65 100644 --- a/src/pages/setting/personality/utils/ExportHTML.ts +++ b/src/pages/setting/personality/utils/ExportHTML.ts @@ -10,79 +10,9 @@ import { SectionType, } from "../types/Types"; -// تابع برای تبدیل تصویر به base64 -const imageToBase64 = async (imageUrl: string): Promise => { - try { - const response = await fetch(imageUrl); - const blob = await response.blob(); - return new Promise((resolve, reject) => { - const reader = new FileReader(); - reader.onload = () => resolve(reader.result as string); - reader.onerror = reject; - reader.readAsDataURL(blob); - }); - } catch (error) { - console.error("Error converting image to base64:", error); - return imageUrl; // در صورت خطا، URL اصلی را برگردان - } -}; - -// تابع برای تبدیل همه تصاویر در داده‌ها به base64 -const convertImagesToBase64 = async ( - data: PersonalityDataType -): Promise => { - const convertSectionImages = async ( - section: SectionType - ): Promise => { - const items = await Promise.all( - section.items.map(async (item) => { - // تبدیل تصاویر در images array - const images = await Promise.all( - item.images.map(async (image) => ({ - ...image, - src: await imageToBase64(image.src), - })) - ); - - // تبدیل background image - let backgroundImage = item.backgroundImage; - if (backgroundImage) { - backgroundImage = await imageToBase64(backgroundImage); - } - - return { - ...item, - images, - backgroundImage, - }; - }) - ); - - return { - ...section, - items, - }; - }; - - const [header, content, footer] = await Promise.all([ - convertSectionImages(data.header), - convertSectionImages(data.content), - convertSectionImages(data.footer), - ]); - - return { - header, - content, - footer, - }; -}; - export const exportPersonalityToHTML = async ( data: PersonalityDataType ): Promise => { - // تبدیل تصاویر به base64 - const dataWithBase64Images = await convertImagesToBase64(data); - // Helper functions const getHorizontalAlign = (alignment?: HorizontalAlignment) => { switch (alignment) { @@ -338,7 +268,8 @@ export const exportPersonalityToHTML = async ( const renderSection = ( section: SectionType, sectionHeight: string, - paddingTop = "" + paddingTop = "", + isContentSection = false ) => { if (section.columnsCount > 0) { return ` @@ -418,6 +349,11 @@ export const exportPersonalityToHTML = async ( }" style="padding: 8px; font-size: 14px; line-height: 1.4;"> ${renderTexts(item?.texts || [])} ${renderImages(item?.images || [])} + ${ + isContentSection + ? '
{{content}}
' + : "" + } `; @@ -490,9 +426,9 @@ export const exportPersonalityToHTML = async ( const html = `
- ${renderSection(dataWithBase64Images.header, "123px")} - ${renderSection(dataWithBase64Images.content, "246px", "16px")} - ${renderSection(dataWithBase64Images.footer, "123px", "16px")} + ${renderSection(data.header, "123px")} + ${renderSection(data.content, "246px", "16px", true)} + ${renderSection(data.footer, "123px", "16px")}
`;