@@ -443,9 +443,9 @@ test.describe("v2_meta", () => {
443
443
` ,
444
444
445
445
"app/routes/_index.jsx" : js `
446
- export const meta = ({ data, matches }) => [
447
- ... matches.map ((match) => match.meta),
448
- ];
446
+ export const meta = ({ data, matches }) =>
447
+ matches.flatMap ((match) => match.meta);
448
+
449
449
export default function Index() {
450
450
return <div>This is the index file</div>;
451
451
}
@@ -464,6 +464,59 @@ test.describe("v2_meta", () => {
464
464
}
465
465
` ,
466
466
467
+ "app/routes/authors.$authorId.jsx" : js `
468
+ import { json } from "@remix-run/node";
469
+
470
+ export async function loader({ params }) {
471
+ return json({
472
+ author: {
473
+ id: params.authorId,
474
+ name: "Sonny Day",
475
+ address: {
476
+ streetAddress: "123 Sunset Cliffs Blvd",
477
+ city: "San Diego",
478
+ state: "CA",
479
+ zip: "92107",
480
+ },
481
+ emails: [
482
+ "sonnyday@fancymail.com",
483
+ "surfergal@veryprofessional.org",
484
+ ],
485
+ },
486
+ });
487
+ }
488
+
489
+ export function meta({ data }) {
490
+ let { author } = data;
491
+ return [
492
+ { title: data.name + " Profile" },
493
+ {
494
+ tagName: "link",
495
+ rel: "canonical",
496
+ href: "https://website.com/authors/" + author.id,
497
+ },
498
+ {
499
+ "script:ld+json": {
500
+ "@context": "http://schema.org",
501
+ "@type": "Person",
502
+ "name": author.name,
503
+ "address": {
504
+ "@type": "PostalAddress",
505
+ "streetAddress": author.address.streetAddress,
506
+ "addressLocality": author.address.city,
507
+ "addressRegion": author.address.state,
508
+ "postalCode": author.address.zip,
509
+ },
510
+ "email": author.emails,
511
+ },
512
+ },
513
+ ];
514
+ }
515
+ export default function AuthorBio() {
516
+ return <div>Bio here!</div>;
517
+ }
518
+ ` ,
519
+
467
520
"app/routes/music.jsx" : js `
468
521
export function meta({ data, matches }) {
469
522
let rootModule = matches.find(match => match.route.id === "root");
@@ -531,4 +584,36 @@ test.describe("v2_meta", () => {
531
584
await app . goto ( "/" ) ;
532
585
expect ( await app . getHtml ( 'meta[property="og:image"]' ) ) . toBeTruthy ( ) ;
533
586
} ) ;
587
+
588
+ test ( "{ 'script:ld+json': {} } adds a <script type='application/ld+json' />" , async ( {
589
+ page,
590
+ } ) => {
591
+ let app = new PlaywrightFixture ( appFixture , page ) ;
592
+ await app . goto ( "/authors/1" ) ;
593
+ let scriptTag = await app . getHtml ( 'script[type="application/ld+json"]' ) ;
594
+ let scriptContents = scriptTag
595
+ . replace ( '<script type="application/ld+json">' , "" )
596
+ . replace ( "</script>" , "" )
597
+ . trim ( ) ;
598
+
599
+ expect ( JSON . parse ( scriptContents ) ) . toEqual ( {
600
+ "@context" : "http://schema.org" ,
601
+ "@type" : "Person" ,
602
+ name : "Sonny Day" ,
603
+ address : {
604
+ "@type" : "PostalAddress" ,
605
+ streetAddress : "123 Sunset Cliffs Blvd" ,
606
+ addressLocality : "San Diego" ,
607
+ addressRegion : "CA" ,
608
+ postalCode : "92107" ,
609
+ } ,
610
+ email : [ "sonnyday@fancymail.com" , "surfergal@veryprofessional.org" ] ,
611
+ } ) ;
612
+ } ) ;
613
+
614
+ test ( "{ tagName: 'link' } adds a <link />" , async ( { page } ) => {
615
+ let app = new PlaywrightFixture ( appFixture , page ) ;
616
+ await app . goto ( "/authors/1" ) ;
617
+ expect ( await app . getHtml ( 'link[rel="canonical"]' ) ) . toBeTruthy ( ) ;
618
+ } ) ;
534
619
} ) ;
0 commit comments