Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
200 views
in Technique[技术] by (71.8m points)

javascript - Create Json-LD with AMP custom Script

is it possible to make json with amp custom script? I have tried various ways and searched for answers on google, but always fail. is it possible?

      <script id="json" type="text/plain" target="amp-script">
                $(document).ready(function(){

                var postId = '7686767';
                var name = 'Test';
                var url = 'example.com';
                var datePublished = '2019-09-09';   
                var image = $('#image').attr('href');
                var author_name = document.getElementById("author_name").textContent; 
                var description = document.getElementById("description").textContent; 
                       var el = document.createElement('script');
                       el.type = 'application/ld+json';
                       el.text = JSON.stringify({
                      "@context": "https://schema.org/",
                      "@type": "Recipe",
                      "@id": postId,
                      "name": name,
                      "image": [
                        image
                      ],
                      "author": {
                        "@type": "Person",
                        "name": author_name
                      },
                      "datePublished": datePublished,
                      "description": description,

                      });
                document.querySelector('head').appendChild(el);
                    });
      </script>
question from:https://stackoverflow.com/questions/65886204/create-json-ld-with-amp-custom-script

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...