lavas-project / jekyll-pwa

Jekyll plugin for PWA
MIT License
107 stars 19 forks source link

AMP support? #13

Open samazgor opened 6 years ago

samazgor commented 6 years ago

How to integrate this for AMP pages?

xiaoiver commented 6 years ago

May I ask how do you generate your AMP pages? Using some Jekyll plugins like amp-jekyll?

samazgor commented 6 years ago

I've fixed the issue btw. Have to load jekyll-pwa-plugin.rb locally and replace lines from 134 to 144.

I m using amplify

xiaoiver commented 5 years ago

What L134-144 do is simply appending service worker registration code to <body>. So maybe I should not hard code the inject point like this.

kalwalt commented 5 years ago

Hi @xiaoiver @samazgor i'm using the plugin with amp but i need also to modify the lines from 134 to 144 because amp not allow to inject javscript code, i would to use the code on my host but not sure if i can build and install the gem on Netlify. i could do the modification in the code if someone help me a bit... :smile: I have not so much experience with Ruby and gem.

samazgor commented 5 years ago

@kalwalt here is what i did for my site.

<script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>

<amp-install-serviceworker src="https://sam.azgor.com/sw-register.js" layout="nodisplay"></amp-install-serviceworker>

dont forget to replace sam.azgor.com with your actual domain name.

kalwalt commented 5 years ago

Thank you @samazgor! Yes basically this is what i tryed but the problem is: how i import the plugin inside jekyll? i created the modified jekyll-pwa-plugin.rb but i didn't understand if i have to add to the plugin in _config.yml. i had never do this before. I am not very smart with Jekyll and Ruby :sob: For this reason i modified completely the plugin deleting the self.insert_sw_register_into_body function and his registration. You can see here my code in my fork of the gem. Basically in this way i inject the code <amp-install-serviceworker src="https://path/to/service-worker.js" layout="nodisplay"></amp-install-serviceworker> with a Liquid tag For now i only tested in my localhost but i would try soon on my website.

kalwalt commented 5 years ago

My modified version of the gem-plugin is on RubyGems here

samazgor commented 5 years ago

@kalwalt create a folder on the root and name it _plugins. Now copy your ruby file into that folder. See this

kalwalt commented 5 years ago

@samazgor i did as you explain, it works as you said... But in the end i prefer with my custom gem. Thank you for the help! Maybe it will be nice to add an option for custom code injection or disable or enable the injection of the script code....