Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ summaryLength = 30
buildFuture = true
relativeURLs = true

enableGitInfo = true

[taxonomies]
sectors = "sector"

Expand Down
18 changes: 18 additions & 0 deletions themes/c8ydocs/layouts/partials/breadcrumbs-ld.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{{- $scratch := newScratch -}}
{{- $scratch.Set "items" slice -}}
{{- $currentPage := . -}}
{{- range seq 1 10 -}}
{{- if $currentPage -}}
{{- $name := "" -}}
{{- if $currentPage.IsHome -}}
{{- $name = "Home" -}}
{{- else -}}
{{- $name = $currentPage.Title -}}
{{- end -}}
{{- $scratch.Set "items" (slice (dict "name" $name "item" $currentPage.Permalink) | append ($scratch.Get "items")) -}}
{{- $currentPage = $currentPage.Parent -}}
{{- else -}}
{{- break -}}
{{- end -}}
{{- end -}}
{{- return ($scratch.Get "items") -}}
47 changes: 47 additions & 0 deletions themes/c8ydocs/layouts/partials/get-page-image.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
{{- $page := .page -}}
{{- $defaultImage := .defaultImage -}}
{{- $image := "" -}}

{{- with $page.Params.image -}}
{{- $image = . -}}
{{- else -}}
{{- $contentToScan := $page.Content -}}

{{- /* Check for headless bundle and aggregate child content */ -}}
{{- if $page.File -}}
{{- $bundle := printf "%s-%s" $page.File.BaseFileName "bundle" -}}
{{- $headless := $page.Site.GetPage $bundle -}}
{{- if $headless -}}
{{- $reusablePages := sort ($headless.Resources.ByType "page") ".Params.weight" -}}
{{- range $reusablePages -}}
{{- $contentToScan = printf "%s\n%s" $contentToScan .Content -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- $re_markdown_image := `!\[.*?\]\((.*?)\)` -}}
{{- $firstMarkdownImage := findRE $re_markdown_image $contentToScan 1 -}}
{{- if gt (len $firstMarkdownImage) 0 -}}
{{- $imagePath := replaceRE $re_markdown_image "$1" (index $firstMarkdownImage 0) -}}
{{- $image = $imagePath -}}
{{- else -}}
{{- $re_html_image := `<img[^>]*src=["']([^"']+)["'][^>]*>` -}}
{{- $firstHtmlImage := findRE $re_html_image $contentToScan 1 -}}
{{- if gt (len $firstHtmlImage) 0 -}}
{{- $imagePath := replaceRE $re_html_image "$1" (index $firstHtmlImage 0) -}}
{{- $image = $imagePath -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- if not $image -}}
{{- if $defaultImage -}}
{{- $image = $defaultImage -}}
{{- end -}}
{{- end -}}

{{- if $image -}}
{{- return ($image | absURL) -}}
{{- else -}}
{{- return -}}
{{- end -}}
1 change: 1 addition & 0 deletions themes/c8ydocs/layouts/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -68,4 +68,5 @@
-->
<script type="text/javascript" src="https://www.bugherd.com/sidebarv2.js?apikey=wmzmiqkyn8isokbvj4xd6g" async="true"></script>

{{ partial "json-ld.html" . }}
</head>
168 changes: 168 additions & 0 deletions themes/c8ydocs/layouts/partials/json-ld.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,168 @@
{{- $data := newScratch -}}

{{- if .IsHome -}}
{{- $hasPart := slice -}}
{{- $sortedsections := sort .Site.Taxonomies.sector ".Page.Params.weight" -}}
{{- range $element := $sortedsections -}}
{{- $hasPart = $hasPart | append (dict "@type" "WebPage" "name" .Page.Title "url" .Page.Permalink) -}}
{{- end -}}
{{- $siteDescription := partial "replace-placeholders.html" (dict "text" .Site.Params.description "siteParams" .Site.Params) -}}

{{- /* Get site-wide default image from params or a hardcoded path */ -}}
{{- $homeImage := "" -}}
{{- with .Site.Params.default_schema_image -}}
{{- $homeImage = . -}}
{{- else -}}
{{- $homeImage = "images/cumulocity-docs-web.jpg" -}}
{{- end -}}

