-
Notifications
You must be signed in to change notification settings - Fork 6
[Gutenberg] Build a base layer for Homepage #13
Conversation
…er, featured, and search block.
There were a few issues that came out while adding the base layout for the homepage, the suggested issues to continue with are:
Thinking that perhaps it would make sense to try figuring out the implementation of @ThierryA Would be great to hear your opinion. Edit: Added a workaround for the [src] issue in 472ede6. |
blocks/hero/index.js
Outdated
// @todo Confirm possible solution for replacing [src] -- add data-ampsrc instead and replace it with filters when displaying the post. | ||
const ampSrcProp = { | ||
'data-ampsrc': "'/api/places?types=(regions)&types=(cities)&input=' + fields_query_live" | ||
}; |
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.
React is allowing the rest of the amp attributes to be saved ([value]
etc.) but [src]
not. Added a workaround which uses data-ampsrc
instead and then this will later get replaced with the_content
filter when rendering the post. Does this seem reasonable?
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.
This is essentially what we're having to do in PHP as well to support these attributes. Before sending into DOMDocument
to parse, we replace all such attributes with data-
attributes and then after parsing is done we convert them back to the original bracketed-notation. See: https://github.com/Automattic/amp-wp/blob/2bcfc19c2108b9b7bdd5c2eab1532e90a2bb0882/includes/utils/class-amp-dom-utils.php#L182-L272
I think what you have is more or less what we have to live with until AMP adds support for an XHTML syntax: ampproject/amphtml#11115
The Gutenberg base layout PR should be ready for initial review. Perhaps the next Gutenberg-related issues could be:
@ThierryA Any thoughts on priorities for continuing with Travel Gutenberg blocks? Would it make sense to already start working on making the blocks configurable / dynamic before this PR gets reviewed? Or perhaps it would make sense to improve the editor style within this PR already. Thoughts? |
Missing functionality @postphotos Just in case it could be helpful for creating block-based tickets, writing out the missing functionality per block that would be required for the blocks be functional / dynamic;
Note that not all the related functionality can be directly added to the blocks (e.g. the search results page itself). |
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.
Thanks @miina, great work here.
Would it make sense to already start working on making the blocks configurable / dynamic before this PR gets reviewed
Yes all blocks should be configurable and dynamic before reviewing the PR.
I also merged the latest from develop
which includes Travis integration with WPCS and ESLint sniffers set. There are a few issues that Travis picks up in the PR which must be addressed. I would suggest to also install the pre-commit hook locally, here are the steps to follow:
git pull
to get the last commit- run
npm install
again to install ESLint and the Dev Lib - run
composer install
to install standardized packages (best to mimic Travis env) - install pre-commit hook
./node_modules/wp-dev-lib/install-pre-commit-hook.sh
Happy to answer any question you may have indeed.
Thanks,
.gitignore
Outdated
@@ -0,0 +1,3 @@ | |||
/node_modules | |||
/assets |
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.
I think we should checkout the compiled file as the blocks should be available without having to run npm commands. I added it in my last commit when merging develop
, however I did not commit the assets yet which will be added next time you push a commit once you have pull the latest.
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.
Added the assets to version control within f7ada7e.
Thank you for reviewing the PR, @ThierryA. The assets are now under version control as well and fixed some CS issues. Currently just added ignore to the On making the blocks configurable / dynamic -- perhaps this can be done block-by-block in separate issues; so far there is one block-specific github issue created (#14), started working on it separately on this branch. |
.gitignore
Outdated
@@ -1,10 +1,5 @@ | |||
<<<<<<< HEAD |
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.
Thanks for fixing this conflict @miina.
Thanks for picking that up @miina, this is fixed in my last commit (merged |
@westonruter If you happen to have time would appreciate your feedback on the PR, to see if there seems to be anything to change. This is basically the base for Gutenberg blocks that creates static blocks, the dynamic/customizable block-related PR-s are/will be based on this PR. |
d5ef7b3
to
2feb47a
Compare
7a14eec
to
d46ede6
Compare
The build failure for d46ede6 is good because it shows that ESLint is successfully running. Apparently dev-lib isn't yet accounting for config files named |
if ( -1 === propsToRemove.indexOf( prop ) ) { | ||
|
||
// Eslint is giving "There should be no spaces inside this paren." error for the line. | ||
if ( propsMapping[ prop ] ) { // eslint-disable-line |
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.
For some reason eslint is throwing There should be no spaces inside this paren. (space-in-parens)
error for this line. Without the spaces it's throwing spaces missing error. Not sure what I'm missing here, any thoughts?
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.
I've noticed that too. Seems like a bug in eslint.
…ml tags for theme-related tags.
@westonruter: Saw your comment on the allowed HTML tags:
Added a filter to allow |
includes/class-amp-travel-blocks.php
Outdated
public function filter_wp_kses_allowed_html( $allowed_tags, $context ) { | ||
if ( 'post' === $context ) { | ||
$amp_tags = array( | ||
'amp-img' => array( |
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.
This should probably be merging with $allowed_tags['img']
for good measure.
Good. I think that's all that is needed for now. We'll need to probably handle this in the AMP plugin generally. For example, when creating AMP-specific blocks in the plugin we'll also need to make sure that all AMP elements and attributes get whitelisted in Kses, similar to how you've now done here. |
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.
Looks Good, Comments About File Structure
Hi @miina,
This PR looks good, and thanks for putting the blocks logic in includes/class-amp-travel-blocks.php
.
Could you please see the comments below? These are mainly to pave the way for more classes in includes/
.
includes/class-amp-travel-blocks.php
Outdated
* AMP_Travel_Blocks constructor. | ||
*/ | ||
public function __construct() { | ||
if ( function_exists( 'gutenberg_init' ) ) { |
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.
@miina, could you please create an init()
method, and move the add_action()
and add_filter()
calls inside it?
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.
Thanks, the change looks good.
functions.php
Outdated
require_once get_template_directory() . '/includes/class-amp-travel-blocks.php'; | ||
|
||
|
||
if ( ! function_exists( 'travel_setup' ) ) : |
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.
@miina,
Thanks for putting the blocks logic in a separate class.
Could you create another file, includes/functions.php
, which has a function like:
function amp_travel_theme() {
return AMP_Travel_Theme::get_instance();
}
Then, the file that this comment is attached to could simply call amp_travel_theme()->init()
after requiring the files above. (This borrows heavily from @ThierryA's work on another project).
Then, the current logic inside if ( ! function_exists( 'travel_setup' ) ) :
could move into a new AMP_Travel_Theme
class: includes/class-amp-travel-theme.php
. That logic could be inside a method that AMP_Travel_Theme::init()
calls.
It'd be great if you could also create a method AMP_Travel_Theme::instantiate_classes()
, and move the line new AMP_Travel_Blocks();
into it.
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.
@kienstra Thanks for the comments, the file structure issues should be addressed now, let me know if there's anything else that might need changing.
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.
Thanks a lot for restructuring the files, @miina. The structure looks good. This will pave the way for more theme classes.
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.
Approved
Hi @miina,
Thanks a lot for your Gutenberg expertise here, and for your great work.
Great work here! |
Fixes #12.
What does the PR contain?
Adds the following Gutenberg editor blocks:
Some relevant notes:
index.php
file for the theme which is basically almost a copy of the HTML of the Travel static template except for the parts that are rendered by blocks;index.php
(except for a one line addition) and also the same full style is loaded to the Gutenberg editor via'enqueue_block_editor_assets'
action;Dev-related notes
package.json
;assets/js/editor-blocks.js
is generated bywebpack
(seewebpack.config.js
);npm install
, and thennpm run dev
for not having to manually rebuild the files after each JS change.Screenshot
With the current PR adding all the blocks in the correct order the page looks like this:
Problems found
[value]
). This can be fixed by either using JS for creating the elements instead of JSX OR by defining an array of the needed attribute and then adding it to JSX. For example:The only property that doesn't seem to work like this is
[src]
--this is currently missing from the Hero block implementation; (Workaround added in 472ede6)(Fixed within 97bbaf2)amp-mustache
template's content is currently missing from the Hero block implementation -- not clear yet how exactly to implement it (quick search showed that there are custom-created solutions out there);TODO / Next steps
(Fixed within 97bbaf2) + Figure out how to fix theamp-mustache
implementation[src]
not being rendered (Workaround added in 472ede6);