【发布时间】:2020-06-09 22:35:58
【问题描述】:
我正在尝试向我在 Gatsby 上运行的博客添加评论脚本。 这是帖子模板的一部分:
return (
<Layout>
<ArticleSEO article={article} authors={authors} location={location} />
<ArticleHero article={article} authors={authors} />
<ArticleAside contentHeight={contentHeight}>
<Progress contentHeight={contentHeight} />
</ArticleAside>
<MobileControls>
<ArticleControls />
</MobileControls>
<ArticleBody ref={contentSectionRef}>
<MDXRenderer content={article.body}>
<ArticleShare />
</MDXRenderer>
</ArticleBody>
{mailchimp && article.subscription && <Subscription />}
// I want to put <script> tag here
{next.length > 0 && (
<NextArticle narrow>
<FooterNext>More articles from {name}</FooterNext>
<ArticlesNext articles={next} />
<FooterSpacer />
</NextArticle>
)}
</Layout>
);
我已经阅读了一些关于这个问题的文章,一些问答,但我无法解决它。 如果您需要完整代码,Click here。这是我要添加的示例脚本:
<script src="https://utteranc.es/client.js"
repo="[ENTER REPO HERE]"
issue-term="pathname"
theme="github-light"
crossorigin="anonymous"
async>
</script>
【问题讨论】:
-
您是否尝试过在
useEffect中创建脚本标签,如下所示:stackoverflow.com/questions/34424845/…? -
这能回答你的问题吗? Adding script tag to React/JSX