{{- $data.Set "page" (dict
"@context" "https://schema.org"
"@type" "WebSite"
"url" .Site.BaseURL
"name" .Site.Title
"description" $siteDescription
"image" ($homeImage | absURL)
"inLanguage" .Site.LanguageCode
"publisher" (dict "@type" "Organization" "name" (.Site.Params.publisher_name | default "Cumulocity GmbH") "logo" (dict "@type" "ImageObject" "url" (.Site.Params.logo | absURL)))
"hasPart" $hasPart
)
-}}
{{- else if or (eq .Kind "section") (eq .Kind "taxonomy") (eq .Kind "term") -}}
{{- $hasPart := slice -}}
{{- range .Pages -}}
{{- $hasPart = $hasPart | append (dict "@type" "TechArticle" "headline" .Title "url" .Permalink) -}}
{{- end -}}
{{- $breadcrumbItems := partial "breadcrumbs-ld.html" . -}}
{{- $breadcrumbList := slice -}}
{{- range $index, $item := $breadcrumbItems -}}
{{- $breadcrumbList = $breadcrumbList | append (dict "@type" "ListItem" "position" (add $index 1) "name" $item.name "item" $item.item) -}}
{{- end -}}

{{- $plainContent := .Content | plainify -}}
{{- $extractedDescription := "" -}}
{{- $paragraphs := split $plainContent "\n\n" -}}
{{- if gt (len $paragraphs) 0 -}}
{{- $firstParagraph := index $paragraphs 0 -}}
{{- if and (gt (len $firstParagraph) 0) (lt (len $firstParagraph) 100) (gt (len $paragraphs) 1) -}}
{{- $secondParagraph := index $paragraphs 1 -}}
{{- $extractedDescription = printf "%s\n\n%s" $firstParagraph $secondParagraph -}}
{{- else -}}
{{- $extractedDescription = $firstParagraph -}}
{{- end -}}
{{- end -}}

{{- $pageImage := partial "get-page-image.html" (dict "page" . "defaultImage" .Site.Params.default_schema_image) -}}

{{- $pageMap := (dict
"@context" "https://schema.org"
"@type" "CollectionPage"
"name" .Title
"description" (truncate 320 $extractedDescription)
"url" .Permalink
"inLanguage" .Site.LanguageCode
"author" (dict "@type" "Organization" "name" (.Site.Params.author_name | default .Site.Title))
"publisher" (dict "@type" "Organization" "name" (.Site.Params.publisher_name | default "Cumulocity GmbH") "logo" (dict "@type" "ImageObject" "url" (.Site.Params.logo | absURL)))
"hasPart" $hasPart
"breadcrumb" (dict "@type" "BreadcrumbList" "itemListElement" $breadcrumbList)
)
-}}
{{- if $pageImage -}}
{{- $pageMap = merge $pageMap (dict "image" $pageImage) -}}
{{- end -}}
{{- $data.Set "page" $pageMap -}}

{{- else if eq .Kind "page" -}}
{{- $breadcrumbItems := partial "breadcrumbs-ld.html" . -}}
{{- $breadcrumbList := slice -}}
{{- range $index, $item := $breadcrumbItems -}}
{{- $breadcrumbList = $breadcrumbList | append (dict "@type" "ListItem" "position" (add $index 1) "name" $item.name "item" $item.item) -}}
{{- end -}}
{{- $extractedDescription := "" -}}
{{- $plainContent := .Content | plainify -}}
{{- $paragraphs := split $plainContent "\n\n" -}}

{{- if eq .Layout "bundle" -}}
{{- if .File -}} {{/* Check if .File exists before accessing it */}}
{{- $bundleName := printf "%s-%s" .File.BaseFileName "bundle" -}} {{/* Corrected variable name here */}}
{{- $headless := .Site.GetPage $bundleName -}}
{{- if $headless -}}
{{- $reusablePages := sort ($headless.Resources.ByType "page") ".Params.weight" -}}
{{- if gt (len $reusablePages) 0 -}}
{{- $firstReusablePage := index $reusablePages 0 -}}
{{- $plainContent = $firstReusablePage.Content | plainify -}}
{{- $paragraphs = split $plainContent "\n\n" -}}
{{- end -}}
{{- end -}}
{{- end -}}
{{- end -}}

