CaiJimmy / hugo-theme-stack

Card-style Hugo theme designed for bloggers
https://stack.jimmycai.com
GNU General Public License v3.0
5.03k stars 1.66k forks source link

giscus在中文下不显示,并提示:”giscus.app 已拒绝连接“ #1096

Closed rickeygong closed 14 hours ago

rickeygong commented 14 hours ago

What happened?

问题描述

giscus在中文下不显示,并提示:”giscus.app 已拒绝连接“

Hugo env

hugo v0.138.0-ad82998d54b3f9f8c2741b67356813b55b3134b9+extended windows/amd64 BuildDate=2024-11-06T11:22:34Z VendorInfo=gohugoio
GOOS="windows"
GOARCH="amd64"
GOVERSION="go1.23.2"
github.com/sass/libsass="3.6.6"
github.com/webmproject/libwebp="v1.3.2"

我的 hugo.yaml

baseurl: https://sample.com/ # 你的域名
languageCode: zh-cn
theme: hugo-theme-stack
# [GongDonghai comments.]博客的主名,粗暴一点就是[xxx博客]之类的
title: xx
copyright: xx

# Theme i18n support
# Available values: ar, bn, ca, de, el, en, es, fr, hu, id, it, ja, ko, nl, pt-br, th, uk, zh-cn, zh-hk, zh-tw
DefaultContentLanguage: zh-cn

# Set hasCJKLanguage to true if DefaultContentLanguage is in [zh-cn ja ko]
# This will make .Summary and .WordCount behave correctly for CJK languages.
hasCJKLanguage: true

languages:
    zh-cn:
        languageName: 中文
        title: xx
        languageCode: zh-cn
        weight: 1
        params:
            sidebar:
                subtitle: xx
    en:
        languageName: English
        title: Dxx
        weight: 2
        languageCode: en
        params:
            sidebar:
                subtitle: xx

services:
    # Change it to your Disqus shortname before using
    disqus:
        shortname: "hugo-theme-stack"
    # GA Tracking ID
    googleAnalytics:
        id:

pagination:
    pagerSize: 10

permalinks:
    post: /p/:slug/
    page: /:slug/

params:
    mainSections:
        - post
    featuredImageField: image
    rssFullContent: true
    favicon: images/favicon.ico

    footer:
        since: 2023
        customText: 

    dateFormat:
        published: 2006-01-02
        lastUpdated: 2006-01-02 15:04 CST

    sidebar:
        emoji: 
        subtitle:
        avatar:
            enabled: true
            local: true
            src: avatar.png

    article:
        math: false
        toc: true
        readingTime: true
        license:
            enabled: true
            default: Licensed under CC BY-NC-SA 4.0

    comments:
        enabled: true
        provider: "giscus"

        disqusjs:
            shortname:
            apiUrl:
            apiKey:
            admin:
            adminLabel:

        # giscus配置信息
        # <script src="https://giscus.app/client.js"
        #         data-repo="aaaa/bbb"
        #         data-repo-id="xxxx"
        #         data-category="ccccc"
        #         data-category-id="cccsss"
        #         data-mapping="pathname"
        #         data-strict="0"
        #         data-reactions-enabled="1"
        #         data-emit-metadata="0"
        #         data-input-position="bottom"
        #         data-theme="preferred_color_scheme"
        #         data-lang="zh-CN"
        #         crossorigin="anonymous"
        #         async>
        # </script>

        giscus:
            repo: "aaaa/bbb"
            repoID: "xxxx"
            category: "ccccc"
            categoryID: "cccsss"
            mapping: "pathname"
            lightTheme: "light"
            darkTheme: "dark"
            reactionsEnabled: 1
            emitMetadata: 0
            lang: ""

        utterances:
            repo:
            issueTerm: pathname
            label:

        beaudar:
            repo:
            issueTerm: pathname
            label:
            theme:

        remark42:
            host:
            site:
            locale:

        vssue:
            platform:
            owner:
            repo:
            clientId:
            clientSecret:
            autoCreateIssue: false

        # Waline client configuration see: https://waline.js.org/en/reference/component.html
        waline:
            serverURL:
            lang:
            pageview:
            emoji:
                - https://unpkg.com/@waline/emojis@1.0.1/weibo
            requiredMeta:
                - name
                - email
                - url
            locale:
                admin: Admin
                placeholder:

        twikoo:
            envId:
            region:
            path:
            lang:

    widgets:
        homepage:
            - type: search
            - type: archives
              params:
                  limit: 5
            - type: categories
              params:
                  limit: 10
            - type: tag-cloud
              params:
                  limit: 10
        page:
            - type: toc

    opengraph:
        twitter:
            # Your Twitter username
            site:

            # Available values: summary, summary_large_image
            card: summary_large_image

    defaultImage:
        opengraph:
            enabled: false
            local: false
            src:

    colorScheme:
        # Display toggle
        toggle: true

        # Available values: auto, light, dark
        default: auto

    imageProcessing:
        cover:
            enabled: true
        content:
            enabled: true

### Custom menu
### See https://stack.jimmycai.com/config/menu
### To remove about, archive and search page menu item, remove `menu` field from their FrontMatter
menu:
    main: []

    social:
        - identifier: github
          name: GitHub
          url: https://github.com/
          weight: 4
          params:
              icon: brand-github

        - identifier: bilibili
          name: Bilibili
          url: https://bilibili.com/
          weight: 3
          params:
              icon: bilibili-line

        - identifier: email
          name: Email
          url: mailto:gdhblog@outlook
          weight: 2
          params:
              icon: email

        - identifier: rss
          name: RSS
          url: /index.xml
          weight: 1
          params:
              icon: rss

related:
    includeNewer: true
    threshold: 60
    toLower: false
    indices:
        - name: tags
          weight: 100

        - name: categories
          weight: 200

markup:
    goldmark:
        extensions:
            passthrough:
                enable: true
                delimiters:
                    block:
                        - - \[
                          - \]
                        - - $$
                          - $$
                    inline:
                        - - \(
                          - \)
        renderer:
            ## Set to true if you have HTML content inside Markdown
            unsafe: true
    tableOfContents:
        endLevel: 4
        ordered: true
        startLevel: 2
    highlight:
        noClasses: false
        codeFences: true
        guessSyntax: true
        lineNoStart: 1
        lineNos: true
        lineNumbersInTable: true
        tabWidth: 4

截图

zh-cn

image

en

image

Hugo version

0.138.0

Theme version

hugo-theme-stack-3.29.0

What browsers are you seeing the problem on?

Microsoft Edge

More information about the browser

版本 130.0.2849.80 (正式版本)

Relevant log output

Refused to frame 'https://giscus.app/' because an ancestor violates the following Content Security Policy directive: "frame-ancestors 'self'".

Link to Minimal Reproducible Example

https://github.com/rickeygong/Gdh_Hugo_Blog

rickeygong commented 14 hours ago

看了其他博主的博客在中文模式下显示正常,控制台看了页面的JS,对比发现渲染出来的js语言标识不对,

应该是 zh-CN , 而不是 zh-cn。于是调整了Blog\themes\hugo-theme-stack\layouts\partials\comments\provider 下的giscus.html

原来

data-lang="{{- default (default `en` $.Language.LanguageCode) .lang -}}"

修改后

data-lang="{{ if eq $.Site.Language.Lang `zh-cn` }}zh-CN{{ else }}{{ default `en` $.Site.Language.Lang }}{{ end }}"