Skip to content

Commit

Permalink
Use Front Matter defaults for seo_description_max_words
Browse files Browse the repository at this point in the history
  • Loading branch information
kemenaran committed Oct 31, 2023
1 parent f728f69 commit 1198ca6
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 20 deletions.
17 changes: 14 additions & 3 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion lib/jekyll-seo-tag/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ def canonical_url
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
Expand Down
16 changes: 0 additions & 16 deletions spec/jekyll_seo_tag_integration_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -352,23 +352,7 @@
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",
Expand Down

0 comments on commit 1198ca6

Please sign in to comment.