Open samazgor opened 6 years ago
May I ask how do you generate your AMP pages? Using some Jekyll plugins like amp-jekyll?
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
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.
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.
@kalwalt here is what i did for my site.
</head>
of your theme/ template if it's already not there. See amp referencec.<script async custom-element="amp-install-serviceworker" src="https://cdn.ampproject.org/v0/amp-install-serviceworker-0.1.js"></script>
jekyll-pwa
plugin manually, choose option 1 - Docs. <script> tag
from L134 to L144 with the following amp snippet.<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.
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 create a folder on the root and name it _plugins
. Now copy your ruby file into that folder. See this
@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....
How to integrate this for AMP pages?