Created by
Daniel Shaw
last modified
| // Variable definitions.
var itinerarySteps = [];
var steps = document.querySelectorAll('.c-accordion__toggle_label > span');
var descriptions = document.querySelectorAll('.c-accordion__drawer_inner p');
// Generate the itinerary list items.
for (i = 0; i < steps.length; i++) {
itinerarySteps.push({
"@type": "ListItem",
"position": i + 1,
"item":
{
"@type": "TouristAttraction",
"name": steps[i].innerText,
"description": descriptions[i].innerText
}
})
};
// Generate schema.
var schema = {
"@context": "https://schema.org",
"@type": "TouristTrip",
"name": {{Meta Title}},
"description": {{Meta Description}},
"touristType": [
"Fiordland Trip",
{{Recommended For}}
],
"subjectOf": {
"@type": "CreativeWork",
"name": {{Heading 1}},
"url": {{Page URL}}
},
"itinerary": {
"@type": "ItemList",
"numberOfItems": steps.length,
"itemListElement": itinerarySteps
}
}
// Inject script to head.
var script = document.createElement('script');
script.type = "application/ld+json";
script.text = JSON.stringify(schema);
document.querySelector('head').appendChild(script);
|