Setting up "amp-jekyll" plugin leads to an error

Hi,
I added amp-jekyll plugin in my Gemfile

gem “amp-jekyll”, “1.0.2”

I Placed the layout file (amp.html) to the _layouts folder

I added the following code in the footer.html

{% if page.path contains '_posts' %}
  <link rel="amphtml" href="{{ page.id | prepend: '/YOURDIR' | prepend: site.baseurl | prepend: site.url | append: '.html' }}">
{% endif %} 

And when I want to run jekyll build

I get the following error

MBP-de-Admin:inger admin$ jekyll build
Configuration file: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_config.yml
            Source: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger
       Destination: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
  Liquid Exception: undefined method `start_with?' for nil:NilClass in /_layouts/amp.html
jekyll 3.6.2 | Error:  undefined method `start_with?' for nil:NilClass

Thank you in advance for your answers

no idea if this is your problem but did you change YOURDIR?

<link rel="amphtml" href="{{ page.id | prepend: '/YOURDIR' | prepend: site.baseurl | prepend: site.url | append: '.html' }}">

Hi rdyar and thank you for your answer. Yes of course, I changed YOURDIR into the directory of my project

{% if page.path contains '_posts' %}
  <link rel="amphtml" href="{{ page.id | prepend: '/inger' | prepend: site.baseurl | prepend: site.url | append: '.html' }}">
{% endif %}

ha ha - well had to ask.

Try running jekyll build -V to do a verbose log, maybe it will show more what is going on.

1 Like

You can additionally run the build command with the --trace option to get more details on the error:

bundle exec jekyll build --trace

It’s hard to suggest a solution without seeing the site and how its set up currently…

1 Like

Hi rdyar and ashmaroli and thank you for your answers. I don’t see from where is coming the error. Browsing on internet, I can see that is kind of error is generic. Here is the trace when I ran
MBP-de-Admin:inger admin$ jekyll build -V

  Logging at level: debug
Configuration file: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_config.yml
         Requiring: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_plugins/ideal_image_slider.rb
         Requiring: jekyll-feed
         Requiring: kramdown
            Source: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger
       Destination: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
       EntryFilter: excluded /Gemfile
       EntryFilter: excluded /Gemfile.lock
       EntryFilter: excluded /Inger-Analytics-feb0aa8b73d1.json
           Reading: _posts/2017-12-30-welcome-to-jekyll.markdown
        Generating: Jekyll::AmpGenerator finished in 0.004647 seconds.
        Generating: JekyllFeed::Generator finished in 0.001888 seconds.
        Generating: Jekyll::JekyllSitemap finished in 0.000933 seconds.
         Rendering: _posts/2017-12-30-welcome-to-jekyll.markdown
  Pre-Render Hooks: _posts/2017-12-30-welcome-to-jekyll.markdown
  Rendering Liquid: _posts/2017-12-30-welcome-to-jekyll.markdown
         Requiring: rouge
  Rendering Markup: _posts/2017-12-30-welcome-to-jekyll.markdown
         Requiring: kramdown
  Rendering Layout: _posts/2017-12-30-welcome-to-jekyll.markdown
         Rendering: 404.html
  Pre-Render Hooks: 404.html
  Rendering Liquid: 404.html
  Rendering Markup: 404.html
  Rendering Layout: 404.html
         Rendering: about.md
  Pre-Render Hooks: about.md
  Rendering Liquid: about.md
  Rendering Markup: about.md
  Rendering Layout: about.md
         Rendering: index.html
  Pre-Render Hooks: index.html
  Rendering Liquid: index.html
  Rendering Markup: index.html
  Rendering Layout: index.html
         Rendering: css/style.scss
  Pre-Render Hooks: css/style.scss
  Rendering Liquid: css/style.scss
  Rendering Markup: css/style.scss
         Rendering: assets/main.scss
  Pre-Render Hooks: assets/main.scss
  Rendering Liquid: assets/main.scss
  Rendering Markup: assets/main.scss
         Rendering: amp/jekyll/update/2017/12/30/welcome-to-jekyll/index.html
  Pre-Render Hooks: amp/jekyll/update/2017/12/30/welcome-to-jekyll/index.html
  Rendering Liquid: amp/jekyll/update/2017/12/30/welcome-to-jekyll/index.html
         Requiring: rouge
  Rendering Markup: amp/jekyll/update/2017/12/30/welcome-to-jekyll/index.html
  Rendering Layout: amp/jekyll/update/2017/12/30/welcome-to-jekyll/index.html
  Liquid Exception: undefined method `start_with?' for nil:NilClass in /_layouts/amp.html
jekyll 3.6.2 | Error:  undefined method `start_with?' for nil:NilClass

