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

Homepage Posts block: add optional 'continue reading' link underneath excerpts #656

Merged
merged 6 commits into from
Jan 5, 2021

Conversation

laurelfulford
Copy link
Contributor

All Submissions:

Changes proposed in this Pull Request:

This PR adds an option to add a customize-able 'Read More' link for each story on a per-post basis.

Unfortunately, current behaviour in WP.com themes could complicate this. This is a comment from me from the original enhancement request:

There are a number of themes that replace the [...] at the end of automatically generated excerpts with something else by filtering excerpt_more (example). The reason the link doesn't happen with Custom Excerpts is that the [...] is not there, since it's assumed that those would end with a full stop and not need an ellipsis.

To work around this, I added a filter that should override any entry_more customization in the theme, switching it to ... when the 'Read More' link is turned on, then removing the filter so it falls back to whatever a theme might be doing for blocks that have it left off.

Closes #495

Note: I've added the 'Don't Merge' tag so some theme styles can be added for this as well (there is a bit adding an arrow already, but it could use refining); in the meantime the block uses the comment class name more-link on the link, so it should pick up styles from most WordPress themes that it's already getting links from.

How to test the changes in this Pull Request:

  1. Apply the PR and run npm run build
  2. Add a homepage posts block to the editor; in the Post Control settings section, confirm there is an option to enable a 'Read More' link that is off by default. Toggle it on and confirm a field to change the read more text appears below it, with the default text "Keep reading":

image

  1. Add 4 Homepage posts block to the editor with different configurations including:
  • A block with the excerpt on and the read more link on; change the read more text.
  • A block with the excerpt on, a custom excerpt length, and the read more link on.
  • A block with no excerpt, and the read more link on; change the read more link text.
  • A block with the excerpt on, and the read more link off.
  1. Confirm on the front end and in the editor, your settings are respected, including the different read more link text, and, when enabled, that the default [...] is replaced with ....

  2. Note: on the front-end, you can see that the .more-link already has styles in the theme, adding an arrow; that will be updated:
    image

  3. Download Varia from WordPress.com and enable it on your test site.

  4. View on the front end and confirm that Varia's custom excerpt_more filter ("Continue Reading") is being picked up on blocks that don't have the 'Read More' link set, but the ones with a 'Read More' link set should still be applying it. All of the links should be applying the arrow from Varia, since it also uses the .more-link CSS class. (Note: Varia's custom filter will not be applied in the editor, since the theme only applies it to the front-end; in that case, the blocks without the 'Read More' link enabled should still fall back to the default [...]):

image

  1. Enable the 'Load More Posts' option on the blocks, and confirm that the Read More options are being applied correctly to posts that are newly loaded, both with and without AMP enabled.
  2. On the front-end, click on the Read More links to confirm they go to the correct posts.

Other information:

  • Have you added an explanation of what your changes do and why you'd like us to include them?
  • Have you written new tests for your changes, as applicable?
  • Have you successfully ran tests with your changes locally?

Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Works great, except when using the "Load More" button I'm seeing 500 fatal errors like this:

PHP Fatal error:  Uncaught Error: Call to undefined method Newspack_Blocks::remove_excerpt_ellipsis_filter() in /Users/dkoo/Local Sites/newspack/app/public/wp-content/plugins/newspack-blocks/src/blocks/homepage-articles/class-wp-rest-newspack-articles-controller.php:103

I think we just need to update some method names in the API controller as suggested below. Otherwise, looks good!

@laurelfulford
Copy link
Contributor Author

Thanks @dkoo!

I ran into this exact issue while running though the texting steps for the PR yesterday, committed a fix in 430ffcc... and then forgot to push it up 🤦‍♀️ That update is now actually on GitHub, and not just hanging around on my local copy of the branch!

Copy link
Contributor

@dkoo dkoo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now! :shipit:

@laurelfulford laurelfulford added the Needs documentation This feature or changes will have to be documented on newspack.blog/support after release. label Dec 19, 2020
@laurelfulford laurelfulford merged commit 3c55a69 into master Jan 5, 2021
@laurelfulford laurelfulford deleted the feat/continue-reading-link branch January 5, 2021 22:38
matticbot pushed a commit that referenced this pull request Jan 12, 2021
# [1.18.0-alpha.1](v1.17.1...v1.18.0-alpha.1) (2021-01-12)

### Features

* add optional 'continue reading' link underneath excerpts ([#656](#656)) ([3c55a69](3c55a69))
* custom endpoint for homepage posts in editor ([#661](#661)) ([1f4880a](1f4880a))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.18.0-alpha.1 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

matticbot pushed a commit that referenced this pull request Jan 12, 2021
# [1.18.0](v1.17.1...v1.18.0) (2021-01-12)

### Features

* add optional 'continue reading' link underneath excerpts ([#656](#656)) ([3c55a69](3c55a69))
* custom endpoint for homepage posts in editor ([#661](#661)) ([1f4880a](1f4880a))
@matticbot
Copy link
Contributor

🎉 This PR is included in version 1.18.0 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs documentation This feature or changes will have to be documented on newspack.blog/support after release. released on @alpha released [Status] Approved
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Blog Posts Block: Add option for manual Continue Reading link
3 participants