Created
December 22, 2017 00:50
-
-
Save rwatts3/ac1197ae4ed14eda319ca394589c5d8e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
component output="false" displayname="Schema" hint="Functions to build valid schema.org" { | |
public function buildGeo(required details) { | |
local.data = arguments.details; | |
local.schemaObj = {}; | |
local.schemaObj = { | |
"geo" = { | |
"@type" = "GeoCoordinates", | |
"latitude" = local.data.latitude, | |
"longitude" = local.data.longitude | |
} | |
}; | |
return local.schemaObj; | |
} | |
public function buildPostalAddress(required details) { | |
local.data = arguments.details; | |
local.schemaObj = {}; | |
local.schemaObj = { | |
"address" = { | |
"@type" = "PostalAddress", | |
"addressLocality" = local.data.city, | |
"addressRegion" = local.data.state, | |
"postalCode" = local.data.zip, | |
// "addressCountry" = "", | |
"streetAddress" = local.data.addr1 | |
} | |
}; | |
return local.schemaObj; | |
} | |
public function buildSchema(required details, required type="listings") { | |
local.data = arguments.details.detail.data.overviewQry; | |
local.schemaObj = {}; | |
if (arguments.type eq 'listings') { | |
local.schemaObj = { | |
"@context" = "http://schema.org", | |
"@type" = "LocalBusiness", | |
"name" = local.data.company, | |
"telephone" = local.data.phone, | |
"description" = local.data.listing, | |
"url" = local.data.url, | |
"image" = local.data.images[1][1].url, | |
"geo" = buildGeo(local.data), | |
"address" = buildPostalAddress(local.data) | |
}; | |
} else if (arguments.type eq 'events') { | |
local.schemaObj = { | |
}; | |
} | |
return local.schemaObj; | |
} | |
public function renderSchema(required details, required type="listings") { | |
local.results = ''; | |
local.schemaObj = {}; | |
local.schemaObj = buildSchema(arguments.details, arguments.type); | |
local.results = '<script type="application/ld+json">#serializeJSON(local.schemaObj)#</script>'; | |
return local.results; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment