jferrandis
9 years agoExpert
[SEO] structured content with LD-JSON
Here is a bunch of code i want to share
I had to implement microdata in community and looking in google specifiction i saw LD-JSON format which sounds to be easier to manipulate than microformat
https://developers.google.com/search/docs/guides/intro-structured-data
So here is my code
<#if config.getString("phase", "prod") == "stage">
<#assign endpoint="http://community.stage.brandname.com/" />
<#else>
<#assign endpoint="http://communaute.brandname.com/" />
<@liaMarkupCache ttl="6000000" variation="node" anonymousOnly="false" />
</#if>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Organization",
"name": "${text.format('brandName')}",
"logo": {
"@type": "ImageObject",
"url": "${asset.get("/html/assets/logo_inline.png")}",
"width": 600,
"height": 60
},
"url": "${endpoint}",
"sameAs": [
"https://www.facebook.com/brandName",
"https://www.youtube.com/user/brandName"
]
}
</script>
<#if page.name="CommunityPage">
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "WebSite",
"name": "${coreNode.title}",
"url": "${endpoint}",
"potentialAction": {
"@type": "SearchAction",
"target": "${endpoint}/t5/forums/searchpage/tab/message?q={search_term_string}",
"query-input": "required name=search_term_string"
}
}
</script>
<#else>
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "BreadcrumbList",
"itemListElement": [
<#list page.content.nav.breadcrumb.crumbs as crumb>
{
"@type": "ListItem",
"position": ${crumb?counter},
"item": {
"@id": "${crumb.url}",
"name": "${crumb.text}"
}
}<#if crumb?has_next>,</#if></#list>]
}
</script>
</#if>
<#if page.name="BlogArticlePage">
<#-- -->
<#-- getData : call to the macros-->
<#-- -->
<#include "queryhandler"/>
<#assign messageDataQuery = rest("2.0","/search?q=" + "SELECT * FROM messages WHERE id = '${page.context.thread.topicMessage.uniqueId}'"?url) />
<#-- call to a macro which render imageURL and image Caption according to dimensions -->
<@getMessageImage imageDimensions="" messageId=page.context.thread.topicMessage.uniqueId />
<script type="application/ld+json">
{
"@context": "http://schema.org",
"@type": "Article",
"mainEntityOfPage": {
"@type": "WebPage",
"@id": "${page.context.thread.topicMessage.webUi.url}"
},
"headline": "${page.context.thread.topicMessage.subject}",
<#if messageImageURL?? && messageImageURL!="">
"image": {
"@type": "ImageObject",
"url": "${endpoint}${messageImageURL}",
"height": ${messageImageHeight},
"width": ${messageImageWidth}
},
</#if>
"datePublished": "${page.context.thread.topicMessage.postDate?datetime}",
"dateModified": "${messageDataQuery.data.items[0].current_revision.last_edit_time?number_to_datetime}",
"author": {
"@type": "Person",
"name": "${page.context.thread.topicMessage.author.login}"
},
"publisher": {
"@type": "Organization",
"name": "${text.format('brandName')}",
"logo": {
"@type": "ImageObject",
"url": "${asset.get("/html/assets/logo_inline.png")}",
"width": 600,
"height": 60
}
},
"description": "${messageDataQuery.data.items[0].teaser}"
}
</script>
</#if>this is working good but for blogArticles, google seems to require AMP-page. Looking for the AMP specifications, it looks hard to respect them in lithium.
Did someone tried to do so?