jekyll / github-metadata

Jekyll plugin to propagate the `site.github` namespace and set default values for use with GitHub Pages.
https://jekyll.github.io/github-metadata/
MIT License
282 stars 127 forks source link

Silently setting site.baseurl breaks htmlproofer #87

Closed jabenninghoff closed 7 years ago

jabenninghoff commented 7 years ago

PR https://github.com/jekyll/github-metadata/pull/76 implemented code that silently sets site.url and site.baseurl if site.baseurl is "unset:" and JEKYLL_ENV="production":

        # Set `site.url` and `site.baseurl` if unset and in production mode.
        if Jekyll.env == "production"
          site.config["url"] ||= drop.url
          site.config["baseurl"] = drop.baseurl if site.config["baseurl"].to_s.empty?
        end

Per the Jekyll docs on continuous integration, I'm running htmlproof. I'd like to validate using JEKYLL_ENV="production", using the following script:

#!/usr/bin/env bash
set -e # halt script on error

# set environment for production builds
PAGES_REPO_NWO="information-safety/information-safety.github.io" \
JEKYLL_ENV="production" \
bundle exec jekyll build
bundle exec htmlproofer --check-favicon --check-html --check-opengraph ./_site

Since site.baseurl is set as "" in my _config.yml, executing this script changes the site.baseurl to /pages/information-safety which causes breakage in site generation and htmlproofer:

Running ["ScriptCheck", "OpenGraphCheck", "LinkCheck", "FaviconCheck", "ImageCheck", "HtmlCheck"] on ["./_site"] on *.html... 

Checking 25 external links...
Ran on 11 files!

- ./_site/2015/11/20/information-safety-launch/index.html
  *  internal image /pages/information-safety/public/iso-7010-w001.svg does not exist (line 24)
  *  internally linking to /pages/information-safety/, which does not exist (line 36)
     <a href="/pages/information-safety/">Blog</a>
  *  internally linking to /pages/information-safety/, which does not exist (line 27)
     <a href="/pages/information-safety/" title="Home">Infomation Safety</a>
  *  internally linking to /pages/information-safety/2015/11/21/stamp-stpa-2016/, which does not exist 
(line 84)
... snip ...
htmlproofer 3.4.0 | Error:  HTML-Proofer found 142 failures!

I've been trying to find a workaround to disable the github-metadata gem but haven't found it. Building with JEKYLL_ENV="production" used to work for me before GitHub added github-metadata to the github-pages dependencies.

parkr commented 7 years ago

If you set baseurl: "/" and url: "", does this resolve the problem for you?

jabenninghoff commented 7 years ago

No. That makes things worse. With JEKYLL_ENV=production, I get:

- ./_site/2015/11/20/information-safety-launch/index.html
  *  http:// is an invalid URL (line 43)
     <a href="//" title="Home">Infomation Safety</a>
  *  http:// is an invalid URL (line 52)
     <a href="//">Blog</a>
...

without, I get:

- ./_site/2015/11/20/information-safety-launch/index.html
  *  http:// is an invalid URL (line 43)
     <a href="//" title="Home">Infomation Safety</a>
  *  http:// is an invalid URL (line 52)
     <a href="//">Blog</a>
...

whereas I didn't get errors before. I'm pretty sure the problem is in the code here:

        # Set `site.url` and `site.baseurl` if unset and in production mode.
        if Jekyll.env == "production"
          site.config["url"] ||= drop.url
          site.config["baseurl"] = drop.baseurl if site.config["baseurl"].to_s.empty?
        end

If I'm reading this correctly, the intent is if the baseurl is unset, then it should be rewritten. In my case, baseurl is correctly set to the empty string and gets rewritten even though it's actually set.

jabenninghoff commented 7 years ago

FYI, I was able to replicate the issue with an (almost) vanilla jekyll site using jekyll new. I modified the following files:

.bundle/config:

---
BUNDLE_PATH: "vendor/bundle"
BUNDLE_DISABLE_SHARED_GEMS: "true"

Gemfile:

source 'https://rubygems.org'

# use Kernel.require as a workaround per https://github.com/bundler/bundler/issues/5346
Kernel.require 'json'
Kernel.require 'open-uri'
version = JSON.parse(open('https://pages.github.com/versions.json').read)

ruby version['ruby']
gem 'github-pages', version['github-pages'], group: :jekyll_plugins
gem 'html-proofer', group: :htmlproofer

