File tree 3 files changed +43
-5
lines changed
3 files changed +43
-5
lines changed Original file line number Diff line number Diff line change @@ -132,6 +132,7 @@ def subdoc_attrs(doc, section)
132
132
attrs [ 'subdoc' ] = true # Mark the subdoc so we don't try and chunk it
133
133
attrs [ 'noheader' ] = true
134
134
attrs [ 'title-separator' ] = ''
135
+ attrs [ 'canonical-url' ] = section . attributes [ 'canonical-url' ]
135
136
attrs . merge! find_related ( section )
136
137
attrs
137
138
end
Original file line number Diff line number Diff line change @@ -24,17 +24,22 @@ def extra_chunker_head
24
24
link_rel ( 'up' , attributes [ 'up_section' ] ) ,
25
25
link_rel ( 'prev' , attributes [ 'prev_section' ] ) ,
26
26
link_rel ( 'next' , attributes [ 'next_section' ] ) ,
27
+ link_rel ( 'canonical' , attributes [ 'canonical-url' ] )
27
28
] . compact . join "\n "
28
29
end
29
30
30
31
def link_rel ( rel , related )
31
32
return unless related
32
33
33
- extra = related . context == :document ? related . attr ( 'title-extra' ) : ''
34
- title = "#{ strip_tags ( link_text ( related ) ) } #{ extra } "
35
- # We're in an attribute so escape quotes too!
36
- title = title . gsub '"' , '"'
37
- %(<link rel="#{ rel } " #{ link_href related } title="#{ title } "/>)
34
+ if related . is_a? ( String )
35
+ %(<link rel="#{ rel } " href="#{ related } "/>)
36
+ else
37
+ extra = related . context == :document ? related . attr ( 'title-extra' ) : ''
38
+ title = "#{ strip_tags ( link_text ( related ) ) } #{ extra } "
39
+ # We're in an attribute so escape quotes too!
40
+ title = title . gsub '"' , '"'
41
+ %(<link rel="#{ rel } " #{ link_href related } title="#{ title } "/>)
42
+ end
38
43
end
39
44
end
40
45
end
Original file line number Diff line number Diff line change @@ -529,6 +529,38 @@ def dest_file(file)
529
529
end
530
530
end
531
531
end
532
+ context 'the section has a canonical link' do
533
+ let ( :input ) do
534
+ <<~ASCIIDOC
535
+ = Title
536
+
537
+ [id="otd",canonical-url="bazbar"]
538
+ == Outdated
539
+
540
+ [[current]]
541
+ == Current
542
+
543
+ Words.
544
+ ASCIIDOC
545
+ end
546
+ file_context 'first subpage' , 'otd.html' do
547
+ let ( :next_title ) { "Current" }
548
+ include_examples 'standard page' , 'index' , 'current'
549
+ it 'contains a <link rel="canonical" ...> header tag' do
550
+ expect ( contents ) . to include <<~HTML
551
+ < link rel ="canonical " href ="bazbar "/>
552
+ HTML
553
+ end
554
+ end
555
+ file_context 'second subpage' , 'current.html' do
556
+ let ( :prev_title ) { "Outdated" }
557
+ include_examples 'standard page' , 'otd' , nil
558
+ it 'does not contains a canonical header tag' do
559
+ expect ( contents ) . not_to include "canonical"
560
+ expect ( contents ) . not_to include "bazbar"
561
+ end
562
+ end
563
+ end
532
564
end
533
565
context 'when chunk level is 2' do
534
566
let ( :convert_attributes ) do
You can’t perform that action at this time.
0 commit comments