PluginProbe
Extendify / 3.2.1
Extendify v3.2.1
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
← All changes | src/AutoLaunch/functions/wp.js +67 -37 3.0.43.2.1 View file →
@@ -5,16 +5,13 @@
5 5 import { __, sprintf } from '@wordpress/i18n';
6 6 import { addQueryArgs } from '@wordpress/url';
7 7
8 8 const allowedHeaders = [
9 - 'header',
10 - 'header-with-center-nav-and-social',
11 9 'header-atlas-beacon',
12 10 'header-ember-harbor',
13 11 'header-catalina-skyline',
14 12 'header-ceadar-peak',
15 13 ];
16 -const homeServicesHeaders = ['header-center-nav-with-phone'];
17 14 const allowedFooters = [
18 15 'footer',
19 16 'footer-social-icons',
20 17 'footer-with-center-logo-and-menu',
@@ -23,8 +20,10 @@
23 20 'footer-with-nav',
24 21 'footer-with-center-logo-social-nav',
25 22 ];
26 23
24 +const MS_PER_DAY = 86_400_000;
25 +
27 26 export const updateOption = (option, value) =>
28 27 apiFetch({
29 28 path: '/extendify/v1/auto-launch/options',
30 29 method: 'POST',
@@ -34,8 +33,21 @@
34 33 apiFetch({
35 34 path: addQueryArgs(`/extendify/v1/auto-launch/options`, { option }),
36 35 });
37 36
37 +export const storeSiteImages = (siteImages) =>
38 + apiFetch({
39 + path: '/extendify/v1/shared/site-images',
40 + method: 'POST',
41 + data: { siteImages },
42 + });
43 +
44 +export const clearSiteImages = () =>
45 + apiFetch({
46 + path: '/extendify/v1/shared/site-images/clear',
47 + method: 'POST',
48 + });
49 +
38 50 export const getPageById = (id) => {
39 51 try {
40 52 return apiFetch({ path: `/wp/v2/pages/${id}` });
41 53 } catch {
@@ -44,20 +56,15 @@
44 56 };
45 57
46 58 const getTemplateParts = () => apiFetch({ path: '/wp/v2/template-parts' });
47 59
48 -export const getHeadersAndFooters = async ({
49 - useNavFooter = false,
50 - siteProfile = {},
51 -} = {}) => {
60 +export const getHeadersAndFooters = async ({ useNavFooter = false } = {}) => {
52 61 const patterns = await getTemplateParts();
53 62 const extendablePatterns = patterns.filter(
54 63 ({ theme }) => theme === 'extendable',
55 64 );
56 - const headerSlugs =
57 - siteProfile.type === 'home services' ? homeServicesHeaders : allowedHeaders;
58 65 const headers = extendablePatterns?.filter(({ slug }) =>
59 - headerSlugs.includes(slug),
66 + allowedHeaders.includes(slug),
60 67 );
61 68
62 69 const footerNav =
63 70 useNavFooter &&
@@ -127,9 +134,48 @@
127 134
128 135 export const createCategory = (data) =>
129 136 apiFetch({ path: '/wp/v2/categories', method: 'POST', data });
130 137
131 -export const createBlogSampleData = async (siteStrings, siteImages) => {
138 +const formatImageUrl = (image) =>
139 + image?.includes('?q=80&w=1470') ? image : `${image}?q=80&w=1470`;
140 +
141 +const replacePostContentImages = (content, images) =>
142 + (content.match(/https:\/\/images\.unsplash\.com\/[^\s"]+/g) || []).reduce(
143 + (updated, match, i) =>
144 + updated.replace(match, formatImageUrl(images[i] || match)),
145 + content,
146 + );
147 +
148 +// The blog-section images fill the newest posts so the home's date-desc loop matches
149 +// the preview 1:1; extra posts fall back to the shared pool.
150 +export const buildBlogPosts = ({
151 + blogTitles,
152 + siteImages,
153 + blogImages = [],
154 + sampleData,
155 +}) => {
156 + const pool = siteImages || [];
157 + // Every post shares the same sample body, so resolve its images once.
158 + const postContent = replacePostContentImages(sampleData.post_content, pool);
159 + return Array.from({ length: 8 }, (_, i) => {
160 + const title =
161 + blogTitles?.[i] ||
162 + // translators: %s is a post number
163 + sprintf(__('Blog Post %s', 'extendify-local'), i + 1);
164 + const image = blogImages[i] ?? pool[i % pool.length];
165 + return {
166 + name: title,
167 + featured_image: image ? formatImageUrl(image) : null,
168 + post_content: postContent,
169 + };
170 + });
171 +};
172 +
173 +export const createBlogSampleData = async (
174 + siteStrings,
175 + siteImages,
176 + blogImages,
177 +) => {
132 178 const localizedBlogSampleData =
133 179 blogSampleData[window.extSharedData?.wpLanguage || 'en_US'] ||
134 180 blogSampleData.en_US;
135 181
@@ -135,35 +181,14 @@
135 181
136 182 const categories =
137 183 (await createWpCategories(localizedBlogSampleData.categories)) || [];
138 184 const tags = (await createWpTags(localizedBlogSampleData.tags)) || [];
139 - const formatImageUrl = (image) =>
140 - image?.includes('?q=80&w=1470') ? image : `${image}?q=80&w=1470`;
141 - const imagesArray = (siteImages || []).sort(() => Math.random() - 0.5);
142 185
143 - const replacePostContentImages = (content, images) =>
144 - (content.match(/https:\/\/images\.unsplash\.com\/[^\s"]+/g) || []).reduce(
145 - (updated, match, i) =>
146 - updated.replace(match, formatImageUrl(images[i] || match)),
147 - content,
148 - );
149 -
150 - const posts = Array.from({ length: 8 }, (_, i) => {
151 - const title =
152 - siteStrings?.aiBlogTitles?.[i] ||
153 - // translators: %s is a post number
154 - sprintf(__('Blog Post %s', 'extendify-local'), i + 1);
155 - const featuredImage = imagesArray[i % imagesArray.length]
156 - ? formatImageUrl(imagesArray[i % imagesArray.length])
157 - : null;
158 - return {
159 - name: title,
160 - featured_image: featuredImage,
161 - post_content: replacePostContentImages(
162 - localizedBlogSampleData.post_content,
163 - imagesArray,
164 - ),
165 - };
186 + const posts = buildBlogPosts({
187 + blogTitles: siteStrings?.aiBlogTitles,
188 + siteImages,
189 + blogImages,
190 + sampleData: localizedBlogSampleData,
166 191 });
167 192
168 193 for (const [index, post] of posts.entries()) {
169 194 try {
@@ -189,8 +214,13 @@
189 214 const postData = {
190 215 title: post.name,
191 216 content: post.post_content,
192 217 status: 'publish',
218 + // Space posts a day apart, newest first, so the home's date-desc loop
219 + // matches the preview order.
220 + date_gmt: new Date(Date.now() - index * MS_PER_DAY)
221 + .toISOString()
222 + .slice(0, 19),
193 223 featured_media: mediaId || null,
194 224 categories: category,
195 225 tags: tagFeaturedPost,
196 226 meta: { made_with_extendify_launch: true },