代码之家  ›  专栏  ›  技术社区  ›  Steven Aguilar

HUGO:由于MIME类型(text/html)不匹配而被阻止(X-Content-type-Options:nosniff)

  •  0
  • Steven Aguilar  · 技术社区  · 6 年前

    我目前正试图部署一个雨果网站Netlify,但我一直无法。我得到以下错误:

    https://cdn.jsdelivr.net/gh/theasteve/blog/master@0.0.1/public/assets/main.js 由于MIME类型(文本/纯文本)不匹配而被阻止 (X-Content-Type-Options:nosniff)。

    prism.js 文件和 main.js 文件。

    错误显示来自 About 页面,即使删除了脚本标记,我仍然得到一个没有添加任何样式的页面。

    <footer class="footer">
      <div class="footer__inner">
        {{ if $.Site.Copyright }}
          <div class="copyright copyright--user">{{ $.Site.Copyright | safeHTML }}</div>
        {{else}}
          {{ partial "logo.html" . }}
          <div class="copyright">
            <span>© {{ now.Year }} Powered by <a href="https://gohugo.io" target="_blank" rel="noopener">Hugo</a></span>
            <span>Theme created by <a href="https://twitter.com/panr" target="_blank" rel="noopener">panr</a></span>
          </div>
        {{end}}
      </div>
    </footer>
    
    <script  src="https://cdn.rawgit.com/theasteve/blog/master/public/assets/main.js"></script>
    <script  src="https://cdn.rawgit.com/theasteve/blog/master/public/assets/prism.js"></script>
    <!-- <script src="{{ "assets/prism.js" | absURL }}"></script> -->
    

    # baseurl = "https://theasteve.github.io/"
    languageCode = "en-us"
    theme = "hello-friend"
    paginate = 5
    
    [params]
      # dir name of your blog content (default is `content/posts`)
      contentTypeName = "posts"
      # "light" or "dark"
      defaultTheme = "light"
      # if you set this to 0, only submenu trigger will be visible
      showMenuItems = 2
      # Show reading time in minutes for posts
      showReadingTime = false
    
    [languages]
      [languages.en]
        title = "theAsteve"
        subtitle = "Lets get it"
        keywords = ""
        copyright = ""
        menuMore = "Show more"
        writtenBy = "Written by"
        readMore = "Read more"
        readOtherPosts = "Read other posts"
        newerPosts = "Newer posts"
        olderPosts = "Older posts"
        minuteReadingTime = "min read"
        dateFormatSingle = "2006-01-02"
        dateFormatList = "2006-01-02"
    
        [languages.en.params.logo]
          logoText = "theAsteve"
          logoHomeLink = "/"
        # or
    
        # path = "/img/your-example-logo.svg"
        alt = "theAsteve"
    
        [languages.en.menu]
          [[languages.en.menu.main]]
            identifier = "about"
            name = "About"
            url = "/about"
    

    我注释掉了baseurl,因为在部署到Netlify时没有显示任何内容。这是我的Netlify.toml

    [build]
    publish = "public"
    command = "hugo --gc --minify"
    
    [context.production.environment]
    HUGO_VERSION = "0.69.2"
    HUGO_ENV = "production"
    HUGO_ENABLEGITINFO = "true"
    
    [context.split1]
    command = "hugo --gc --minify --enableGitInfo"
    
    [context.split1.environment]
    HUGO_VERSION = "0.69.2"
    HUGO_ENV = "production"
    
    [context.deploy-preview]
    command = "hugo --gc --minify --buildFuture -b $DEPLOY_PRIME_URL"
    
    [context.deploy-preview.environment]
    HUGO_VERSION = "0.69.2"
    
    [context.branch-deploy]
    command = "hugo --gc --minify -b $DEPLOY_PRIME_URL"
    
    [context.branch-deploy.environment]
    HUGO_VERSION = "0.69.2"
    
    [context.next.environment]
    HUGO_ENABLEGITINFO = "true"
    

    为什么返回HTML?为什么资产没有被编译?

    0 回复  |  直到 6 年前
        1
  •  1
  •   kaulex    6 年前

    找到了解决办法。这是因为hugo试图从另一个URL加载css/js文件,即如果你在mydomain.com/en/hugo试图导入mydomain.com/css/mycss.css,但它必须是mydomain.com/en/css/mycss.css

    为此,您需要将baseof.html中的静态导入替换为:

    <link rel="stylesheet" href='{{ "css/materialize.css" | absLangURL }}'>
    

    你必须用你所有的href和src关键字。