-
Notifications
You must be signed in to change notification settings - Fork 2k
/
Copy pathavailable-designs.ts
52 lines (45 loc) · 1.61 KB
/
available-designs.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
/**
* External dependencies
*/
import { addQueryArgs } from '@wordpress/url';
/**
* Internal dependencies
*/
import { isEnabled } from '../../config';
import type { Design } from './stores/onboard/types';
const availableDesignsConfig = require( './available-designs-config.json' );
interface AvailableDesigns {
featured: Design[];
}
const availableDesigns: Readonly< AvailableDesigns > = availableDesignsConfig;
export const getDesignImageUrl = ( design: Design ) => {
// We temporarily show pre-generated screenshots until we can generate tall versions dynamically using mshots.
// See `bin/generate-gutenboarding-design-thumbnails.js` for generating screenshots.
// https://github.com/Automattic/mShots/issues/16
// https://github.com/Automattic/wp-calypso/issues/40564
if ( ! isEnabled( 'gutenboarding/mshot-preview' ) ) {
return `/calypso/page-templates/design-screenshots/${ design.slug }_${ design.template }_${ design.theme }.jpg`;
}
const mshotsUrl = 'https://s.wordpress.com/mshots/v1/';
const previewUrl = addQueryArgs( design.src, {
font_headings: design.fonts.headings,
font_base: design.fonts.base,
} );
return mshotsUrl + encodeURIComponent( previewUrl );
};
/**
* Asynchronously load available design images
*/
export function prefetchDesignThumbs() {
if ( typeof window !== 'undefined' ) {
availableDesigns.featured.forEach( ( design: Design ) => {
const href = getDesignImageUrl( design );
const link = document.createElement( 'link' );
link.rel = 'prefetch';
link.as = 'image';
link.href = href;
document.head.appendChild( link );
} );
}
}
export default availableDesigns;