_config.yml:

# Welcome to Jekyll!
#
# This config file is meant for settings that affect your whole blog, values
# which you are expected to set up once and rarely edit after that. If you find
# yourself editing this file very often, consider using Jekyll's data files
# feature for the data you need to update frequently.
#
# For technical reasons, this file is *NOT* reloaded automatically when you use
# 'bundle exec jekyll serve'. If you change this file, please restart the server process.

# Site settings
# These are used to personalize your new site. If you look in the HTML files,
# you will see them accessed via {{ site.title }}, {{ site.email }}, and so on.
# You can create any custom variable you would like, and they will be accessible
# in the templates via {{ site.myvariable }}.
title: Your awesome title
email: your-email@domain.com
description: > # this means to ignore newlines until "baseurl:"
  Write an awesome description for your new site here. You can edit this
  line in _config.yml. It will appear in your document head meta (for
  Google search results) and in your feed.xml site description.
baseurl: "" # the subpath of your site, e.g. /blog
url: "" # the base hostname & protocol for your site, e.g. http://example.com
twitter_username: jekyllrb
github_username:  jekyll

# Build settings
markdown: kramdown
theme: minima
gems:
  - jekyll-feed
exclude:
  - Gemfile
  - Gemfile.lock
  - vendor

./script/cibuild:

#!/usr/bin/env bash
set -e # halt script on error

# set environment for production builds
PAGES_REPO_NWO="owner/repo" \
JEKYLL_ENV="production" \
bundle exec jekyll build
bundle exec htmlproofer --check-favicon --check-html --check-opengraph ./_site

./script/cibuild full output:


$ ./script/cibuild 
Configuration file: /Users/agamemnon/GitHub/jekyll/_config.yml
            Source: /Users/agamemnon/GitHub/jekyll
       Destination: /Users/agamemnon/GitHub/jekyll/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
   GitHub Metadata: No GitHub API authentication could be found. Some fields may be missing or have incorrect data.
                    done in 1.02 seconds.
 Auto-regeneration: disabled. Use --watch to enable.
Running ["ScriptCheck", "OpenGraphCheck", "LinkCheck", "ImageCheck", "HtmlCheck", "FaviconCheck"] on ["./_site"] on *.html... 

Checking 7 external links...
Ran on 5 files!

- ./_site/about/index.html
  *  internally linking to /pages/owner/repo/, which does not exist (line 26)
     <a class="site-title" href="/pages/owner/repo/">Your awesome title</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 40)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 13)
     <link rel="canonical" href="/pages/owner/repo/about/">
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 44)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/assets/main.css, which does not exist (line 12)
     <link rel="stylesheet" href="/pages/owner/repo/assets/main.css">
  *  internally linking to /pages/owner/repo/feed.xml, which does not exist (line 14)
     <link rel="alternate" type="application/rss+xml" title="Your awesome title" href="/pages/owner/repo/feed.xml">
  *  no favicon specified
- ./_site/index.html
  *  internally linking to /pages/owner/repo/, which does not exist (line 26)
     <a class="site-title" href="/pages/owner/repo/">Your awesome title</a>
  *  internally linking to /pages/owner/repo/, which does not exist (line 13)
     <link rel="canonical" href="/pages/owner/repo/">
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 40)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 44)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/assets/main.css, which does not exist (line 12)
     <link rel="stylesheet" href="/pages/owner/repo/assets/main.css">
  *  internally linking to /pages/owner/repo/feed.xml, which does not exist (line 14)
     <link rel="alternate" type="application/rss+xml" title="Your awesome title" href="/pages/owner/repo/feed.xml">
  *  internally linking to /pages/owner/repo/feed.xml, which does not exist (line 94)
     <a href="/pages/owner/repo/feed.xml">via RSS</a>
  *  internally linking to /pages/owner/repo/jekyll/update/2017/01/24/welcome-to-jekyll.html, which does not exist (line 88)
     <a class="post-link" href="/pages/owner/repo/jekyll/update/2017/01/24/welcome-to-jekyll.html">Welcome to Jekyll!</a>
  *  internally linking to /pages/owner/repo/test/jekyll/update/2017/01/24/welcome-to-jekyll.html, which does not exist (line 80)
     <a class="post-link" href="/pages/owner/repo/test/jekyll/update/2017/01/24/welcome-to-jekyll.html">Welcome to Jekyll!</a>
  *  no favicon specified
