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/pages.js +31 -29 3.0.6 → trunk View file →
@@ -1,11 +1,12 @@
1 1 import { importImage, updateOption } from '@auto-launch/functions/wp';
2 +import { launchStrings } from '@auto-launch/strings';
2 3 import { PATTERNS_HOST } from '@constants';
3 4 import { reqDataBasics } from '@shared/lib/data';
4 5 import { pageNames } from '@shared/lib/pages';
5 6 import apiFetch from '@wordpress/api-fetch';
6 7 import { createBlock, parse, serialize } from '@wordpress/blocks';
7 -import { __, sprintf } from '@wordpress/i18n';
8 +import { __ } from '@wordpress/i18n';
8 9 import { setStatus } from './helpers';
9 10
10 11 // Slugs that plugins own — skip creating design-build pages for these.
11 12 export const PLUGIN_OWNED_PAGES = [
@@ -12,8 +13,10 @@
12 13 { slug: 'shop', plugin: 'woocommerce' },
13 14 { slug: 'events', plugin: 'the-events-calendar' },
14 15 ];
15 16
17 +export const isBlogPage = ({ originalSlug }) => originalSlug === 'blog';
18 +
16 19 export const getPagesToCreate = (data) => {
17 20 const { home, pages, siteProfile } = data;
18 21 const homepage = {
19 22 id: 'home',
@@ -20,17 +23,18 @@
20 23 name: pageNames.home.title,
21 24 slug: 'home',
22 25 patterns: home.patterns,
23 26 };
24 - const needsBlog = siteProfile.objective === 'blog';
25 - const blogPage = needsBlog
26 - ? {
27 - name: pageNames.blog.title,
28 - id: 'blog',
29 - patterns: [],
30 - slug: 'blog',
31 - }
32 - : null;
27 + const hasBlog = pages.some(({ slug }) => slug === 'blog');
28 + const blogPage =
29 + siteProfile.blog && !hasBlog
30 + ? {
31 + name: pageNames.blog.title,
32 + id: 'blog',
33 + patterns: [],
34 + slug: 'blog',
35 + }
36 + : null;
33 37
34 38 // Remove the page title pattern from all pages
35 39 const patternHasTitle = (pattern) =>
36 40 !pattern.patternTypes?.includes('page-title');
@@ -122,9 +126,19 @@
122 126
123 127 return serialize(parse(rawHTML).map(walk));
124 128 };
125 129
126 -export const createWpPages = async (pagesRaw, { stickyNav }) => {
130 +// navSlug: the design menu entry this section was picked for (applyDesignBuildNav).
131 +export const sectionSlug = (pattern) =>
132 + pattern.navSlug ??
133 + Object.values(pageNames).find(({ alias }) =>
134 + alias.includes(pattern.patternTypes?.[0]),
135 + )?.slug;
136 +
137 +export const createWpPages = async (
138 + pagesRaw,
139 + { skipSectionIds = false } = {},
140 +) => {
127 141 const pages = [];
128 142
129 143 for (const page of pagesRaw) {
130 144 const content = [];
@@ -129,21 +143,15 @@
129 143 for (const page of pagesRaw) {
130 144 const content = [];
131 145 const seenPatternTypes = new Set();
132 146
133 - setStatus(sprintf(__('Adding page: %s', 'extendify-local'), page.name));
147 + setStatus(launchStrings().statusAddingPage(page.name));
134 148
135 149 for (const [_, pattern] of page.patterns.entries()) {
136 150 const code = pattern.code;
137 - const patternType = pattern.patternTypes?.[0];
151 + const slug = sectionSlug(pattern);
138 152
139 - const { slug: defaultSlug } =
140 - Object.values(pageNames).find(({ alias }) =>
141 - alias.includes(patternType),
142 - ) || {};
143 - const slug = pattern.navSlug ?? defaultSlug;
144 -
145 - if (seenPatternTypes.has(slug) || !slug) {
153 + if (skipSectionIds || seenPatternTypes.has(slug) || !slug) {
146 154 content.push(code);
147 155 continue;
148 156 }
149 157
@@ -154,13 +162,9 @@
154 162 const pageData = {
155 163 title: page.name,
156 164 status: 'publish',
157 165 content: content.join(''),
158 - template: stickyNav
159 - ? 'no-title-sticky-header'
160 - : page.slug === 'home'
161 - ? 'no-title'
162 - : 'page-with-title',
166 + template: page.slug === 'home' ? 'no-title' : 'page-with-title',
163 167 meta: { made_with_extendify_launch: true },
164 168 };
165 169
166 170 let newPage;
@@ -179,9 +183,9 @@
179 183 await updateOption('show_on_front', 'page');
180 184 await updateOption('page_on_front', maybeHome.id);
181 185 }
182 186
183 - const maybeBlog = pages.find(({ originalSlug }) => originalSlug === 'blog');
187 + const maybeBlog = pages.find(isBlogPage);
184 188 if (maybeBlog) {
185 189 await updateOption('page_for_posts', maybeBlog.id);
186 190 }
187 191
@@ -238,11 +242,9 @@
238 242 try {
239 243 // Get the imprint page template
240 244 const imprintPage = await getImprintPageTemplate({ siteStyle });
241 245 // Create the page in WordPress with the fetched template
242 - const [createdImprintPage] = await createWpPages([imprintPage], {
243 - stickyNav: false,
244 - });
246 + const [createdImprintPage] = await createWpPages([imprintPage]);
245 247 return createdImprintPage;
246 248 } catch (error) {
247 249 console.error('Failed to add imprint page:', error);
248 250 return null;