soinproduction-gutenberg 0.1.7 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -9,6 +9,7 @@ import breakpoints from './breakpoints.cjs';
9
9
  import remDimensions from './rem-css.cjs';
10
10
  import { scopeEditorSelector } from './editor-css.mjs';
11
11
  import { syncSections } from './sync-sections.mjs';
12
+ import {publishSectionPreviews} from './section-previews.mjs';
12
13
  import {syncBlocks} from './sync-blocks.mjs';
13
14
  import * as react from 'react';
14
15
  import * as reactDom from 'react-dom';
@@ -127,16 +128,8 @@ for (const group of ['sections', 'elements', 'layout']) {
127
128
 
128
129
  if(connections.modules.includes('booking'))await import('./build-booking.mjs');
129
130
 
130
- // Kit sections keep their authored raster preview beside section.tsx.
131
- for (const entry of fs.readdirSync('src/sections', { withFileTypes: true })) {
132
- if (!entry.isDirectory()) continue;
133
- for (const extension of ['webp', 'png', 'jpg', 'jpeg', 'svg']) {
134
- const source = `src/sections/${entry.name}/preview.${extension}`;
135
- if (!fs.existsSync(source)) continue;
136
- fs.mkdirSync(output + '/previews/sections', { recursive: true });
137
- fs.copyFileSync(source, `${output}/previews/sections/${entry.name}.${extension}`);
138
- }
139
- }
131
+ // Publish each section preview under the stable metadata slug and its legacy folder alias.
132
+ publishSectionPreviews(process.cwd(),path.resolve(output));
140
133
 
141
134
  // Editor-only CSS uses the same named media queries as authored content.
142
135
  const editorCssPath=output+'/editor.css';
@@ -0,0 +1,23 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ /** Publish the metadata slug used by section(), retaining folder URLs as compatibility aliases. */
5
+ export function publishSectionPreviews(root, output) {
6
+ const directory=path.join(root,'src/sections');if(!fs.existsSync(directory))return [];
7
+ const published=[];
8
+ for(const entry of fs.readdirSync(directory,{withFileTypes:true})){
9
+ if(!entry.isDirectory()||!entry.name.startsWith('section-'))continue;
10
+ const folder=path.join(directory,entry.name),metaFile=path.join(folder,'section.json');
11
+ const meta=fs.existsSync(metaFile)?JSON.parse(fs.readFileSync(metaFile,'utf8')):{};
12
+ const slug=meta.slug??entry.name;
13
+ if(!/^[a-z0-9][a-z0-9-]*$/.test(slug))throw new Error('Invalid section preview slug: '+slug);
14
+ for(const extension of ['webp','png','jpg','jpeg','svg']){
15
+ const source=path.join(folder,'preview.'+extension);if(!fs.existsSync(source))continue;
16
+ const target=path.join(output,'previews/sections');fs.mkdirSync(target,{recursive:true});
17
+ for(const name of new Set([slug,entry.name])){
18
+ const file=path.join(target,name+'.'+extension);fs.copyFileSync(source,file);published.push(file);
19
+ }
20
+ }
21
+ }
22
+ return published;
23
+ }
@@ -31,7 +31,7 @@
31
31
  'formsEndpoint' => rest_url( 'site/v1/forms/' )
32
32
  ];
33
33
 
34
- if (section_style_manifest()) $site['runtime']['sectionStyleBase'] = get_template_directory_uri() . '/build/wordpress/assets.php/sections/';
34
+ if (section_style_manifest()) $site['runtime']['sectionStyleBase'] = get_template_directory_uri() . '/build/wordpress/sections/';
35
35
  return $site;
36
36
  }
37
37
 
@@ -45,6 +45,6 @@ function enqueue_section_styles(): void {
45
45
  $file = $asset['file'] ?? '';
46
46
  if (!preg_match('/^[a-z0-9-]+\.css$/D', $file)) continue;
47
47
  $path = get_template_directory() . '/build/wordpress/sections/' . $file;
48
- if (is_readable($path)) wp_enqueue_style('site-section-' . substr(hash('sha256', $name), 0, 12), get_template_directory_uri() . '/build/wordpress/assets.php/sections/' . $file, [], null);
48
+ if (is_readable($path)) wp_enqueue_style('site-section-' . substr(hash('sha256', $name), 0, 12), get_template_directory_uri() . '/build/wordpress/sections/' . $file, [], null);
49
49
  }
