Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions docs/advanced-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,3 +189,24 @@ seo_paginator_message: "%<current>s / %<total>s | "

While the value can be any string text, we recommend using a Ruby string-template containing the variables `current` and `total`
similar to the example above, to incorporate the current page-number and total number of paginated pages in the title.

### Adding a page title category

You can optionally add a page category to its title.
This is useful for indicating to the users that some pages are logically grouped or are of a specific kind.

For example page front matter including:

```yml
title: "my page"
title_category: "category"
```

And `_config.yml` including:

```yml
title: "my site"
```

Will generate `my page | category | my site` as the page's main `<title>` tag
and `my page | category` as all other page's title declarations like `og:title`.
10 changes: 9 additions & 1 deletion lib/jekyll-seo-tag/drop.rb
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,15 @@ def site_description

# Page title without site title or description appended
def page_title
@page_title ||= format_string(page["title"]) || site_title
return @page_title if defined?(@page_title)

title = format_string(page["title"])
title_category = format_string(page["title_category"])
@page_title = if title && title_category && title != title_category
title + TITLE_SEPARATOR + title_category
else
title || title_category || site_title
end
end

def site_tagline_or_description
Expand Down
24 changes: 24 additions & 0 deletions spec/jekyll_seo_tag/drop_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,30 @@
end
end

context "with a page title, page title category and site title" do
let(:page) { make_page("title" => "page title", "title_category" => "page title category") }

it "builds the title" do
expect(subject.title).to eql("page title | page title category | site title")
end
end

context "with a page title category and site title" do
let(:page) { make_page("title_category" => "page title category") }

it "builds the title" do
expect(subject.title).to eql("page title category | site title")
end
end

context "with a page title, identical page title category and site title" do
let(:page) { make_page("title" => "page title", "title_category" => "page title") }

it "builds the title" do
expect(subject.title).to eql("page title | site title")
end
end

context "with a site description but no page title" do
let(:page) { make_page }
let(:config) do
Expand Down
Loading