-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
Suggest more post formats based on block presence. #3156
Conversation
Codecov Report
@@ Coverage Diff @@
## master #3156 +/- ##
==========================================
+ Coverage 31.11% 32.82% +1.71%
==========================================
Files 230 229 -1
Lines 6448 7475 +1027
Branches 1150 1465 +315
==========================================
+ Hits 2006 2454 +448
- Misses 3726 4127 +401
- Partials 716 894 +178
Continue to review full report at Codecov.
|
cbfd9a7
to
2a87316
Compare
It might be interesting in the future to tie this with the |
It's an interesting idea. Would it necessary be tied to keyword, or should we be more explicit about the relationship to post format with a separate property on the block API? |
// so we can derive a suitable post format from it. | ||
if ( blocks.length === 1 ) { | ||
name = state.editor.blocksByUid[ blocks[ 0 ] ].name; | ||
} | ||
|
||
// If there are two blocks in the content and the last one is a text blocks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the intended logic here? Should it really be restricted to posts with two blocks specifically, or is the idea if the block is entirely text except for a first non-text block, it should inherit format based on that first block?
let name;
// If there is only one block in the content of the post grab its name
// so we can derive a suitable post format from it.
if ( uids.length === 1 ) {
name = getBlock( uids[ 0 ] ).name;
} else if ( uids.length > 1 ) {
const isMostlyText = uids.slice( 1 ).every( ( uid ) => {
return getBlock( uid ).name === 'core/paragraph';
} );
if ( isMostlyText ) {
name = getBlock( uids[ 0 ] ).name;
}
}
This is non-trivial logic, so might be worth memoizing, and definitely worth testing.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The latter. If there are only two blocks, and the second one is text, the first one determines the format suggestion if it matches one of the post formats.
Example: quote + comment like https://ma.tt/2017/10/gauguin-to-olive-garden/
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If there are more than two we don't suggest anymore as we consider it a standard post.
Added a couple tests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use a squashing.
- Add audio block suggestions. - Add galleries. - Add video embeds as videos. - Also consider pullquotes a kind of quote.
87a8537
to
c13b6ba
Compare
Now that we have more blocks, let's expand the suggestion.