WPBuddy / largo

A WordPress framework for news websites. Finely-crafted by INN and expertly-honed and maintained by the technology team at WP Buddy.
http://largo.wpbuddy.co
GNU General Public License v2.0
170 stars 83 forks source link

largo_remove_hero does not remove duplicate heroes on Gutenberg content. #1834

Open benlk opened 5 years ago

benlk commented 5 years ago

https://github.com/INN/largo/blob/512da701664b329f2f92244bbe54880a6e146431/inc/post-templates.php#L191-L204

In situations where the first block on a post is an image block, the first paragraph of the post is not the image tag. It's a comment.

<!-- wp:image {"id":4923609,"className":"size-large wp-image-4923609"} -->
<figure class="wp-block-image size-large wp-image-4923609"><img src="https://citylimits.test/wp-content/uploads/2019/06/9351636396_89cf3d92d0_o-771x514.jpg" alt="sex work protest" class="wp-image-4923609"/><figcaption><p class="wp-media-credit"><a href="https://www.flickr.com/photos/piczilla/9351636396/in/photolist-ffnzGh-ikZTmj-csDva7-ffnA5o-csDoqd-wXnJH9-72Zn35-csDq8d-4ngpvq-csDgAh-cE31Ff-csD5ym-csDdhs-5QrDsM-csDeZm-csDnrE-bjLsQR-7hYi6X-29vuZow-csD7A7-SSHNLZ-5Ksxb2-4ViLfG-csDrR7-bku5n4-bjsjfD-bku4jc-bjLATr-bku6Qr-hc1G6T-6Vm8KP-bjLzin-bjseHF-bjLrbk-bjLvVe-bku6aM-bjsaka-hc33Hk-bkueEX-hc35hx-6VrNoo-bjLiHz-bjsdKe-92JTvN-4ZUf7d-92JN2Q-KTUb38-92JGbC-92JBYU-6VmJQK">Type 17 Productions</a></p>Sex workers rally in 2013. Some sex workers argue that policies aimed at 'ending demand' actually increase the risks they face.</figcaption></figure>
<!-- /wp:image -->

as a post content will be passed through the filter.

$p[0] is '<!-- wp:image {"id":4923609,"className":"size-large wp-image-4923609"} -->', not an image that matches the regex.

Even if we adjusted this algorithm to skip the opening comment, and to treat figcaptions like the paragraph tag, we're edging into the dangerous territory for parsing HTML with regular expressions. https://stackoverflow.com/a/1732454

benlk commented 5 years ago

If we want to fix this parser:

If we don't want to fix the parser:

benlk commented 5 years ago

Personally, I'm in favor of the deprecation technique.

By removing Largo Featured Media in favor of Gutenberg, sites will have more editorial control over how the media displays in their posts, with the same level of control over whether it displays at all. Getting rid of the featured media output would also bring Largo's existing templates closer to the "Blank Slate" template described in https://github.com/INN/largo/issues/1663