At Jetpack we recently created a new Gutenberg block which displays “Related Posts”. This block is similar in content to the “Latest Posts” block in WordPress.org; it’s just a list of posts. The difference is the way the posts are displayed:
There are plans afoot to update the “Latest Posts” block, so that it contains an image and a post summary (see image below).
As these two blocks grow they seem to be converging on similar layouts, but with different content.
There are similar overlaps with other blocks. For example the layout of the WordPress.org gallery block could also be used to display a list of posts, as could the recently launched Tiled Gallery block. Evidently there are many layout possibilities for a list of posts!
As the number of Gutenberg blocks grows these overlaps become more obvious. As we start to build pages with Gutenberg it starts to become apparent that this is going to get very messy very quickly.
Essentially blocks have a content and a presentation element. Taking the example we began with, we can see overlap between many different types of content:
Lists of content
One type of content is a list of text, images and links. These come in many different forms, but they share the same structure:
- Latest posts
- List of posts in a category
- List of post in a tag
- Archive of posts by month/year etc
- List of categories/tags
- List featured posts
- List of images
- List of authors
- List of [custom post type]
Similarly, all of the above types of content could be displayed in any of the following ways:
Here are some examples of the different types of layout that this content could use:
The challenge is that each of these different types content can be displayed in each of these different layouts. If we wanted to create blocks for each of these combinations we’d end up with over a hundred different blocks. On the other hand we could build one single block which was so complex that it could display all these combinations within one block. Neither of these would be sensible solutions.
Can we use Block Style Variations?
Separating Content and Presentation
One solution to this problem could be to separate content from presentation in our blocks. What if we were able to define semantics for the content in our blocks, which could be interpreted by different layouts? This would mean users would first think about the content they wanted to show, and then all display options would be open to them.
A Shared Data Structure
The overlap between these blocks occurs because they all share the same data structure (an array of text, image and link). It would be possible to define a standard data structure that blocks can use. When blocks share a data structure, then it should be possible for them to share common layouts. This would mean a photo gallery display could be reused to display a list of posts, or a block that displays a list of recent posts could be reused to show a list of authors.
How Could this work?
“Block Transformations” are an existing mechanism which converts one block into another. At present every transformation has to be coded separately.
Could we re-imagine the way that transformations work, so that if blocks share a common data-structure, they can easily be transformed into each other, without writing custom transformation code?
Similarly, could we make changes to the way “Block Style Variations” work, so that they can apply a layout to our structured data?
What do you think? Is this a problem? Are there other solutions I haven’t considered? Leave a comment!