- ./_site/jekyll/update/2017/01/24/welcome-to-jekyll.html
  *  internally linking to /pages/owner/repo/, which does not exist (line 26)
     <a class="site-title" href="/pages/owner/repo/">Your awesome title</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 40)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 44)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/assets/main.css, which does not exist (line 12)
     <link rel="stylesheet" href="/pages/owner/repo/assets/main.css">
  *  internally linking to /pages/owner/repo/feed.xml, which does not exist (line 14)
     <link rel="alternate" type="application/rss+xml" title="Your awesome title" href="/pages/owner/repo/feed.xml">
  *  internally linking to /pages/owner/repo/jekyll/update/2017/01/24/welcome-to-jekyll.html, which does not exist (line 13)
     <link rel="canonical" href="/pages/owner/repo/jekyll/update/2017/01/24/welcome-to-jekyll.html">
  *  no favicon specified
- ./_site/test/index.html
  *  internally linking to /pages/owner/repo/, which does not exist (line 26)
     <a class="site-title" href="/pages/owner/repo/">Your awesome title</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 40)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 44)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/assets/main.css, which does not exist (line 12)
     <link rel="stylesheet" href="/pages/owner/repo/assets/main.css">
  *  internally linking to /pages/owner/repo/feed.xml, which does not exist (line 94)
     <a href="/pages/owner/repo/feed.xml">via RSS</a>
  *  internally linking to /pages/owner/repo/feed.xml, which does not exist (line 14)
     <link rel="alternate" type="application/rss+xml" title="Your awesome title" href="/pages/owner/repo/feed.xml">
  *  internally linking to /pages/owner/repo/jekyll/update/2017/01/24/welcome-to-jekyll.html, which does not exist (line 88)
     <a class="post-link" href="/pages/owner/repo/jekyll/update/2017/01/24/welcome-to-jekyll.html">Welcome to Jekyll!</a>
  *  internally linking to /pages/owner/repo/test/, which does not exist (line 13)
     <link rel="canonical" href="/pages/owner/repo/test/">
  *  internally linking to /pages/owner/repo/test/jekyll/update/2017/01/24/welcome-to-jekyll.html, which does not exist (line 80)
     <a class="post-link" href="/pages/owner/repo/test/jekyll/update/2017/01/24/welcome-to-jekyll.html">Welcome to Jekyll!</a>
  *  no favicon specified
- ./_site/test/jekyll/update/2017/01/24/welcome-to-jekyll.html
  *  External link https://talk.jekyllrb.com/ failed: got a time out (response code 0)
  *  internally linking to /pages/owner/repo/, which does not exist (line 26)
     <a class="site-title" href="/pages/owner/repo/">Your awesome title</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 40)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/about/, which does not exist (line 44)
     <a class="page-link" href="/pages/owner/repo/about/">About</a>
  *  internally linking to /pages/owner/repo/assets/main.css, which does not exist (line 12)
     <link rel="stylesheet" href="/pages/owner/repo/assets/main.css">
  *  internally linking to /pages/owner/repo/feed.xml, which does not exist (line 14)
     <link rel="alternate" type="application/rss+xml" title="Your awesome title" href="/pages/owner/repo/feed.xml">
  *  internally linking to /pages/owner/repo/test/jekyll/update/2017/01/24/welcome-to-jekyll.html, which does not exist (line 13)
     <link rel="canonical" href="/pages/owner/repo/test/jekyll/update/2017/01/24/welcome-to-jekyll.html">
  *  no favicon specified
htmlproofer 3.4.0 | Error:  HTML-Proofer found 42 failures!
jekyllbot commented 7 years ago

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.

jabenninghoff commented 7 years ago

Is there more information needed? I'm still seeing this behavior.

jekyllbot commented 7 years ago

This issue has been automatically marked as stale because it has not been commented on for at least two months.

The resources of the Jekyll team are limited, and so we are asking for your help.

If this is a bug and you can still reproduce this error on the master branch, please reply with all of the information you have about it in order to keep the issue open.

If this is a feature request, please consider whether it can be accomplished in another way. If it cannot, please elaborate on why it is core to this project and why you feel more than 80% of users would find this beneficial.

This issue will automatically be closed in two months if no further activity occurs. Thank you for all your contributions.