将带有隐私包的 cookie 消息添加到 blogdown 网站

Adding cookie message with the privacy pack to blogdown website

我想添加一条 cookie 消息,以告知读者我的博客正在使用 cookie。我正在使用带有“tranquilpeak”主题的 hugo blogdown。不幸的是,这个主题还没有实现隐私包,所以我试图从这个 site 添加在“学术”主题中使用的信息。我补充说:

privacy_pack = true

到“config.toml”。使用

创建了“cookie_consent.html”文件
{{ if .Site.Params.privacy_pack }}
<link rel="stylesheet" href="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.css">
<script src="//cdnjs.cloudflare.com/ajax/libs/cookieconsent2/3.0.3/cookieconsent.min.js">        
</script>
<script>
  window.addEventListener("load", function(){
    window.cookieconsent.initialise({
      "palette": {
    "popup": {
      "background": "#000"
    },
    "button": {
      "background": "#f1d600"
    }
  },
  "content": {
    "message": {{ i18n "cookie_message" | default "This website uses cookies to ensure you get the best experience on our website." }},
    "dismiss": {{ i18n "cookie_dismiss" | default "Got it!" }},
    "link": {{ i18n "cookie_learn" | default "Learn more" }}
       }
})});
    </script>
     {{ end }}

然后我补充说:

 {{ partial "cookie_consent.html" . }}

到文件“header.html”。不幸的是,cookie 声明没有出现,我不知道从哪里开始寻找原因。感谢任何帮助。

谢天谢地,Maateen pointed out that one can use the Cookie Consent JavaScript plugin

您可以访问此 link 并生成您自己的代码。但是,为了快速解决问题,您可以复制以下代码并将它们粘贴到主题的 "foot_end.html" 末尾。

<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.css" />
<script src="https://cdn.jsdelivr.net/npm/cookieconsent@3/build/cookieconsent.min.js" data-cfasync="false"></script>
<script>
window.cookieconsent.initialise({
  "palette": {
    "popup": {
      "background": "#2D2D39"
    },
    "button": {
      "background": "#14a7d0"
    }
  },
  "theme": "edgeless",
  "position": "bottom-right",
  "content": {
      "message": "This website uses cookies for Google Analytics so that I know how many people are reading the blog and which blogposts are the most popular. The website does not collect any personal data.",
  "href": "https://www.cookiesandyou.com/"
  }
});
</script>

要查看此代码的演示,您可以访问我的 blog