Skip to content

Commit 0dd07ff

Browse files
Merge pull request #55 from alleyinteractive/fix/redo-ci
Redo CI fixes to blocks.php
2 parents 83cfdc7 + 91c6139 commit 0dd07ff

1 file changed

Lines changed: 23 additions & 17 deletions

File tree

‎inc/blocks.php‎

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
* Enqueue stylesheets for blocks. Each stylesheet will be enqueued on-render.
1818
*
1919
* @see https://developer.wordpress.org/reference/functions/wp_enqueue_block_style/
20-
* @return void
2120
*/
2221
function enqueue_block_styles(): void {
2322
$folder_path = get_entry_dir_path( 'block-styles', true );
@@ -50,35 +49,42 @@ function enqueue_block_styles(): void {
5049
return;
5150
}
5251

53-
$css_files = array_filter(
52+
$block_directories = array_filter(
5453
$folder_contents,
55-
fn ( $item ): bool => pathinfo( (string) $item, PATHINFO_EXTENSION ) === 'css'
54+
fn ( string $item ): bool => is_dir( $folder . '/' . $item ) && ! in_array( $item, [ '.', '..' ], true )
5655
);
5756

58-
// Create entry details.
59-
foreach ( $css_files as $css_file ) {
60-
$block_name = preg_replace( '/\.css$/', '', $css_file );
61-
$block_entries[] = [
62-
'block_name' => $block_name,
63-
'block_namespace' => $dir . '/' . $block_name,
64-
'file_name' => $css_file,
65-
'file_path' => $folder . '/',
66-
'handle' => get_template() . '-' . $dir . '-' . $block_name,
67-
];
57+
// Create entry details for each block directory.
58+
foreach ( $block_directories as $block_dir ) {
59+
$block_folder = $folder . '/' . $block_dir;
60+
$index_css_path = $block_folder . '/index.css';
61+
62+
// Check if index.css exists in the block directory.
63+
if ( file_exists( $index_css_path ) ) {
64+
$block_entries[] = [
65+
'block_name' => $block_dir,
66+
'block_namespace' => $dir . '/' . $block_dir,
67+
'file_name' => 'index.css',
68+
'file_path' => $block_folder,
69+
'handle' => get_template() . '-' . $dir . '-' . $block_dir,
70+
];
71+
}
6872
}
6973
}
7074

7175
foreach ( $block_entries as $block ) {
76+
$entry_dir = 'block-styles/' . $block['block_namespace'];
77+
7278
wp_enqueue_block_style(
7379
$block['block_namespace'],
7480
[
7581
'handle' => $block['handle'] . '-styles', // Ex: `create-wordpress-theme-core-paragraph-styles`.
76-
'src' => get_template_directory_uri() . '/build/block-styles/' . $block['block_namespace'] . '.css',
77-
'deps' => get_asset_dependency_array( $block['block_namespace'] ),
78-
'ver' => get_asset_version( $block['block_namespace'] ),
82+
'src' => get_template_directory_uri() . '/build/' . trailingslashit( $entry_dir ) . $block['file_name'],
83+
'deps' => get_asset_dependency_array( $entry_dir ),
84+
'ver' => get_asset_version( $entry_dir ),
7985

8086
// Adding "path" allows inlining of block styles on the frontend when possible.
81-
'path' => $block['file_path'] . $block['file_name'],
87+
'path' => $block['file_path'] . '/' . $block['file_name'],
8288
]
8389
);
8490
}

0 commit comments

Comments
 (0)