skip to Main Content

Could you help me understand how %s is referencing the <SEO /> component’s title attribute inside the <Helmet /> component in the gatsby starter theme?

https://github.com/gatsbyjs/gatsby-starter-default/blob/master/src/components/seo.js

Line 19:

titleTemplate={`%s | ${data.site.siteMetadata.title}`}

2

Answers


  1. The pattern %s is used to be replaced for string:

    const str = 'world';
    console.log('Hello %s!', str);
    Login or Signup to reply.
  2. $s is inferred from the “title” prop of your component.

    Here is a link to the relevant source code:

    https://github.com/nfl/react-helmet/blob/b79d30ff44c7ff3c175c31059076e5e549a1b402/src/HelmetUtils.js#L27

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search