I suppose that the error occurs in index.html (or may be afterwards ?)

Here is my index.html page

---
layout: default
title: Hank Quinlan, Horrible Cop
lang: fr
---
<div class="blurb">
	<h1>Hi there, I'm Hank Quinlan!</h1>
	<p>I'm best known as the horrible cop from <em>A Touch of Evil</em> Don't trust me. <a href="/about">Read more about my life...</a></p>
</div><!-- /.blurb -->

Here is my default.html

<!DOCTYPE html>

            {% include header.html %}
			
			{{ content }}

            {% include footer.html %}

and here is my footer.html

			</div><!-- /.container -->
			<footer>
	    		<ul>
	        		<li><a href="mailto:hankquinlanhub@gmail.com">email</a></li>
	        		<li><a href="https://github.com/hankquinlan">github.com/hankquinlan</a></li>
				</ul>
			</footer>
		</body>
<script>
function setActive() {
  var aObj = document.getElementsByClassName("mainMenu").getElementsByTagName('a');
  for(i=0;i<aObj.length;i++) {
    if(document.location.href.indexOf(aObj[i].href)>=0) {
      aObj[i].className='active';
    }
  }
}
window.onload = setActive;
</script>
<link rel="stylesheet" type="text/css" href="/css/style.css">
{% if page.path contains '_posts' %}
  <link rel="amphtml" href="{{ page.id | prepend: '/inger' | prepend: site.baseurl | prepend: site.url | append: '.html' }}">
{% endif %}
<script src="assets/javascript/common/google_map_api.js"></script>
</html>

Here is my _config.yml content

# 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: Inger Hair at Home at Aix en Provence
email: flamant@club-internet.fr
description: #>- # this means to ignore newlines until "baseurl:"
  This site is intended to introduce the activity of hair at home of Inger at Aix en Provence.
baseurl: "" # the subpath of your site, e.g. /blog
url: "https://localhost" # the base hostname & protocol for your site, e.g. http://example.com
#baseurl: "" # the subpath of your site, e.g. /blog
#url: "https://flamant.github.io" # the base hostname & protocol for your site, e.g. http://example.com
twitter_username: jekyllrb
github_username:  flamant

# Build settings
markdown: kramdown
theme: minima
plugins:
  - jekyll-feed

# Exclude from processing.
# The following items will not be processed, by default. Create a custom list
# to override the default setting.
exclude:
  - Gemfile
  - Gemfile.lock
  - node_modules
  - vendor/bundle/
  - vendor/cache/
  - vendor/gems/
  - vendor/ruby/
  - Inger-Analytics-feb0aa8b73d1.json
  - .gitignore
  
defaults:
  -
    scope:
      path: ""
    values:
      lang: fr
   
# Source language is optional. If set, translations to it will not be
# performed.
#source_lang: en
translations:
  en:
    callTheNumber: Contact me at
    sendmeAMail: Send me a mail
    clickHere: click here
    ingerHairStylingAtHome: INGER HAIRSTYLING SERVICE AT HOME
    home: HOME
    whoIAm: WHO I AM
    tariffs2018: TARIFFS 2018
    coveredMunicipalities: COVERED MUNICIPALITIES
    facebook: facebook
  fr:
    callTheNumber: Appelez moi au
    sendmeAMail: Envoyez moi un mail
    clickHere: cliquez ici
    ingerHairStylingAtHome: INGER COIFFURE A DOMICILE
    home: ACCUEIL
    whoIAm: QUI SUIS-JE
    tariffs2018: TARIFS 2018
    coveredMunicipalities: LES COMMUNES DESSERVIES
    facebook: facebook    

Here is the trace when I ran 

MBP-de-Admin:inger admin$ bundle exec jekyll build --trace

Configuration file: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_config.yml
            Source: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger
       Destination: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
  Liquid Exception: undefined method `start_with?' for nil:NilClass in /_layouts/amp.html
/Users/admin/.rvm/gems/ruby-2.4.1/gems/amp-jekyll-1.0.2/lib/jekyll/amp_filter.rb:19:in `block in amp_images': undefined method `start_with?' for nil:NilClass (NoMethodError)
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.1/lib/nokogiri/xml/node_set.rb:190:in `block in each'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.1/lib/nokogiri/xml/node_set.rb:189:in `upto'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/nokogiri-1.8.1/lib/nokogiri/xml/node_set.rb:189:in `each'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/amp-jekyll-1.0.2/lib/jekyll/amp_filter.rb:14:in `amp_images'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/strainer.rb:56:in `invoke'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/context.rb:86:in `invoke'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/variable.rb:78:in `block in render'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/variable.rb:76:in `each'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/variable.rb:76:in `inject'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/variable.rb:76:in `render'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/block_body.rb:109:in `render_node'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/block_body.rb:88:in `block in render'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/block_body.rb:75:in `each'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/block_body.rb:75:in `render'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/template.rb:208:in `block in render'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/template.rb:242:in `with_profiling'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/template.rb:207:in `render'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/liquid-4.0.0/lib/liquid/template.rb:220:in `render!'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/liquid_renderer/file.rb:30:in `block (2 levels) in render!'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/liquid_renderer/file.rb:42:in `measure_bytes'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/liquid_renderer/file.rb:29:in `block in render!'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/liquid_renderer/file.rb:49:in `measure_time'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/liquid_renderer/file.rb:28:in `render!'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/renderer.rb:123:in `render_liquid'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/renderer.rb:188:in `render_layout'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/renderer.rb:155:in `place_in_layouts'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/renderer.rb:85:in `render_document'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/renderer.rb:62:in `run'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/site.rb:466:in `block in render_pages'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/site.rb:464:in `each'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/site.rb:464:in `render_pages'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/site.rb:193:in `render'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/site.rb:73:in `process'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/command.rb:28:in `process_site'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/commands/build.rb:65:in `build'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/commands/build.rb:36:in `process'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/lib/jekyll/commands/build.rb:18:in `block (2 levels) in init_with_program'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `block in execute'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `each'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/mercenary-0.3.6/lib/mercenary/command.rb:220:in `execute'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/mercenary-0.3.6/lib/mercenary/program.rb:42:in `go'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/mercenary-0.3.6/lib/mercenary.rb:19:in `program'
	from /Users/admin/.rvm/gems/ruby-2.4.1/gems/jekyll-3.6.2/exe/jekyll:15:in `<top (required)>'
	from /Users/admin/.rvm/gems/ruby-2.4.1/bin/jekyll:23:in `load'
	from /Users/admin/.rvm/gems/ruby-2.4.1/bin/jekyll:23:in `<main>'
	from /Users/admin/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `eval'
	from /Users/admin/.rvm/gems/ruby-2.4.1/bin/ruby_executable_hooks:15:in `<main>'

And finaly, here is my project tree

Here is the last part of project tree

Sorry, this the one

The error stems from Line:19 in the amp_filter.rb of the amp-jekyll plugin…

Bring this issue up with the gem author and he’ll either tell you how to proceed or he’ll fix the bug in his code…

1 Like

Thanks a lot ashmaroli, and sorry, I should have seen the error earlier. But thank you for your advice to bring the issue to the author.

Previously I loaded the plugins putting the “files.rb” (like amp_filter.rb) into _plugins directory. Secondly, I deleted those "files.rb’ from the _plugins directory and used finally the loading in Gemfile. Shoudn’t I to programmatically uninstall “files.rb” (like amp_filter.rb) from a directory placed somewhere in my computer or is it also the result of the loading of gems in Gemfile ?

Hi ashmaroli,
I found the error. I had in my header.html (that I include in index.html) an image defined as following

<img width="16" height="16" alt="phone icon" scr="{{site.url}}{{site.baseurl}}/assets/images/icons/Phone_number-16px-16px.png">

This was causing the following error

MBP-de-Admin:inger admin$ bundle exec jekyll build
Configuration file: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_config.yml
            Source: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger
       Destination: /Users/admin/Documents/Perso/Site-Internet/Jekyll/inger/_site
 Incremental build: disabled. Enable with --incremental
      Generating... 
  Liquid Exception: undefined method `start_with?' for nil:NilClass in /_layouts/amp.html
