juusaw / amp-jekyll

Build Accelerated Mobile Page versions of your Jekyll posts
MIT License
281 stars 59 forks source link

Unable to get image dimensions #24

Closed mertcangokgoz closed 2 years ago

mertcangokgoz commented 7 years ago

How to fix this, not generate _site folder

Unable to get image dimensions for "/home/mertcan/Desktop/mertcangokgoz.github.io/_site/assets/logrotateconfirmationgorsel.jpg". For local files, build the site with '--skip-initial-build' for better results. [Error: undefined method `[]' for nil:NilClass]

And modify amp.html because im not using any header or footer html

---
layout: amp
---

<!doctype html>
<html amp lang="en">

<head>
    <meta charset="UTF-8">
    <title>{{ page.title }} </title>
    <meta name="generator" content="Jekyll">
    <link href="https://plus.google.com/103305118431759296457" rel="publisher" />
    <meta name="author" content="{{ site.data.theme.name }}" />
    <meta name="distribution" content="global" />
    <meta name="robots" content="follow, all" />
    <link rel="alternate" type="application/rss+xml" title="{{ site.data.theme.name }}" href="{{site.url}}/feed" />
    <link rel="canonical" href="{{ page.canonical_url | prepend: site.baseurl | prepend: site.url }}" />
    <meta name="viewport" content="width=device-width,minimum-scale=1,initial-scale=1">
    <link href="https://maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css" rel="stylesheet" integrity="sha384-wvfXpqpZZVQGK6TAh5PVlGOfQNHSoD2xbE+QkPxCAFlNEevoEH3Sl0sibVcOQVnN" crossorigin="anonymous">
    <style amp-custom></style>
    <style amp-boilerplate>
        body {
            -webkit-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
            -moz-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
            -ms-animation: -amp-start 8s steps(1, end) 0s 1 normal both;
            animation: -amp-start 8s steps(1, end) 0s 1 normal both
        }

        @-webkit-keyframes -amp-start {
            from {
                visibility: hidden
            }
            to {
                visibility: visible
            }
        }

        @-moz-keyframes -amp-start {
            from {
                visibility: hidden
            }
            to {
                visibility: visible
            }
        }

        @-ms-keyframes -amp-start {
            from {
                visibility: hidden
            }
            to {
                visibility: visible
            }
        }

        @-o-keyframes -amp-start {
            from {
                visibility: hidden
            }
            to {
                visibility: visible
            }
        }

        @keyframes -amp-start {
            from {
                visibility: hidden
            }
            to {
                visibility: visible
            }
        }
    </style>
    <noscript><style amp-boilerplate>body{-webkit-animation:none;-moz-animation:none;-ms-animation:none;animation:none}</style></noscript>
    <script async src="https://cdn.ampproject.org/v0.js"></script>
</head>

<body>
    <div class="container">
        <div class="content">
            <h1 class="title">
                {{ page.title | amp_images }}
            </h1>
            {{ content | markdownify | amp_images }}
            <div class="footer">
                {% include footer.html %}
            </div>
        </div>
    </div>
</body>

</html>
juusaw commented 7 years ago

Hi! Does this happen to every image file in your posts? Are you running the latest version of gem or a version in _plugins folder?

moonshark commented 7 years ago

Hi @juusaw

I am having a similar problem. When it compiles I get this error:

Unable to get image dimensions for "/Users/chris/html/guide/_site/guide/images/blog-images/fort-myers.jpg". For local files, build the site with '--skip-initial-build' for better results. [Error: undefined method `[]' for nil:NilClass]

The URL for the images is correct on the page, the images are saved here and work for the non amp pages: "/Users/chris/html/guide/images/blog-images/fort-myers.jpg"

When it is compiling it's added an extra '/guide/_site' into the URL, this is why it cannot find the files. I do not use a '_site' folder. I have changed it in my config like this:

baseurl: "/guide"

I installed the gem by including it inside the gem/config files and running bundle.

Can you help me please?

Thanks Chris

mertcangokgoz commented 7 years ago

Hi @juusaw

I see the following error in the post with each photo. Sometimes it does not give an error.

Unable to get image dimensions for "/home/mertcan/Desktop/mertcangokgoz.github.io/_site/assets/telegramprotokolgorsel_vl0gf9.jpg". For local files, build the site with '--skip-initial-build' for better results. [Error: undefined method `[]' for nil:NilClass]

Jekyll Build Output

https://travis-ci.org/MertcanGokgoz/mertcangokgoz.github.io/builds/247684294

kevincolten commented 7 years ago

This does affect amp in that it leaves out the height/width attributes of images, making them invalid.

The error occurs when building the first time. If you build twice, leaving in original _site folder after the first time, the second time will work without errors.

sharu725 commented 7 years ago

I have observed this error happening to all the images which have a class mentioned in markdown. Something like this [Alt text](/path/to/image.img){: .full} But once I remove{: .full}, no error is seen.

I hope something with the amp_images filter is wrong. It may not be able to properly read images with markdown class attribute.

sharu725 commented 7 years ago

@moonshark looks like you have changed the destination in _config.yml. When I changed it, I got a lot of errors. All of them were [Error: undefined method[]' for nil:NilClass]`.

Then I found the particular ruby gem, changed the code a little bit and then it worked as expected. Usual location of the gem is C:\Ruby22\lib\ruby\gems\2.2.0\gems\amp-jekyll-1.0.2\lib\jekyll. It depends on where you have installed it.

Find the gem and change the below line (line no. 24) from src = File.join(Dir.pwd, '_site', image['src']) to src = File.join(Dir.pwd, '', image['src'])

That should work.

bradymholt commented 6 years ago

I had this issue happen on every build when cloning a Jekyll site git repository and using jekyll build --source [path] --destination [path]. Since I was using source / destination, the _site_ folder was not getting created in the source path so even sequential builds were failing. My final solution was to symlink _site_ to the source root so it would be able to find the images: https://github.com/bradymholt/geekytidbits.com/blob/master/ansible/roles/git-bare/templates/post-receive.j2#L11. I do think https://github.com/juusaw/amp-jekyll/blob/f077aa422245f49ee49a60efdb3889fda287c77d/lib/jekyll/amp_filter.rb#L24 needs to be changed to:

src = File.join(Dir.pwd, '', image['src'])