HU GO: был заблокирован из-за несоответствия типа MIME («text / html») (X-Content-Type-Options: nosniff) - PullRequest
1 голос
/ 27 апреля 2020

В настоящее время я пытаюсь развернуть сайт HU GO в Netlify, но мне не удалось. Я получаю следующую ошибку:

Ресурс из «https://cdn.jsdelivr.net/gh/theasteve/blog/master@0.0.1 / public / assets / main. js» был заблокирован из-за типа MIME («text / plain»). ”) Несоответствие (X-Content-Type-Options: nosniff).

Не уверен, почему Netlify возвращает HTML вместо файла JavaScript. При проверке файла призма. js и файла main. js.

появляются оба файла. Ошибка отображается из Что касается страницы , даже после удаления тегов скрипта я получаю страницу без добавления каких-либо стилей.

<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> -->

Вот мой config.toml

# 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? Почему активы не компилируются?

1 Ответ

0 голосов
/ 05 мая 2020

Нашел решение. Это потому, что hu go пытается загрузить файлы css / js с другого URL, т.е. если вы находитесь на mydomain.com/en/ hu go пытается импортировать mydomain.com/css/mycss.css но это должен быть mydomain.com/en/css/mycss.css

Так что для этого вам нужно заменить stati c import в вашей базе. html с:

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

Вы должны сделать это со всеми своими ключевыми словами href и sr c. Надеюсь, что смогу помочь: D

...