PluginProbe
Extendify / 3.1.3
Extendify v3.1.3
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-variation.js

get-variation.js in Extendify 3.1.3, at src/AutoLaunch/fetchers/get-variation.js

52 lines 1.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { apiFetchWithTimeout } from '@auto-launch/functions/helpers';
2 import { deepMerge } from '@shared/lib/utils';
3
4 // TODO: add zod types - this was copy/pasted from legacy launch
5 export const getThemeVariation = async ({ slug, fonts }, opts) => {
6 const { fallback = false } = opts || {};
7 const rawVariations = await apiFetchWithTimeout({
8 path: 'wp/v2/global-styles/themes/extendable/variations',
9 });
10
11 const variations = rawVariations.filter(
12 (v) =>
13 (v.settings?.color || v.styles?.color) &&
14 (v.settings?.typography || v.styles?.typography),
15 );
16
17 let variation = variations.find((v) => {
18 const matchSlug =
19 v.slug || v.title.toLowerCase().trim().replace(/\s+/g, '-');
20 return matchSlug === slug;
21 });
22
23 // Fallback to random variation if slug doesn't match
24 if (!variation && fallback) {
25 variation = variations.sort(() => Math.random() - 0.5)[0];
26 }
27
28 if (!fonts) return variation;
29
30 return deepMerge(variation, {
31 styles: {
32 elements: {
33 heading: {
34 typography: {
35 fontFamily: `var(--wp--preset--font-family--${fonts.heading.slug})`,
36 },
37 },
38 },
39 typography: {
40 fontFamily: `var(--wp--preset--font-family--${fonts.body.slug})`,
41 },
42 },
43 settings: {
44 typography: {
45 fontFamilies: {
46 custom: [fonts.heading, fonts.body].filter((font) => !!font.host),
47 },
48 },
49 },
50 });
51 };
52