PluginProbe
Extendify / 3.0.4
Extendify v3.0.4
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / AutoLaunch / fetchers / get-home.js

get-home.js in Extendify 3.0.4, at src/AutoLaunch/fetchers/get-home.js

63 lines 1.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import {
2 applyDesignBuildHero,
3 applyDesignBuildNav,
4 } from '@auto-launch/fetchers/get-design-build';
5 import { getHomeShape, homeTemplateShape } from '@auto-launch/fetchers/shape';
6 import {
7 fetchWithTimeout,
8 retryTwice,
9 setStatus,
10 } from '@auto-launch/functions/helpers';
11 import { getHeadersAndFooters } from '@auto-launch/functions/wp';
12 import { PATTERNS_HOST } from '@constants';
13 import { reqDataBasics } from '@shared/lib/data';
14 import { __ } from '@wordpress/i18n';
15
16 const url = `${PATTERNS_HOST}/api/home`;
17 const { wpLanguage, showImprint } = window.extSharedData;
18 const method = 'POST';
19 const headers = { 'Content-Type': 'application/json' };
20
21 export const handleHome = async ({
22 siteProfile,
23 sitePlugins,
24 siteImages,
25 aiHeaders,
26 designBuild,
27 }) => {
28 // translators: this is for a action log UI. Keep it short
29 setStatus(__('Preparing your home page', 'extendify-local'));
30
31 const body = JSON.stringify({
32 ...reqDataBasics,
33 siteProfile,
34 siteImages,
35 sitePlugins,
36 aiHeaders,
37 // If pages are passed in they may be used
38 pages: designBuild?.pages ?? [],
39 buildId: designBuild?.buildId,
40 });
41
42 const response = await retryTwice(() =>
43 fetchWithTimeout(url, { method, headers, body }),
44 );
45 const template = homeTemplateShape.parse(await response.json());
46 template.patterns = applyDesignBuildHero(template.patterns, designBuild);
47 template.patterns = applyDesignBuildNav(template.patterns, designBuild);
48
49 const hasFooterNav = Array.isArray(showImprint)
50 ? showImprint.includes(wpLanguage ?? '') &&
51 siteProfile.category === 'Business'
52 : false;
53
54 const { headers: head, footers: foot } = await getHeadersAndFooters({
55 useNavFooter: hasFooterNav,
56 siteProfile,
57 });
58 const headerCode =
59 designBuild?.headerCode ?? head[0]?.content?.raw?.trim() ?? '';
60 const footerCode = foot[0]?.content?.raw?.trim() ?? '';
61 return getHomeShape.parse({ home: { ...template, headerCode, footerCode } });
62 };
63