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 +30 -24 3.1.3 → 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) => {
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
@@ -175,9 +183,9 @@
175 183 await updateOption('show_on_front', 'page');
176 184 await updateOption('page_on_front', maybeHome.id);
177 185 }
178 186
179 - const maybeBlog = pages.find(({ originalSlug }) => originalSlug === 'blog');
187 + const maybeBlog = pages.find(isBlogPage);
180 188 if (maybeBlog) {
181 189 await updateOption('page_for_posts', maybeBlog.id);
182 190 }
183 191
@@ -234,11 +242,9 @@
234 242 try {
235 243 // Get the imprint page template
236 244 const imprintPage = await getImprintPageTemplate({ siteStyle });
237 245 // Create the page in WordPress with the fetched template
238 - const [createdImprintPage] = await createWpPages([imprintPage], {
239 - stickyNav: false,
240 - });
246 + const [createdImprintPage] = await createWpPages([imprintPage]);
241 247 return createdImprintPage;
242 248 } catch (error) {
243 249 console.error('Failed to add imprint page:', error);
244 250 return null;