jekyll 3.6.2 | Error:  undefined method `start_with?' for nil:NilClass

When I remove this img tag, there no more error.

So I tried to embed an a amp-img tag like the following

<amp-img width="16" height="16" alt="phone icon" scr="{{site.url}}{{site.baseurl}}/assets/images/icons/Phone_number-16px-16px.png" layout="responsive"></amp-img>

But I can’t see the image. I tried to remove {{site.url}}{{site.baseurl}} from the url (to have a relative path) but it doesn’t work. I did as the following link explain but I have no result.

Thank you in advance for your answers

The issue could be the missing / between {{ site.url }} and {{ site.baseurl }}
To avoid confusion use the built-in URLFilters… ( absolute_url and relative_url )

<amp-img
  width="16"
  height="16"
  alt="phone icon"
  src="{{ 'assets/images/icons/Phone_number-16px-16px.png' | absolute_url }}" 
  layout="responsive">
</amp-img>

or

<amp-img
  width="16"
  height="16"
  alt="phone icon"
  src="{{ 'assets/images/icons/Phone_number-16px-16px.png' | relative_url }}" 
  layout="responsive">
</amp-img>
1 Like

Hello ashmaroli and thank you for your answer. Thank you for your advice. But unfortunately nothing shows up, whatever url I set. I checked each time the url and the access to the image

Hello, I think that I integrate in a bad way the “amp.html” file according to the documentation (https://github.com/juusaw/amp-jekyll).

I put it in the _layouts folder but without using it somewhere else. As the images I test are in _includes/header.html file which is the following:

I can’t see the utility of the “amp.html” file. Shall I change it, integrate it somewhere, reference it somewhere ? Thank you for your answer

Have you tried pinging the plugin developer? Doesn’t appear any of us are users of it so your guess is as good as ours :nerd_face:

Hello mmistake and thank you for your answer. I pinged the plugin developer but until now no answer. I moved forward and propose a new “header.html” wich is the following : https://github.com/flamant/fileshare/blob/master/header_1.html


But I have the following errors in console

I don’t understand why it doesn’t take into account my src attributes even when I hardcode the url. I checked on browser each url that I wrote and it leads to the proper image. Thank you in advance

i know nothing about amp, but their example of an amp-image tag has a closing tag that you don’t. And even if that is not needed and it is self closing I think you need a slash at the end.

Hello rdyar and thank you for your answer, sorry but my amp-img tag has a closing tag

@flamant, have you been able to find the solution for your problem?

If you still have troubles to get it up & running, can you share your Github repository?

So I can clone it and build your Jekyll pages locally - armed with all the debugging tools I might be able to track down the issues & errors you’re struggling with.

1 Like

Hello pabloduo and thank you for your answer
It is very nice to offer your support

Here is the link to my project repository (it is the beginning of the project)

regards