{{- if gt (len $paragraphs) 0 -}}
{{- $firstParagraph := index $paragraphs 0 -}}
{{- if and (gt (len $firstParagraph) 0) (lt (len $firstParagraph) 100) (gt (len $paragraphs) 1) -}}
{{- $secondParagraph := index $paragraphs 1 -}}
{{- $extractedDescription = printf "%s\n\n%s" $firstParagraph $secondParagraph -}}
{{- else -}}
{{- $extractedDescription = $firstParagraph -}}
{{- end -}}
{{- end -}}

{{- /* Call the new partial for image extraction */ -}}
{{- $pageImage := partial "get-page-image.html" (dict "page" . "defaultImage" .Site.Params.default_schema_image) -}}

{{- $datePublished := "" -}}
{{- if .Date -}}
{{- $datePublished = .Date.Format "2006-01-02T15:04:05Z07:00" -}}
{{- else if .PublishDate -}}
{{- $datePublished = .PublishDate.Format "2006-01-02T15:04:05Z07:00" -}}
{{- else if .Lastmod -}}
{{- $datePublished = .Lastmod.Format "2006-01-02T15:04:05Z07:00" -}}
{{- end -}}

{{- $dateModified := "" -}}
{{- if .Lastmod -}}
{{- $dateModified = .Lastmod.Format "2006-01-02T15:04:05Z07:00" -}}
{{- else if .Date -}}
{{- $dateModified = .Date.Format "2006-01-02T15:04:05Z07:00" -}}
{{- end -}}

{{- $pageMap := dict
"@context" "https://schema.org"
"@type" "TechArticle"
"headline" .Title
"description" (truncate 320 (.Description | default $extractedDescription))
"mainEntityOfPage" (dict "@type" "WebPage" "@id" .Permalink)
"author" (dict "@type" "Organization" "name" (.Site.Params.author_name | default .Site.Title))
"publisher" (dict "@type" "Organization" "name" (.Site.Params.publisher_name | default "Cumulocity GmbH") "logo" (dict "@type" "ImageObject" "url" (.Site.Params.logo | absURL)))
"breadcrumb" (dict "@type" "BreadcrumbList" "itemListElement" $breadcrumbList)
}}
{{- if $datePublished -}}
{{- $pageMap = merge $pageMap (dict "datePublished" $datePublished) -}}
{{- end -}}
{{- if $dateModified -}}
{{- $pageMap = merge $pageMap (dict "dateModified" $dateModified) -}} {{/* This is the only change */}}
{{- end -}}

{{- if $pageImage -}}
{{- $pageMap = merge $pageMap (dict "image" $pageImage) -}}
{{- end -}}
{{- $data.Set "page" $pageMap -}}

{{- with .Params.sector -}}
{{- $sectorName := index . 0 -}}
{{- $sectorPage := $.Site.GetPage (printf "/sector/%s" $sectorName) -}}
{{- if $sectorPage -}}
{{- $data.SetInMap "page" "articleSection" $sectorPage.Title -}}
{{- end -}}
{{- end -}}
{{- with .Parent -}}
{{- $isPartOf := dict "@type" "CollectionPage" "name" .Title "url" .Permalink -}}
{{- $data.SetInMap "page" "isPartOf" $isPartOf -}}
{{- end -}}
{{- end -}}

{{- if $data.Get "page" -}}
<script type="application/ld+json">
{{- $data.Get "page" | jsonify (dict "indent" " ") | safeJS -}}
</script>
{{- end -}}
8 changes: 8 additions & 0 deletions themes/c8ydocs/layouts/partials/replace-placeholders.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{{- define "replacePlaceholders" -}}
{{- $text := .text -}}
{{- $siteParams := .siteParams -}}
{{- $text = replace $text "var-company-sag" ($siteParams.company_sag | default "") -}}
{{- $text = replace $text "var-enterprise-tenant" ($siteParams.enterprise_tenant | default "") -}}
{{- $text = replace $text "var-product-c8y-iot" ($siteParams.product_c8y_iot | default "") -}}
{{- return $text -}}
{{- end -}}