From 1198ca6b8c98781431feefd7c2c0e894a9926b48 Mon Sep 17 00:00:00 2001 From: Pierre de La Morinerie Date: Mon, 30 Oct 2023 22:58:51 +0100 Subject: [PATCH] Use Front Matter defaults for seo_description_max_words --- docs/advanced-usage.md | 17 ++++++++++++++--- lib/jekyll-seo-tag/drop.rb | 2 +- spec/jekyll_seo_tag_integration_spec.rb | 16 ---------------- 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/docs/advanced-usage.md b/docs/advanced-usage.md index 0a5ad70..f6991bc 100644 --- a/docs/advanced-usage.md +++ b/docs/advanced-usage.md @@ -82,14 +82,25 @@ You can set it the same way as the other author properties. For example, you can ### Customizing description length -By default the description is limited to the first 50 words of the full content. +By default, the description is limited to the first 100 words of the full content. -You can adjust this limit either at the page level or at the site level, by using the `seo_description_max_words` page property: +You can adjust this limit at the page level, by using the `seo_description_max_words` page property: ```yml - seo_description_max_words: 100 + seo_description_max_words: 200 ``` +You can also set a default site-wide value for all pages using [Front Matter defaults](https://jekyllrb.com/docs/configuration/front-matter-defaults/) in your `_config.yml` file: + +```yml +defaults: + - scope: + path: "" + values: + seo_description_max_words: 200 +``` + + ### Customizing JSON-LD output The following options can be set for any particular page. While the default options are meant to serve most users in the most common circumstances, there may be situations where more precise control is necessary. diff --git a/lib/jekyll-seo-tag/drop.rb b/lib/jekyll-seo-tag/drop.rb index 525e946..9d4a9f6 100644 --- a/lib/jekyll-seo-tag/drop.rb +++ b/lib/jekyll-seo-tag/drop.rb @@ -177,7 +177,7 @@ module Jekyll end def description_max_words - @description_max_words ||= page["seo_description_max_words"] || site["seo_description_max_words"] || 50 + @description_max_words ||= page["seo_description_max_words"] || 100 end private diff --git a/spec/jekyll_seo_tag_integration_spec.rb b/spec/jekyll_seo_tag_integration_spec.rb index 2117c51..58a9af1 100755 --- a/spec/jekyll_seo_tag_integration_spec.rb +++ b/spec/jekyll_seo_tag_integration_spec.rb @@ -352,23 +352,7 @@ RSpec.describe Jekyll::SeoTag do end context "description" do - context "with site.seo_description_max_words" do - let(:site) { make_site("url" => "http://example.invalid", "seo_description_max_words" => 6) } - let(:meta) do - { - "title" => "post", - "description" => "For a long time, I went to bed early", - "image" => "/img.png" - } - end - - it "truncates the description" do - expect(json_data["description"]).to eql("For a long time, I went…") - end - end - context "with page.seo_description_max_words" do - let(:site) { make_site("url" => "http://example.invalid", "seo_description_max_words" => 10) } let(:meta) do { "title" => "post",