【问题标题】:Removing references to Gatsby删除对 Gatsby 的引用
【发布时间】:2019-10-21 00:44:43
【问题描述】:

如何安全地删除 Gatsby 构建的静态站点中对 Gatsby 的所有引用?

例如,默认的html.js(在.cache/default-html.js中)包含:

import React from "react"
import PropTypes from "prop-types"

export default function HTML(props) {
  return (
    <html {...props.htmlAttributes}>
      <head>
        <meta charSet="utf-8" />
        <meta httpEquiv="x-ua-compatible" content="ie=edge" />
        <meta
          name="viewport"
          content="width=device-width, initial-scale=1, shrink-to-fit=no"
        />
        {props.headComponents}
      </head>
      <body {...props.bodyAttributes}>
        {props.preBodyComponents}
        <noscript key="noscript" id="gatsby-noscript">
          This app works best with JavaScript enabled.
        </noscript>
        <div
          key={`body`}
          id="___gatsby"
          dangerouslySetInnerHTML={{ __html: props.body }}
        />
        {props.postBodyComponents}
      </body>
    </html>
  )
}

HTML.propTypes = {
  htmlAttributes: PropTypes.object,
  headComponents: PropTypes.array,
  bodyAttributes: PropTypes.object,
  preBodyComponents: PropTypes.array,
  body: PropTypes.string,
  postBodyComponents: PropTypes.array,
}

这会在我每个页面的源代码中产生&lt;div id="___gatsby"&gt;&lt;div style="outline:none" tabindex="-1" role="group" id="gatsby-focus-wrapper"&gt;

我想从我所有默认包含的页面中删除字符串 gatsby(而不是我明确添加它的页面 - 例如,我可能会将 &lt;div&gt;This site was built by gatsby&lt;/div&gt; 添加到页脚)。

【问题讨论】:

    标签: javascript reactjs configuration gatsby


    【解决方案1】:

    根据文档,您可以 customize html.js 在核心 Gatsby 应用程序之外编辑 HTML。

    但这可能对您没有帮助,因为它还指出

    在您的 &lt;body&gt; 中,您必须有一个 id 为 ___gatsby 的 div

    【讨论】:

      猜你喜欢
      • 2022-06-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-10-28
      • 2017-06-17
      • 2021-11-30
      • 1970-01-01
      相关资源
      最近更新 更多