| @@ -8,12 +8,13 @@ | ||
| 8 | 8 | retryTwice, |
| 9 | 9 | setStatus, |
| 10 | 10 | } from '@auto-launch/functions/helpers'; |
| 11 | 11 | import { getHeadersAndFooters } from '@auto-launch/functions/wp'; |
| 12 | +import { launchStrings } from '@auto-launch/strings'; | |
| 12 | 13 | import { PATTERNS_HOST } from '@constants'; |
| 13 | 14 | import { digest } from '@shared/api/digest'; |
| 14 | 15 | import { reqDataBasics } from '@shared/lib/data'; |
| 15 | -import { __ } from '@wordpress/i18n'; | |
| 16 | +import { siteImageUrlsByType } from '@shared/lib/site-images'; | |
| 16 | 17 | |
| 17 | 18 | const url = `${PATTERNS_HOST}/api/home`; |
| 18 | 19 | const { wpLanguage, showImprint } = window.extSharedData; |
| 19 | 20 | const method = 'POST'; |
| @@ -26,14 +27,30 @@ | ||
| 26 | 27 | aiHeaders, |
| 27 | 28 | designBuild, |
| 28 | 29 | }) => { |
| 29 | 30 | // translators: this is for a action log UI. Keep it short |
| 30 | - setStatus(__('Preparing your home page', 'extendify-local')); | |
| 31 | + setStatus(launchStrings().statusHome); | |
| 31 | 32 | |
| 33 | + // A full-page design build already carries the whole home; skip the | |
| 34 | + // /api/home fetch and build the page from the built patterns directly. | |
| 35 | + const builtHome = designBuild?.builtPages?.find((p) => p.slug === 'home'); | |
| 36 | + if (builtHome?.fullPage && builtHome.patterns?.length) { | |
| 37 | + // The full page is final — keep the BE's sections verbatim and flag them | |
| 38 | + // so generatePageContent skips the /api/patterns rewrite. | |
| 39 | + const patterns = builtHome.patterns.map((p) => ({ | |
| 40 | + ...p, | |
| 41 | + contentGenerated: true, | |
| 42 | + })); | |
| 43 | + const parts = await resolveTemplateParts({ siteProfile, designBuild }); | |
| 44 | + return getHomeShape.parse({ | |
| 45 | + home: { id: 'home', slug: 'home', patterns, ...parts }, | |
| 46 | + }); | |
| 47 | + } | |
| 48 | + | |
| 32 | 49 | const body = JSON.stringify({ |
| 33 | 50 | ...reqDataBasics, |
| 34 | 51 | siteProfile, |
| 35 | - siteImages, | |
| 52 | + siteImages: siteImageUrlsByType(siteImages), | |
| 36 | 53 | sitePlugins, |
| 37 | 54 | aiHeaders, |
| 38 | 55 | // If pages are passed in they may be used |
| 39 | 56 | pages: designBuild?.pages ?? [], |
| @@ -58,11 +75,26 @@ | ||
| 58 | 75 | throw new Error(response.statusText); |
| 59 | 76 | } |
| 60 | 77 | |
| 61 | 78 | const template = homeTemplateShape.parse(await response.json()); |
| 79 | + template.patterns = applyDesignBuildNav( | |
| 80 | + template.patterns, | |
| 81 | + designBuild, | |
| 82 | + siteProfile.structure, | |
| 83 | + ); | |
| 62 | 84 | template.patterns = applyDesignBuildHero(template.patterns, designBuild); |
| 63 | - template.patterns = applyDesignBuildNav(template.patterns, designBuild); | |
| 64 | 85 | |
| 86 | + const parts = await resolveTemplateParts({ siteProfile, designBuild }); | |
| 87 | + return getHomeShape.parse({ home: { ...template, ...parts } }); | |
| 88 | +}; | |
| 89 | + | |
| 90 | +const resolveTemplateParts = async ({ siteProfile, designBuild }) => { | |
| 91 | + const headerPart = designBuild?.templateParts?.header; | |
| 92 | + const footerPart = designBuild?.templateParts?.footer; | |
| 93 | + // Both parts came from the design build; skip the template-parts fetch. | |
| 94 | + if (headerPart && footerPart) | |
| 95 | + return { headerCode: headerPart, footerCode: footerPart }; | |
| 96 | + | |
| 65 | 97 | const hasFooterNav = Array.isArray(showImprint) |
| 66 | 98 | ? showImprint.includes(wpLanguage ?? '') && |
| 67 | 99 | siteProfile.category === 'Business' |
| 68 | 100 | : false; |
| @@ -71,9 +103,9 @@ | ||
| 71 | 103 | useNavFooter: hasFooterNav, |
| 72 | 104 | }); |
| 73 | 105 | const randomHeader = head[Math.floor(Math.random() * head.length)]; |
| 74 | 106 | const randomFooter = foot[Math.floor(Math.random() * foot.length)]; |
| 75 | - const headerCode = | |
| 76 | - designBuild?.headerCode ?? randomHeader?.content?.raw?.trim() ?? ''; | |
| 77 | - const footerCode = randomFooter?.content?.raw?.trim() ?? ''; | |
| 78 | - return getHomeShape.parse({ home: { ...template, headerCode, footerCode } }); | |
| 107 | + return { | |
| 108 | + headerCode: headerPart ?? randomHeader?.content?.raw?.trim() ?? '', | |
| 109 | + footerCode: footerPart ?? randomFooter?.content?.raw?.trim() ?? '', | |
| 110 | + }; | |
| 79 | 111 | }; |