Jekyll build将"localhost"链接放在_site(生产)文件中

Wor*_*ery 7 liquid jekyll

我正在运行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">
Run Code Online (Sandbox Code Playgroud)

摘自_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
Run Code Online (Sandbox Code Playgroud)

mar*_*nuy 13

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

$ bundle exec jekyll build
Run Code Online (Sandbox Code Playgroud)

这将产生与配置变量的值规范链接url_config.yml.

<link rel="canonical" href="https://wordbrewery.com/blog/">
Run Code Online (Sandbox Code Playgroud)

如果你运行jekyll的serve命令,那么url的值将是localhost因为它的目标是服务本地实例来调试你的jekyll应用程序.

<link rel="canonical" href="http://localhost:4000/blog/">
Run Code Online (Sandbox Code Playgroud)

或者甚至更好地将生产指定为environment变量,以便根据您所处的环境选择执行部分代码,默认情况下,Jekyll将environmnet变量设置为开发:

$ JEKYLL_ENV=production bundle exec jekyll build
Run Code Online (Sandbox Code Playgroud)

然后在你的代码中你可以添加如下内容:

{% if jekyll.environment == "production" %}
   {% include adsense.html %}
{% endif %}
Run Code Online (Sandbox Code Playgroud)

  • 奇怪的是,当我运行“bundle exec jekyll build”时,它会生成带有“http://localhost:4000”的网址,知道为什么吗? (2认同)