Forum Discussion

jferrandis's avatar
8 years ago

[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? 

 

  • This is a tricky one, the caching aspect of AMP  is what concerns me especially if comments are enabled.

     

    Do you have your community connected to Google Webmaster Tools?

     

    There is a function in the Search Console for Search Apperance/Highlighting that allows you to check how Google sees the community when it crawls the different page types, you can highlight parts of the page that are important and associate those areas with the information that is displayed so that Google can build a view of your pages and interpret them a bit better.

     

    It might be an idea to look into this.