Skip to content

Create content meta tags for Shelf, Book, Chapter, and Page - #2393

Merged
ssddanbrown merged 5 commits into
BookStackApp:masterfrom
james-geiger:create-content-meta-tags
Jun 23, 2021
Merged

ssddanbrown merged 5 commits into
BookStackApp:masterfrom
james-geiger:create-content-meta-tags

Conversation

@james-geiger

@james-geiger james-geiger commented Dec 3, 2020

Copy link
Copy Markdown
Contributor

Draft PR to implement #2348.

To Do:

  • Page
  • Chapter
  • Book
  • Shelf
  • Default

@james-geiger

Copy link
Copy Markdown
Contributor Author

This PR implements the feature request in #2348 for media embeds that adhere to Open Graph specifications. Most sites that support Open Graph require a title, URL, description, and image.

A new method on the Page model has been created to return either the first image in the HTML body of the page or the book cover to which the page belongs.

The default for each image relies on the book default image, which returns as base64. I'm not sure how well this will be supported across different sites, so I welcome additional feedback.

phpunit tests are failing, so might need some additional guidance. Some make sense, i.e test_iframe_js_and_base64_urls_are_removed() but not others.

@james-geiger
james-geiger marked this pull request as ready for review December 22, 2020 05:33

@Abijeet Abijeet left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thank you for your contribution. Please see my comments.

Comment thread app/Entities/Models/Page.php Outdated

try {
$cover = $images->length > 0 ? $images[0]->getAttribute('src') : $this->book->getBookCover();
} catch (Exception $err) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We should either add a use \Exception; statement at the top or put \Exception here.

@james-geiger james-geiger Feb 9, 2021

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Abijeet See changes in 48587d2 and let me know your thoughts.

Comment thread app/Entities/Models/Page.php Outdated

public function getCoverImage(): string
{
$dom = new \DomDocument();

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I would put the logic to fetch the first page image in PageContent class, if that returns null, we can return the book cover.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@Abijeet See changes in 48587d2 and let me know your thoughts.

Comment thread resources/views/chapters/show.blade.php Outdated
Comment thread resources/views/pages/show.blade.php Outdated
Comment thread resources/views/base.blade.php Outdated
@Abijeet

Abijeet commented Jan 24, 2021

Copy link
Copy Markdown
Member

I think if we replace HTML with text (as mentioned here: #2393 (comment)) , we can fix the failing tests.

Updated to use Str::length for entity descriptions.
Moved function to get first image in page to PageContent class.
@james-geiger

Copy link
Copy Markdown
Contributor Author

Unit tests continue to fail even after changing code to utilize text property of pages... Not sure if it has to do with this branch.

@james-geiger
james-geiger requested a review from Abijeet February 9, 2021 07:29
@ssddanbrown ssddanbrown added this to the Next Feature Release milestone Jun 23, 2021
ssddanbrown added a commit that referenced this pull request Jun 23, 2021
For review of meta tag additions as per PR #2393.
This commit removes any image guesswork and only uses images that have
been set by the author for the specific content.
This also adds tests to cover the expected OG tags.
@ssddanbrown
ssddanbrown merged commit 58fa767 into BookStackApp:master Jun 23, 2021
@ssddanbrown

Copy link
Copy Markdown
Member

Thanks for this @james-geiger.

I've now merged and followed this up with 265f5db with some tweaks and testing.

I've scaled back the implementation a bit and removed an logic that guesses images, uses default backup options or uses images of related content. I'd prefer to keep this logic minimal and specific to content that has been specifically chose by the user. Would prefer omission of content rather than any potential confusion. Hope that's understandable.

Will be part of the next feature release.

@james-geiger

Copy link
Copy Markdown
Contributor Author

@ssddanbrown Absolutely understand the scale back. I think it's worth noting that, because different sites implement this spec differently, many require an image to be "valid" and won't display without an image. This is prevalent on the "social" sites, could be different on others.

I mention this not to suggest that a default be enforced, but so that users can be aware.

@james-geiger
james-geiger deleted the create-content-meta-tags branch June 24, 2021 20:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Development

Successfully merging this pull request may close these issues.

3 participants