diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 4dddd9cd221..8e8ea896399 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -28,6 +28,10 @@ {{- if and (ne $.Params.disable_opengraph_meta_tags true) .File -}} {{- partial "meta.html" . -}} {{- end -}} + {{- $mdURL := partialCached "page-agent-hint.html" (dict "ctx" .) .RelPermalink -}} + {{- with $mdURL -}} + + {{- end -}} {{- $bodyClass := $.Scratch.Get "bodyClass" -}} {{- $customClass := $.Params.customclass -}} @@ -35,6 +39,9 @@ + {{- with partialCached "page-agent-hint.html" (dict "ctx" .) .RelPermalink -}} + + {{- end -}}
diff --git a/layouts/partials/page-agent-hint.html b/layouts/partials/page-agent-hint.html new file mode 100644 index 00000000000..a73b0d0d184 --- /dev/null +++ b/layouts/partials/page-agent-hint.html @@ -0,0 +1,14 @@ +{{- $ctx := .ctx -}} +{{- $mdURL := "" -}} + +{{- $rel := $ctx.RelPermalink -}} +{{- if and $rel (ne $rel "/") -}} +{{- $trimmed := strings.TrimRight "/" $rel | strings.TrimLeft "/" -}} +{{- $candidate := printf "https://docs.datadoghq.com/%s.md" $trimmed -}} +{{- $pages := partialCached "pages-json-cache.html" "pages.json" -}} +{{- if index $pages $candidate -}} +{{- $mdURL = $candidate -}} +{{- end -}} +{{- end -}} + +{{- return $mdURL -}} diff --git a/layouts/partials/pages-json-cache.html b/layouts/partials/pages-json-cache.html new file mode 100644 index 00000000000..01f6c7012f6 --- /dev/null +++ b/layouts/partials/pages-json-cache.html @@ -0,0 +1,13 @@ +{{- $url := "https://docs.datadoghq.com/pages.json" -}} + +{{- $res := resources.GetRemote $url -}} +{{- with $res.Err -}} + {{- errorf "Failed to fetch remote JSON %s: %s" $url . -}} +{{- end -}} + +{{- $pages := $res | transform.Unmarshal -}} +{{- if not $pages -}} + {{- errorf "Failed to unmarshal JSON from: %s" $url -}} +{{- end -}} + +{{- return $pages -}}