PluginProbe
Extendify / trunk
Extendify vtrunk
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 +54 -37 3.0.6 → trunk 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',
@@ -57,20 +56,15 @@
57 56 };
58 57
59 58 const getTemplateParts = () => apiFetch({ path: '/wp/v2/template-parts' });
60 59
61 -export const getHeadersAndFooters = async ({
62 - useNavFooter = false,
63 - siteProfile = {},
64 -} = {}) => {
60 +export const getHeadersAndFooters = async ({ useNavFooter = false } = {}) => {
65 61 const patterns = await getTemplateParts();
66 62 const extendablePatterns = patterns.filter(
67 63 ({ theme }) => theme === 'extendable',
68 64 );
69 - const headerSlugs =
70 - siteProfile.type === 'home services' ? homeServicesHeaders : allowedHeaders;
71 65 const headers = extendablePatterns?.filter(({ slug }) =>
72 - headerSlugs.includes(slug),
66 + allowedHeaders.includes(slug),
73 67 );
74 68
75 69 const footerNav =
76 70 useNavFooter &&
@@ -140,9 +134,48 @@
140 134
141 135 export const createCategory = (data) =>
142 136 apiFetch({ path: '/wp/v2/categories', method: 'POST', data });
143 137
144 -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 +) => {
145 178 const localizedBlogSampleData =
146 179 blogSampleData[window.extSharedData?.wpLanguage || 'en_US'] ||
147 180 blogSampleData.en_US;
148 181
@@ -148,35 +181,14 @@
148 181
149 182 const categories =
150 183 (await createWpCategories(localizedBlogSampleData.categories)) || [];
151 184 const tags = (await createWpTags(localizedBlogSampleData.tags)) || [];
152 - const formatImageUrl = (image) =>
153 - image?.includes('?q=80&w=1470') ? image : `${image}?q=80&w=1470`;
154 - const imagesArray = (siteImages || []).sort(() => Math.random() - 0.5);
155 185
156 - const replacePostContentImages = (content, images) =>
157 - (content.match(/https:\/\/images\.unsplash\.com\/[^\s"]+/g) || []).reduce(
158 - (updated, match, i) =>
159 - updated.replace(match, formatImageUrl(images[i] || match)),
160 - content,
161 - );
162 -
163 - const posts = Array.from({ length: 8 }, (_, i) => {
164 - const title =
165 - siteStrings?.aiBlogTitles?.[i] ||
166 - // translators: %s is a post number
167 - sprintf(__('Blog Post %s', 'extendify-local'), i + 1);
168 - const featuredImage = imagesArray[i % imagesArray.length]
169 - ? formatImageUrl(imagesArray[i % imagesArray.length])
170 - : null;
171 - return {
172 - name: title,
173 - featured_image: featuredImage,
174 - post_content: replacePostContentImages(
175 - localizedBlogSampleData.post_content,
176 - imagesArray,
177 - ),
178 - };
186 + const posts = buildBlogPosts({
187 + blogTitles: siteStrings?.aiBlogTitles,
188 + siteImages,
189 + blogImages,
190 + sampleData: localizedBlogSampleData,
179 191 });
180 192
181 193 for (const [index, post] of posts.entries()) {
182 194 try {
@@ -202,8 +214,13 @@
202 214 const postData = {
203 215 title: post.name,
204 216 content: post.post_content,
205 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),
206 223 featured_media: mediaId || null,
207 224 categories: category,
208 225 tags: tagFeaturedPost,
209 226 meta: { made_with_extendify_launch: true },