Merge pull request #18473 from dvdksn/data-front-matter

data front matter
This commit is contained in:
David Karlsson 2023-10-19 19:54:41 +02:00 committed by GitHub
commit f8ebcc6c9f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 55 additions and 4 deletions

18
data/frontmatter.yaml Normal file
View File

@ -0,0 +1,18 @@
# this file lets you add descriptions and keywords
# to files without modifying the file.
#
# Useful for upstream pages where we don't want to
# or can't add front matter to the source!
#
# To add descriptions and keywords for a page,
# add a key with the path of the page file,
# relative to the content directory. For upstream
# page files, that's the target of the file mount.
engine/reference/builder.md:
description: |
Find all the available commands you can use in a Dockerfile
and learn how to use them, including COPY, ARG, ENTRYPOINT, and more.
keywords: |
dockerfile, docker file, docker copy, dockerfile exec, docker entrypoint,
dockerfile entrypoint, dockerfile arg, docker args, entrypoint, shell dockerfile

View File

@ -1,5 +1,5 @@
{{ $title := partial "utils/title.html" . }}
{{ $description := .Description | default .Summary }}
{{ $description := partial "utils/description.html" . }}
{{ if .IsHome }}
<title>{{ site.Title }}</title>
{{ else }}
@ -13,7 +13,7 @@
<meta name="description" content="{{ $description }}" />
<meta
name="keywords"
content="{{ .Keywords | default "docker, docker open source, docker platform, distributed applications, microservices, containers, docker containers, docker software, docker virtualization" }}"
content="{{- partial "utils/keywords.html" . -}}"
/>
<link rel="canonical" href="{{ .Permalink }}" />

View File

@ -0,0 +1,14 @@
{{ $desc := "" }}
{{ if .Description }}
{{ $desc = .Description }}
{{ else }}
{{ $desc = .Summary }}
{{ with .File }}
{{ with (index (site.Data.frontmatter) .Path) }}
{{ with .description }}
{{ $desc = strings.Replace . "\n" " " | strings.TrimRight " " }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ return $desc }}

View File

@ -0,0 +1,14 @@
{{ $keywords := "" }}
{{ if .Keywords }}
{{ $keywords = .Keywords }}
{{ else }}
{{ $keywords = "docker, docker open source, docker platform, distributed applications, microservices, containers, docker containers, docker software, docker virtualization" }}
{{ with .File }}
{{ with (index (site.Data.frontmatter) .Path) }}
{{ with .keywords }}
{{ $keywords = strings.Replace . "\n" " " | strings.TrimRight " " }}
{{ end }}
{{ end }}
{{ end }}
{{ end }}
{{ return $keywords }}

View File

@ -3,8 +3,13 @@
{{ $title = .LinkTitle }}
{{ else }}
{{ $title = index (findRE `# .*` .RawContent) 0 | strings.TrimLeft "# " }}
{{ if not $title }}
{{ with .File }}
{{ with .File }}
{{ with (index (site.Data.frontmatter) .Path) }}
{{ with .title }}
{{ $title = . }}
{{ end }}
{{ end }}
{{ if not $title }}
{{ $title = strings.ReplaceRE "[-_]" " " .TranslationBaseName }}
{{ end }}
{{ end }}