diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html index 4dddd9cd221..4a3a9a0512d 100644 --- a/layouts/_default/baseof.html +++ b/layouts/_default/baseof.html @@ -35,6 +35,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..30ec02f105f --- /dev/null +++ b/layouts/partials/pages-json-cache.html @@ -0,0 +1,13 @@ +{{- $url := "https://docs.datadoghq.com/pages.json" -}} + +{{- $res := resources.GetRemote $url -}} +{{- if not $res -}} + {{- errorf "Failed to fetch remote JSON: %s" $url -}} +{{- end -}} + +{{- $pages := $res | transform.Unmarshal -}} +{{- if not $pages -}} + {{- errorf "Failed to unmarshal JSON from: %s" $url -}} +{{- end -}} + +{{- return $pages -}}