首页 文章

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

提问于
浏览
7

我正在运行 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

2 回答

  • 11

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

    $ 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 变量设置为 development

    $ JEKYLL_ENV=production bundle exec jekyll build
    

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

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

    对于像我这样在以后遇到这种情况的人们 - 我发现 jekyll build ing同时我有另一个进程 jekyll serve ing导致localhost被不合理地包含在html文件中 .

    取消另一个 serve 进程首先为我工作 .

相关问题