jekyll / jekyll-seo-tag

A Jekyll plugin to add metadata tags for search engines and social networks to better index and display your site's content.
https://jekyll.github.io/jekyll-seo-tag
MIT License
1.66k stars 294 forks source link

Truncate the description value to 100 words #492

Closed kemenaran closed 1 year ago

kemenaran commented 1 year ago

Currently, on post pages, the value of the description, og: description, twitter: description and application/ld-json tags represent the whole text of the post.

Which means that the text of the post is included five times in the HTML document – adding to the page weight needlessly.

This commit ensures the description string is truncated to a sane value.

y377 commented 1 year ago

@kemenaran If it can be customized according to the percentage, this should be the ultimate solution: for example, from 10% to 90% of the full text (if the description is defined in the preface), it is recommended to consider it!

kemenaran commented 1 year ago

@mattr- would you consider this improvement mergeable in the current state – or do you prefer to make it configurable?

mattr- commented 1 year ago

280 characters feels like a twitter specific limitation. Regardless of that, a blanket truncation at 280 characters doesn't take into account word or sentence endings, and it feels like we should do that before this PR is mergeable.

kemenaran commented 1 year ago

@mattr- thanks for your review! I updated the PR to:

I also added tests, and a new documentation section describing the behavior.

Does that look reasonable to you?

kemenaran commented 1 year ago

Yup, I just pushed fixes to the rubocop issues, it should be good now.

mattr- commented 1 year ago

Thanks for tackling this!

@jekyllbot: merge +minor

kemenaran commented 1 year ago

Great! Thanks for having a look into this, and for the maintenance work.

y377 commented 11 months ago

@jekyllbot @kemenaran Thank you for your great efforts. Please tell me how to update the improved code. Because the plug-in has been installed before, no matter whether you use gem install jekyll-seo-tag or gem update jekyll-seo-tag, it will not help.

mattr- commented 11 months ago

You'll need to wait on a plugin release or tell bundler to fetch the code from the git repo in order to use this new feature.