File tree Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Expand file tree Collapse file tree 3 files changed +54
-1
lines changed Original file line number Diff line number Diff line change @@ -189,3 +189,24 @@ seo_paginator_message: "%<current>s / %<total>s | "
189189
190190While the value can be any string text, we recommend using a Ruby string-template containing the variables `current` and `total`
191191similar to the example above, to incorporate the current page-number and total number of paginated pages in the title.
192+
193+ # ## Adding a page title category
194+
195+ You can optionally add a page category to its title.
196+ This is useful for indicating to the users that some pages are logically grouped or are of a specific kind.
197+
198+ For example page front matter including :
199+
200+ ` ` ` yml
201+ title: "my page"
202+ title_category: "category"
203+ ` ` `
204+
205+ And `_config.yml` including :
206+
207+ ` ` ` yml
208+ title: "my site"
209+ ` ` `
210+
211+ Will generate `my page | category | my site` as the page's main `<title>` tag
212+ and `my page | category` as all other page's title declarations like `og:title`.
Original file line number Diff line number Diff line change @@ -47,7 +47,15 @@ def site_description
4747
4848 # Page title without site title or description appended
4949 def page_title
50- @page_title ||= format_string ( page [ "title" ] ) || site_title
50+ return @page_title if defined? ( @page_title )
51+
52+ title = format_string ( page [ "title" ] )
53+ title_category = format_string ( page [ "title_category" ] )
54+ @page_title = if title && title_category && title != title_category
55+ title + TITLE_SEPARATOR + title_category
56+ else
57+ title || title_category || site_title
58+ end
5159 end
5260
5361 def site_tagline_or_description
Original file line number Diff line number Diff line change 7373 end
7474 end
7575
76+ context "with a page title, page title category and site title" do
77+ let ( :page ) { make_page ( "title" => "page title" , "title_category" => "page title category" ) }
78+
79+ it "builds the title" do
80+ expect ( subject . title ) . to eql ( "page title | page title category | site title" )
81+ end
82+ end
83+
84+ context "with a page title category and site title" do
85+ let ( :page ) { make_page ( "title_category" => "page title category" ) }
86+
87+ it "builds the title" do
88+ expect ( subject . title ) . to eql ( "page title category | site title" )
89+ end
90+ end
91+
92+ context "with a page title, identical page title category and site title" do
93+ let ( :page ) { make_page ( "title" => "page title" , "title_category" => "page title" ) }
94+
95+ it "builds the title" do
96+ expect ( subject . title ) . to eql ( "page title | site title" )
97+ end
98+ end
99+
76100 context "with a site description but no page title" do
77101 let ( :page ) { make_page }
78102 let ( :config ) do
You can’t perform that action at this time.
0 commit comments