50
50
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "soinproduction-gutenberg",
3
- "version": "0.1.7",
3
+ "version": "0.1.9",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -9,6 +9,7 @@ import breakpoints from './breakpoints.cjs';
9
9
  import remDimensions from './rem-css.cjs';
10
10
  import { scopeEditorSelector } from './editor-css.mjs';
11
11
  import { syncSections } from './sync-sections.mjs';
12
+ import {publishSectionPreviews} from './section-previews.mjs';
12
13
  import {syncBlocks} from './sync-blocks.mjs';
13
14
  import * as react from 'react';
14
15
  import * as reactDom from 'react-dom';
@@ -127,16 +128,8 @@ for (const group of ['sections', 'elements', 'layout']) {
127
128
 
128
129
  if(connections.modules.includes('booking'))await import('./build-booking.mjs');
129
130
 
130
- // Kit sections keep their authored raster preview beside section.tsx.
131
- for (const entry of fs.readdirSync('src/sections', { withFileTypes: true })) {
132
- if (!entry.isDirectory()) continue;
133
- for (const extension of ['webp', 'png', 'jpg', 'jpeg', 'svg']) {
134
- const source = `src/sections/${entry.name}/preview.${extension}`;
135
- if (!fs.existsSync(source)) continue;
136
- fs.mkdirSync(output + '/previews/sections', { recursive: true });
137
- fs.copyFileSync(source, `${output}/previews/sections/${entry.name}.${extension}`);
138
- }
139
- }
131
+ // Publish each section preview under the stable metadata slug and its legacy folder alias.
132
+ publishSectionPreviews(process.cwd(),path.resolve(output));
140
133
 
141
134
  // Editor-only CSS uses the same named media queries as authored content.
142
135
  const editorCssPath=output+'/editor.css';
@@ -0,0 +1,23 @@
1
+ import fs from 'node:fs';
2
+ import path from 'node:path';
3
+
4
+ /** Publish the metadata slug used by section(), retaining folder URLs as compatibility aliases. */
5
+ export function publishSectionPreviews(root, output) {
6
+ const directory=path.join(root,'src/sections');if(!fs.existsSync(directory))return [];
7
+ const published=[];
8
+ for(const entry of fs.readdirSync(directory,{withFileTypes:true})){
9
+ if(!entry.isDirectory()||!entry.name.startsWith('section-'))continue;
10
+ const folder=path.join(directory,entry.name),metaFile=path.join(folder,'section.json');
11
+ const meta=fs.existsSync(metaFile)?JSON.parse(fs.readFileSync(metaFile,'utf8')):{};
12
+ const slug=meta.slug??entry.name;
13
+ if(!/^[a-z0-9][a-z0-9-]*$/.test(slug))throw new Error('Invalid section preview slug: '+slug);
14
+ for(const extension of ['webp','png','jpg','jpeg','svg']){
15
+ const source=path.join(folder,'preview.'+extension);if(!fs.existsSync(source))continue;
16
+ const target=path.join(output,'previews/sections');fs.mkdirSync(target,{recursive:true});
17
+ for(const name of new Set([slug,entry.name])){
18
+ const file=path.join(target,name+'.'+extension);fs.copyFileSync(source,file);published.push(file);
19
+ }
20
+ }
21
+ }
22
+ return published;
23
+ }
@@ -31,7 +31,7 @@
31
31
  'formsEndpoint' => rest_url( 'site/v1/forms/' )
32
32
  ];
33
33
 
34
- if (section_style_manifest()) $site['runtime']['sectionStyleBase'] = get_template_directory_uri() . '/build/wordpress/assets.php/sections/';
34
+ if (section_style_manifest()) $site['runtime']['sectionStyleBase'] = get_template_directory_uri() . '/build/wordpress/sections/';
35
35
  return $site;
36
36
  }
37
37
 
@@ -45,6 +45,6 @@ function enqueue_section_styles(): void {
45
45
  $file = $asset['file'] ?? '';
46
46
  if (!preg_match('/^[a-z0-9-]+\.css$/D', $file)) continue;
47
47
  $path = get_template_directory() . '/build/wordpress/sections/' . $file;
48
- if (is_readable($path)) wp_enqueue_style('site-section-' . substr(hash('sha256', $name), 0, 12), get_template_directory_uri() . '/build/wordpress/assets.php/sections/' . $file, [], null);
48
+ if (is_readable($path)) wp_enqueue_style('site-section-' . substr(hash('sha256', $name), 0, 12), get_template_directory_uri() . '/build/wordpress/sections/' . $file, [], null);
49
49
  }
50
50
  }