Jekyll build places "localhost" links in _site (production) files

I run bundle exec jekyll build && bundle exec jekyll serve --watch to create a _site folder, which we then upload FTP to the web server. The index.html file in the _site folder contains links to the local URL of the local host, and not the correct site URL, which leads to broken links. FTP deployment presumably means that the link text will be deployed as on a production server, and users will be redirected to "localhost" and not to our blog URL. How can i fix this? I have not encountered any problems before.

Excerpt from 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"> 

Excerpt from _config.yml:

 title: "The WordBrewery Blog | Language Untapped" description: "WordBrewery 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 
+6
source share
2 answers

You just need to create your site (do not service it locally) so that you can then upload the generated files to your server:

 $ bundle exec jekyll build 

This will create a canonical link with the value of the url configuration variable in _config.yml .

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

If you run the jekyll serve command, then the url value will be localhost , since its purpose is to serve the local instance to debug your jekyll application.

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

Or it’s even better to specify production as an environment variable so that you can execute parts of the code depending on the environment you are in. By default, Jekyll sets the environmnet variable to development

 $ JEKYLL_ENV=production bundle exec jekyll build 

Then in your code you can put something like:

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

For people who stumble on this later, like me, I found that jekyll build ing, while I had a different jekyll serve process, at the same time led to the unwanted inclusion of the local host in html files.

Canceling another serve process first worked for me.

0
source

Source: https://habr.com/ru/post/1013839/


All Articles