Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for creating non-meta tags with v2_meta #5746

Merged
merged 8 commits into from Mar 10, 2023

Conversation

chaance
Copy link
Collaborator

@chaance chaance commented Mar 9, 2023

This PR adds 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 is useful for things like canonical URLs, alternate language references and structured data JSON.

The added API looks like this:

export function meta({ data }) {
  let { author } = data;
  return [
    { title: data.name + " Profile" },
    {
      // <link rel='canonical' href='https://website.com/authors/1'>
      tagName: "link",
      rel: "canonical",
      href: "https://website.com/authors/" + author.id,
    },
    {
      // <script type='application/ld+json'>{ ... }</script>
      "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,
      },
    },
  ];
}

@changeset-bot
Copy link

changeset-bot bot commented Mar 9, 2023

🦋 Changeset detected

Latest commit: 6dedab6

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 18 packages
Name Type
@remix-run/react Minor
@remix-run/server-runtime Minor
@remix-run/testing Minor
@remix-run/cloudflare Minor
@remix-run/deno Minor
@remix-run/dev Minor
@remix-run/node Minor
@remix-run/cloudflare-pages Minor
@remix-run/cloudflare-workers Minor
create-remix Minor
@remix-run/css-bundle Minor
@remix-run/architect Minor
@remix-run/express Minor
@remix-run/netlify Minor
@remix-run/vercel Minor
@remix-run/serve Minor
remix Minor
@remix-run/eslint-config Minor

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

...matches.map((match) => match.meta),
];
export const meta = ({ data, matches }) =>
matches.flatMap((match) => match.meta);
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While both technically work (React renders nested arrays of arrays just fine), the output of map doesn't match our return type API.

@ryanflorence ryanflorence merged commit 1d46d33 into dev Mar 10, 2023
@ryanflorence ryanflorence deleted the chance/v2-meta-updates branch March 10, 2023 19:00
@github-actions github-actions bot added the awaiting release This issue has been fixed and will be released soon label Mar 10, 2023
@github-actions
Copy link
Contributor

🤖 Hello there,

We just published version v0.0.0-nightly-7d96a22-20230311 which includes this pull request. If you'd like to take it for a test run please try it out and let us know what you think!

Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
awaiting release This issue has been fixed and will be released soon CLA Signed package:server-runtime renderer:react
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants