Use Front Matter defaults for seo_description_max_words

This commit is contained in:
Pierre de La Morinerie 2023-10-30 22:58:51 +01:00
parent f728f6968d
commit 1198ca6b8c
3 changed files with 15 additions and 20 deletions

View File

@ -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.

View File

@ -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

View File

@ -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",