Remix Blog
Words are nice... but code speaks louder. Dive into a fully commented project template, showcasing these techniques (and more) in action.
Sorry, no results found for "".
Similarly to what we offer with responsive images, our GraphQL API also offers a way to fetch pre-computed meta tags based on the content you insert inside DatoCMS.
Here's a sample of the meta tags you can automatically generate. It includes meta tags for SEO, social share and website favicons:
You can easily include all this information inside your Remix app with the help of our react-datocms
package, so make sure to install it, if you've not already done it:
npm i --save react-datocms
With Remix, you can specify meta tags for a page using the meta
export:
export function meta({ data }) { title: "Something cool", description: "This becomes the nice preview on search results." };};
With DatoCMS you can feed content coming from a _seoMetaTags
query directly into Remix by using the toRemixMeta
function, which generates a compatible object for Remix's meta
function:
1import { request } from "../lib/datocms";2import { toRemixMeta } from "react-datocms";3import { useLoaderData } from "remix";4
5const HOMEPAGE_QUERY = `6 {7 blog {8 seo: _seoMetaTags {9 attributes10 content11 tag12 }13 }14 }`;15
16export async function loader() {17 return request(HOMEPAGE_QUERY, {18 variables: { limit: 10 }19 });20}21
22export function meta({ data }) {23 return toRemixMeta(data.blog.seo);24};25
26
27export default function Home() {28 // ...29}
If you want to add all the link
and meta
tags needed to generate favicons for your website, you can use the renderMetaTags
helper along with the faviconMetaTags
GraphQL query:
Remix offers a links
export to define which <link>
elements to add to the page, but for performance reasons it doesn't receive any loader data, so you cannot use it to render favicons meta tags! The best way to render them is using renderMetaTags
in your root component, like in the example.
1import {2 Links,3 LiveReload,4 Meta,5 Form,6 Outlet,7 Scripts,8 ScrollRestoration,9 useLoaderData,10} from 'remix';11import { renderMetaTags } from 'react-datocms';12import { load } from '~/lib/datocms';13
14export const loader = async ({ request }) => {15 return load(`16 {17 site: _site {18 favicon: faviconMetaTags(variants: [icon, msApplication, appleTouchIcon]) {19 attributes20 content21 tag22 }23 }24 }25 `);26};27
28export default function App() {29 const { site } = useLoaderData();30
31 return (32 <html lang="en">33 <head>34 <meta charSet="utf-8" />35 <meta name="viewport" content="width=device-width,initial-scale=1" />36 <Meta />37 <Links />38 {renderMetaTags(site.favicon)}39 </head>40 <body>41 <Outlet />42 <ScrollRestoration />43 <Scripts />44 {process.env.NODE_ENV === 'development' && <LiveReload />}45 </body>46 </html>47 );48}
Want to know more about SEO customization in DatoCMS? Check out this video tutorial: