@@ -41,6 +41,117 @@ document.addEventListener("DOMContentLoaded", function () {
4141 document . head . appendChild ( meta ) ;
4242 }
4343
44+ // Function to add canonical link
45+ function addCanonical ( url ) {
46+ const link = document . createElement ( "link" ) ;
47+ link . rel = "canonical" ;
48+ link . href = url ;
49+ document . head . appendChild ( link ) ;
50+ }
51+
52+ // Function to add search engine specific meta tags
53+ function addSearchEngineMetaTags ( path ) {
54+ // Add canonical URL
55+ addCanonical ( window . location . href ) ;
56+
57+ // Default robots directive for all pages
58+ let robotsDirective = "index, follow" ;
59+
60+ // Page-specific robots directives
61+ if ( path . includes ( "/legal/" ) ) {
62+ robotsDirective = "noindex, nofollow" ; // Block legal pages from indexing
63+ } else if ( path . includes ( "/branding/" ) ) {
64+ robotsDirective = "noindex, nofollow" ; // Keep internal branding private
65+ } else if ( path === "/404.html" ) {
66+ robotsDirective = "noindex, nofollow" ; // Don't index 404 pages
67+ } else if ( path . includes ( "/contact/" ) ) {
68+ robotsDirective = "index, follow" ; // Good for local SEO
69+ }
70+
71+ // General robots meta tag
72+ addMetaTag ( "robots" , robotsDirective ) ;
73+
74+ // Google-specific directives
75+ addMetaTag ( "googlebot" , `${ robotsDirective } , max-snippet:160, max-image-preview:large` ) ;
76+
77+ // Bing-specific directives
78+ addMetaTag ( "bingbot" , robotsDirective ) ;
79+
80+ // Additional meta tags for better indexing
81+ addMetaTag ( "referrer" , "no-referrer-when-downgrade" ) ;
82+ addMetaTag ( "format-detection" , "telephone=no" ) ;
83+
84+ // Add hreflang for English (assuming your site is English-only)
85+ const hrefLang = document . createElement ( "link" ) ;
86+ hrefLang . rel = "alternate" ;
87+ hrefLang . hreflang = "en" ;
88+ hrefLang . href = window . location . href ;
89+ document . head . appendChild ( hrefLang ) ;
90+ }
91+
92+ // Function to add JSON-LD structured data
93+ function addStructuredData ( pageMeta , path ) {
94+ const script = document . createElement ( "script" ) ;
95+ script . type = "application/ld+json" ;
96+
97+ let structuredData ;
98+
99+ if ( path === "/" ) {
100+ // Organization schema for homepage
101+ structuredData = {
102+ "@context" : "https://schema.org" ,
103+ "@type" : "Organization" ,
104+ name : "ColDog Studios" ,
105+ url : "https://www.coldogstudios.com" ,
106+ logo : "https://www.coldogstudios.com/assets/images/cds/logo/cdsLogo.png" ,
107+ description : pageMeta . description ,
108+ foundingDate : "2023" ,
109+ contactPoint : {
110+ "@type" : "ContactPoint" ,
111+ url : "https://www.coldogstudios.com/contact/" ,
112+ } ,
113+ sameAs : [ ] ,
114+ } ;
115+ } else if ( path . includes ( "/projects/" ) ) {
116+ // SoftwareApplication schema for projects
117+ structuredData = {
118+ "@context" : "https://schema.org" ,
119+ "@type" : "SoftwareApplication" ,
120+ name : pageMeta . title ,
121+ description : pageMeta . description ,
122+ url : window . location . href ,
123+ author : {
124+ "@type" : "Organization" ,
125+ name : "ColDog Studios" ,
126+ } ,
127+ publisher : {
128+ "@type" : "Organization" ,
129+ name : "ColDog Studios" ,
130+ } ,
131+ } ;
132+ } else {
133+ // WebPage schema for other pages
134+ structuredData = {
135+ "@context" : "https://schema.org" ,
136+ "@type" : "WebPage" ,
137+ name : pageMeta . title ,
138+ description : pageMeta . description ,
139+ url : window . location . href ,
140+ author : {
141+ "@type" : "Organization" ,
142+ name : "ColDog Studios" ,
143+ } ,
144+ publisher : {
145+ "@type" : "Organization" ,
146+ name : "ColDog Studios" ,
147+ } ,
148+ } ;
149+ }
150+
151+ script . textContent = JSON . stringify ( structuredData ) ;
152+ document . head . appendChild ( script ) ;
153+ }
154+
44155 // Fetch and apply metadata from metadata.json
45156 fetch ( "https://www.coldogstudios.com/metadata.json" )
46157 . then ( ( response ) => {
@@ -64,6 +175,9 @@ document.addEventListener("DOMContentLoaded", function () {
64175
65176 metaTags . forEach ( ( tag ) => addMetaTag ( tag . name , tag . content ) ) ;
66177
178+ // Add Search Engine Specific Meta Tags
179+ addSearchEngineMetaTags ( currentPath ) ;
180+
67181 // Add Social Media Meta Tags
68182 const currentUrl = window . location . href ;
69183 const siteTitle = document . title ;
@@ -80,6 +194,9 @@ document.addEventListener("DOMContentLoaded", function () {
80194 addMetaTag ( "twitter:title" , siteTitle ) ;
81195 addMetaTag ( "twitter:description" , pageMeta . description ) ;
82196 addMetaTag ( "twitter:image" , "https://www.coldogstudios.com/assets/images/cds/cdsWallpaperLite.png" ) ;
197+
198+ // Add JSON-LD structured data for better search engine understanding
199+ addStructuredData ( pageMeta , currentPath ) ;
83200 } else {
84201 console . error ( "No metadata found for the current path:" , currentPath ) ;
85202 }
0 commit comments