forked from remix-run/remix
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for creating non-meta tags with
v2_meta
(remix-run#5746)
- Loading branch information
1 parent
8a6eb39
commit 2bdeea4
Showing
5 changed files
with
157 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
--- | ||
"@remix-run/react": minor | ||
"@remix-run/server-runtime": patch | ||
--- | ||
|
||
Add support for generating `<script type='application/ld+json' />` and meta-related `<link />` tags to document head via the route `meta` function when using the `v2_meta` future flag |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -443,9 +443,9 @@ test.describe("v2_meta", () => { | |
`, | ||
|
||
"app/routes/_index.jsx": js` | ||
export const meta = ({ data, matches }) => [ | ||
...matches.map((match) => match.meta), | ||
]; | ||
export const meta = ({ data, matches }) => | ||
matches.flatMap((match) => match.meta); | ||
export default function Index() { | ||
return <div>This is the index file</div>; | ||
} | ||
|
@@ -464,6 +464,59 @@ test.describe("v2_meta", () => { | |
} | ||
`, | ||
|
||
"app/routes/authors.$authorId.jsx": js` | ||
import { json } from "@remix-run/node"; | ||
export async function loader({ params }) { | ||
return json({ | ||
author: { | ||
id: params.authorId, | ||
name: "Sonny Day", | ||
address: { | ||
streetAddress: "123 Sunset Cliffs Blvd", | ||
city: "San Diego", | ||
state: "CA", | ||
zip: "92107", | ||
}, | ||
emails: [ | ||
"[email protected]", | ||
"[email protected]", | ||
], | ||
}, | ||
}); | ||
} | ||
export function meta({ data }) { | ||
let { author } = data; | ||
return [ | ||
{ title: data.name + " Profile" }, | ||
{ | ||
tagName: "link", | ||
rel: "canonical", | ||
href: "https://website.com/authors/" + author.id, | ||
}, | ||
{ | ||
"script:ld+json": { | ||
"@context": "http://schema.org", | ||
"@type": "Person", | ||
"name": author.name, | ||
"address": { | ||
"@type": "PostalAddress", | ||
"streetAddress": author.address.streetAddress, | ||
"addressLocality": author.address.city, | ||
"addressRegion": author.address.state, | ||
"postalCode": author.address.zip, | ||
}, | ||
"email": author.emails, | ||
}, | ||
}, | ||
]; | ||
} | ||
export default function AuthorBio() { | ||
return <div>Bio here!</div>; | ||
} | ||
`, | ||
|
||
"app/routes/music.jsx": js` | ||
export function meta({ data, matches }) { | ||
let rootModule = matches.find(match => match.route.id === "root"); | ||
|
@@ -531,4 +584,36 @@ test.describe("v2_meta", () => { | |
await app.goto("/"); | ||
expect(await app.getHtml('meta[property="og:image"]')).toBeTruthy(); | ||
}); | ||
|
||
test("{ 'script:ld+json': {} } adds a <script type='application/ld+json' />", async ({ | ||
page, | ||
}) => { | ||
let app = new PlaywrightFixture(appFixture, page); | ||
await app.goto("/authors/1"); | ||
let scriptTag = await app.getHtml('script[type="application/ld+json"]'); | ||
let scriptContents = scriptTag | ||
.replace('<script type="application/ld+json">', "") | ||
.replace("</script>", "") | ||
.trim(); | ||
|
||
expect(JSON.parse(scriptContents)).toEqual({ | ||
"@context": "http://schema.org", | ||
"@type": "Person", | ||
name: "Sonny Day", | ||
address: { | ||
"@type": "PostalAddress", | ||
streetAddress: "123 Sunset Cliffs Blvd", | ||
addressLocality: "San Diego", | ||
addressRegion: "CA", | ||
postalCode: "92107", | ||
}, | ||
email: ["[email protected]", "[email protected]"], | ||
}); | ||
}); | ||
|
||
test("{ tagName: 'link' } adds a <link />", async ({ page }) => { | ||
let app = new PlaywrightFixture(appFixture, page); | ||
await app.goto("/authors/1"); | ||
expect(await app.getHtml('link[rel="canonical"]')).toBeTruthy(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters