G2A Many GEOs
SHARE
TWEET

faqPage

jroakes May 4th, 2020 (edited) 281 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. // Define the class for your questions and answers here.
  3. // They should be marked up in a consistent manner.
  4. var questionClass = 'question';
  5. var answerClass   = 'answer';
  6.  
  7. // Output schema to console. Set to `false` if adding via tag manager.
  8. var logOutput     = false;
  9.  
  10. (function(){
  11.  
  12.     // Build Data
  13.     var questions = Array.from(document.getElementsByClassName(questionClass)).map(function(e){return e.textContent});
  14.     var answers = Array.from(document.getElementsByClassName(answerClass)).map(function(e){return e.textContent});
  15.  
  16.     if (questions.length && answers.length){
  17.  
  18.         var data = {
  19.           "@context": "https://schema.org",
  20.           "@type": "FAQPage",
  21.           "mainEntity": []
  22.         };
  23.  
  24.         buildItem = (q,a) => {
  25.  
  26.             var item = {
  27.                 "@type": "Question",
  28.                 "name": null ,
  29.                 "acceptedAnswer": {
  30.                   "@type": "Answer",
  31.                   "text":null }
  32.                 };
  33.  
  34.             item['name'] = q;
  35.             item['acceptedAnswer']['text'] = a;
  36.  
  37.             return item;
  38.         }
  39.    
  40.         console.assert(questions.length == answers.length, {questions: questions.length, answers: answers.length, errorMsg: "Questions and Answers are not the same lengths"});
  41.  
  42.         data['mainEntity'] = questions.map(function(q,i){return buildItem(q,answers[i])});
  43.  
  44.         var script = document.createElement('script');
  45.         script.type = "application/ld+json";
  46.         script.innerHTML = JSON.stringify(data);
  47.         document.getElementsByTagName('head')[0].appendChild(script);
  48.  
  49.         if (logOutput){
  50.             console.log(script.outerHTML);
  51.         }
  52.  
  53.     }
  54.  
  55. })(document);
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top