add raw HTML with [removed] inside Gatsby React page

前端 未结 5 1389
小蘑菇
小蘑菇 2020-12-01 18:13

I am trying to add an external embed code to my Gatsby page.

I currently use

import React from \'react\'
import Link from \'gatsby-link\'


let test          


        
5条回答
  •  广开言路
    2020-12-01 18:43

    One way - perhaps the preferred way - is using the SSR file.

    From the docs:

    The file gatsby-ssr.js lets you alter the content of static HTML files as they are being Server-Side Rendered (SSR) by Gatsby and Node.js. To use the Gatsby SSR APIs, create a file called gatsby-ssr.js in the root of your site. Export any of the APIs you wish to use in this file.

    A tutorial on how to do that is here: https://uxworks.online/how-to-add-a-script-in-head-or-body-tag-in-your-gatsby-website/

    It uses the setHeadComponents method to inject into html.js:

    setHeadComponents
    

    It takes an array of components as its first argument which will be added to head components during building time and which will be passed to html.js.

提交回复
热议问题