@@ -10,6 +10,7 @@ export default async function decorate(block) {
1010 buttonStyle : block . children ?. [ 4 ] ?. children ?. [ 1 ] ?. children ?. [ 0 ] ?. textContent ?. trim ( ) . toLowerCase ( ) ,
1111 altText : block . children ?. [ 4 ] ?. children ?. [ 2 ] ?. children ?. [ 0 ] ?. textContent ?. trim ( ) ,
1212 } ;
13+ const anchorHref = pageHeaderData . anchorNode ?. href ;
1314
1415 // create the container element
1516 const pageHeader = document . createElement ( "div" ) ;
@@ -19,9 +20,22 @@ export default async function decorate(block) {
1920 pageHeaderContent . classList . add ( "page-header__content" , "grid-item" , "grid-item--50" ) ;
2021
2122 // there should always be a title, so create it as an h1
22- const pageTitle = document . createElement ( "h1" ) ;
23- pageTitle . classList . add ( "page-header__title" , "util-heading-xl" ) ;
23+ let pageTitle = document . createElement ( "h1" ) ;
2424 pageTitle . innerText = pageHeaderData . title ;
25+ pageTitle . classList . add ( "page-header__title" , "util-heading-xl" ) ;
26+
27+ if ( pageHeaderData . anchorNode && ! anchorHref . includes ( "#" ) ) {
28+ // if there's a link, wrap the title in an anchor
29+ const wrappingAnchor = document . createElement ( "a" ) ;
30+ wrappingAnchor . setAttribute ( "href" , anchorHref ) ;
31+ wrappingAnchor . append ( pageTitle ) ;
32+ const visuallyHiddenText = document . createElement ( "span" ) ;
33+ visuallyHiddenText . classList . add ( "util-visually-hidden" ) ;
34+ visuallyHiddenText . innerText = "Read the story" ;
35+ wrappingAnchor . append ( visuallyHiddenText ) ;
36+ pageTitle = wrappingAnchor ;
37+ }
38+
2539 pageHeaderContent . append ( pageTitle ) ;
2640
2741 // if there is a description, add it as an h2
@@ -87,9 +101,20 @@ export default async function decorate(block) {
87101 if ( pageHeaderData . visual ) {
88102 if ( pageHeaderData . visual ?. nodeName == "PICTURE" ) {
89103 // Image
90- pageHeaderData . visual . classList . add ( "page-header__image" , "grid-item" , "grid-item--50" ) ;
91- pageHeaderData . visual . setAttribute ( "alt" , "" ) ;
92- pageHeader . append ( pageHeaderData . visual ) ;
104+ let pageHeaderVisual = pageHeaderData . visual ;
105+ // If there's a link, wrap the image in an anchor,
106+ // but hide it from assistive technologies
107+ if ( pageHeaderData . anchorNode ) {
108+ const wrappingAnchor = document . createElement ( "a" ) ;
109+ wrappingAnchor . setAttribute ( "href" , anchorHref ) ;
110+ wrappingAnchor . setAttribute ( "role" , "presentation" ) ;
111+ wrappingAnchor . append ( pageHeaderVisual ) ;
112+ pageHeaderVisual = wrappingAnchor ;
113+ } else {
114+ pageHeaderVisual . setAttribute ( "alt" , "" ) ;
115+ }
116+ pageHeaderVisual . classList . add ( "page-header__image" , "grid-item" , "grid-item--50" ) ;
117+ pageHeader . append ( pageHeaderVisual ) ;
93118 } else {
94119 // Video
95120 const embedCode = pageHeaderData . visual ?. innerText ?. trim ( ) ;
0 commit comments