Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add logic for block style entry points #229

Merged

Conversation

dmtrmrv
Copy link
Contributor

@dmtrmrv dmtrmrv commented May 20, 2024

This PR introduces the enqueue_block_specific_styles() function in the blocks.php file. This function is designed to enqueue styles that are specific to a block.

The function operates by first retrieving all the CSS files in the 'blocks/autoenqueue' directory. For each stylesheet, it determines the block type by removing the directory path and '.css' from the stylesheet path.

The function then attempts to get the asset file for the block type. If the asset file doesn't exist, it creates a new one with the version set to the file modification time of the stylesheet and no dependencies.

Finally, the function enqueues the block style using the block type, the URL to the stylesheet, the path to the stylesheet, the version from the asset file, and the dependencies from the asset file.

This is required for 10up/10up-toolkit#339

How To Test

Once 10up/10up-toolkit#390 is merged and released, the /dist/blocks/ directory will contain a new folder: /autoenqueue/. I was able to test this by generating block styles via the 10up-toolkit repository and then copying the /autoenqueue/ folder into the scaffold.

Credits

Props @fabiankaegy, @dmtrmrv, @Antonio-Laguna

Checklist:

  • I agree to follow this project's Code of Conduct.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests pass.

@fabiankaegy
Copy link
Member

Marking this as a draft till the toolkit PR has been merged & released :)

@fabiankaegy fabiankaegy marked this pull request as draft May 23, 2024 13:31
@fabiankaegy fabiankaegy self-requested a review May 23, 2024 13:31
themes/10up-theme/includes/blocks.php Outdated Show resolved Hide resolved
themes/10up-theme/includes/blocks.php Outdated Show resolved Hide resolved
@fabiankaegy
Copy link
Member

This PR has been updated and tested 👍 Once toolkit 6.3 gets officially released we can merge this in 👍

@fabiankaegy fabiankaegy merged commit f9f67bc into trunk Sep 26, 2024
2 checks passed
@fabiankaegy fabiankaegy deleted the feature/339-filename-based-entrypoint-for-block-specific-CSS branch September 26, 2024 09:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants