【问题标题】:Jekyll build is putting 'localhost' links in _site (production) filesJekyll build 将 'localhost' 链接放入 _site(生产)文件中
【发布时间】:2017-01-06 18:09:52
【问题描述】:

我正在运行bundle exec jekyll build && bundle exec jekyll serve --watch 来生成_site 文件夹,然后我们通过FTP 将其上传到Web 服务器。 _site 文件夹中的 index.html 文件包含指向“localhost”本地 URL 的链接,而不是正确的站点 URL,从而导致链接断开。使用 FTP 部署大概意味着链接的文本将按原样部署到生产服务器,并且用户将被重定向到“localhost”而不是我们的博客 URL。我怎样才能解决这个问题?我之前没有遇到任何问题。

摘自 index.html:

  <link rel="stylesheet" type="text/css" href="/blog/slick/slick.css"/>
  <link rel="stylesheet" type="text/css" href="/blog/slick/slick-theme.css"/>
  <link rel="stylesheet" href="/blog/css/main.css">
  <link rel="canonical" href="http://localhost:4000/blog/">
  <link rel="alternate" type="application/rss+xml" title="The WordBrewery Blog | Language Untapped" href="http://localhost:4000/blog/feed.xml">

摘自_config.yml:

title: "The WordBrewery Blog | Language Untapped"
description: "WordBrewery's home for aspiring polyglots. Study tips, book and app reviews, grammar and vocabulary lessons, interviews, and other language-learning resources."
baseurl: "/blog" # the subpath of your site
url: "https://wordbrewery.com" # the base hostname & protocol for your site
feed: <link rel="alternate" type="application/rss+xml" title="{{ site.name }}" href="{{ site.url }}/feed.xml" target="_blank">
wordbrewery: "[WordBrewery](http://wordbrewery.com){:target='_blank'}"
languages-offered: "twenty"

# Jekyll settings

markdown: kramdown
permalink: /:categories/:title/
gems: [jekyll, jekyll-archives, github-pages, bundler, bourbon, neat, jekyll-seo-tag, classifier-reborn, jekyll-feed, nokogiri, jekyll-sitemap, "jekyll/figure"]
encoding: utf-8
lsi: true
timezone: America/Denver
logo: "{{ site.url }}/assets/images/logo-gold.jpg"
avatar: "{{ site.url }}/assets/images/fb-profile.jpg"
locale: "en_US"

# YAML defaults

defaults:
    scope:
      path: "" # an empty string here means all files in the project
    values:
      layout: post
      title: "WordBrewery now has native-speaker audio for beginning Spanish"
      author: "WordBrewery"
      category: Learning
      image: SpanishSpain.jpg
      featured: true
    sass:
      sass_dir: _sass

【问题讨论】:

  • 没有 jekyll 代码,很难调试。任何存储库网址?或者_includes/head.html 内容。

标签: jekyll liquid


【解决方案1】:

您只需要构建您的网站(而不是在本地提供),然后您就可以将生成的文件上传到您的服务器:

$ bundle exec jekyll build

这将使用_config.yml 中的配置变量url 的值生成规范链接。

<link rel="canonical" href="https://wordbrewery.com/blog/">

如果您运行 jekyll 的 serve 命令,则 url 的值将是 localhost,因为它的目标是提供本地实例来调试您的 jekyll 应用程序。

<link rel="canonical" href="http://localhost:4000/blog/">

或者甚至更好地将 production 指定为 environment 变量,这样您就可以根据您所在的环境选择执行部分代码,默认情况下,Jekyll 将 environmnet 变量设置为 发展

$ JEKYLL_ENV=production bundle exec jekyll build

然后在您的代码中,您可以输入如下内容:

{% if jekyll.environment == "production" %}
   {% include adsense.html %}
{% endif %}

【讨论】:

  • 奇怪的是,当我运行bundle exec jekyll build 时,它会生成带有http://localhost:4000 的url,知道为什么吗?
【解决方案2】:

对于像我这样后来偶然发现此问题的人 - 我发现 jekyll build ing 而我同时有另一个进程 jekyll serveing 导致 localhost 不受欢迎地包含在 html 文件中。

取消另一个 serve 进程首先对我有用。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2019-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-08-06
    • 2016-09-10
    • 1970-01-01
    相关资源
    最近更新 更多