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

Suggest more post formats based on block presence. #3156

Merged
merged 3 commits into from
Oct 31, 2017

Conversation

mtias
Copy link
Member

@mtias mtias commented Oct 25, 2017

Now that we have more blocks, let's expand the suggestion.

@mtias mtias added the [Feature] Document Settings Document settings experience label Oct 25, 2017
@codecov
Copy link

codecov bot commented Oct 25, 2017

Codecov Report

Merging #3156 into master will increase coverage by 1.71%.
The diff coverage is 87.5%.

Impacted file tree graph

@@            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
Impacted Files Coverage Δ
editor/selectors.js 95.08% <87.5%> (-0.18%) ⬇️
components/button/index.js 93.33% <0%> (-6.67%) ⬇️
components/popover/index.js 83.53% <0%> (-0.31%) ⬇️
components/navigable-menu/index.js 25.71% <0%> (-0.22%) ⬇️
editor/sidebar/post-format/index.js 0% <0%> (ø) ⬆️
editor/writing-flow/index.js 0% <0%> (ø) ⬆️
editor/modes/visual-editor/inserter.js 93.33% <0%> (ø) ⬆️
editor/block-toolbar/index.js 0% <0%> (ø) ⬆️
editor/modes/visual-editor/index.js 0% <0%> (ø) ⬆️
... and 30 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update aee3546...c13b6ba. Read the comment docs.

@mtias mtias force-pushed the add/more-suggested-formats branch from cbfd9a7 to 2a87316 Compare October 26, 2017 10:09
@mtias
Copy link
Member Author

mtias commented Oct 26, 2017

It might be interesting in the future to tie this with the keyword aliases. That way 3rd party blocks could opt in into the suggestion mechanism by having a matching alias (like image).

@aduth
Copy link
Member

aduth commented Oct 26, 2017

It might be interesting in the future to tie this with the keyword aliases. That way 3rd party blocks could opt in into the suggestion mechanism by having a matching alias (like image).

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
Copy link
Member

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.

Copy link
Member Author

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/

Copy link
Member Author

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.

@mtias
Copy link
Member Author

mtias commented Oct 31, 2017

Added a couple tests.

Copy link
Member

@aduth aduth left a 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.

@mtias mtias added this to the Beta 1.6 milestone Oct 31, 2017
mtias added 3 commits October 31, 2017 15:44
- Add audio block suggestions.
- Add galleries.
- Add video embeds as videos.
- Also consider pullquotes a kind of quote.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] Document Settings Document settings experience
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants