6 changed files with 64 additions and 125 deletions
@ -1,70 +0,0 @@ |
|||||||
package generator |
|
||||||
|
|
||||||
import ( |
|
||||||
"encoding/json" |
|
||||||
) |
|
||||||
|
|
||||||
// GenerateStructuredData generates JSON-LD structured data
|
|
||||||
func GenerateStructuredData(siteName, siteURL, pageType, title, description, url string) string { |
|
||||||
var data map[string]interface{} |
|
||||||
|
|
||||||
switch pageType { |
|
||||||
case "article": |
|
||||||
data = map[string]interface{}{ |
|
||||||
"@context": "https://schema.org", |
|
||||||
"@type": "Article", |
|
||||||
"headline": title, |
|
||||||
"description": description, |
|
||||||
"url": url, |
|
||||||
"publisher": map[string]interface{}{ |
|
||||||
"@type": "Organization", |
|
||||||
"name": siteName, |
|
||||||
}, |
|
||||||
} |
|
||||||
case "website": |
|
||||||
data = map[string]interface{}{ |
|
||||||
"@context": "https://schema.org", |
|
||||||
"@type": "WebSite", |
|
||||||
"name": siteName, |
|
||||||
"url": siteURL, |
|
||||||
} |
|
||||||
default: |
|
||||||
data = map[string]interface{}{ |
|
||||||
"@context": "https://schema.org", |
|
||||||
"@type": "WebPage", |
|
||||||
"name": title, |
|
||||||
"url": url, |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
jsonData, _ := json.Marshal(data) |
|
||||||
return string(jsonData) |
|
||||||
} |
|
||||||
|
|
||||||
// GenerateBreadcrumbStructuredData generates breadcrumb structured data
|
|
||||||
func GenerateBreadcrumbStructuredData(items []BreadcrumbItem, siteURL string) string { |
|
||||||
breadcrumbList := make([]map[string]interface{}, len(items)) |
|
||||||
for i, item := range items { |
|
||||||
breadcrumbList[i] = map[string]interface{}{ |
|
||||||
"@type": "ListItem", |
|
||||||
"position": i + 1, |
|
||||||
"name": item.Name, |
|
||||||
"item": siteURL + item.URL, |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
data := map[string]interface{}{ |
|
||||||
"@context": "https://schema.org", |
|
||||||
"@type": "BreadcrumbList", |
|
||||||
"itemListElement": breadcrumbList, |
|
||||||
} |
|
||||||
|
|
||||||
jsonData, _ := json.Marshal(data) |
|
||||||
return string(jsonData) |
|
||||||
} |
|
||||||
|
|
||||||
// BreadcrumbItem represents a breadcrumb item
|
|
||||||
type BreadcrumbItem struct { |
|
||||||
Name string |
|
||||||
URL string |
|
||||||
} |
|
||||||
Loading…
Reference in new issue