From 2934b4b4da3e9bbae15b21e2f7973cb6bbb59009 Mon Sep 17 00:00:00 2001 From: lucperkins Date: Wed, 20 Jun 2018 15:55:16 -0700 Subject: [PATCH] Auto _headers file generation logic --- config.toml | 28 ++++++++++++++++++++++++--- layouts/index.headers | 38 +++++++++++++++++++++++++++++++++++++ netlify.toml | 3 +-- netlify_noindex_headers.txt | 3 --- 4 files changed, 64 insertions(+), 8 deletions(-) create mode 100644 layouts/index.headers delete mode 100644 netlify_noindex_headers.txt diff --git a/config.toml b/config.toml index 08ad4bff74b97..61ef3b4d2cf6b 100644 --- a/config.toml +++ b/config.toml @@ -31,14 +31,27 @@ date = ["date", ":filename", "publishDate", "lastmod"] # Be explicit about the output formats. We (currently) only want an RSS feed for the home page. [outputs] -home = [ "HTML", "RSS"] +home = [ "HTML", "RSS", "HEADERS" ] page = [ "HTML"] section = [ "HTML"] +# Add a "text/netlify" media type for auto-generating the _headers file +[mediaTypes] +[mediaTypes."text/netlify"] +suffix = "" +delimiter = "" + [outputFormats] [outputFormats.RSS] baseName = "feed" +# _headers file output (uses the template at layouts/index.headers) +[outputFormats.HEADERS] +mediatype = "text/netlify" +baseName = "_headers" +isPlainText = true +notAlternative = true + [params] time_format_blog = "Monday, January 02, 2006" @@ -56,6 +69,17 @@ currentUrl = "https://kubernetes.io/docs/home/" nextUrl = "http://kubernetes-io-vnext-staging.netlify.com/" githubWebsiteRepo = "github.com/kubernetes/website" +[params.pushAssets] +css = [ + "callouts", + "styles", + "custom-jekyll/tags" +] +js = [ + "custom-jekyll/tags", + "script" +] + [[params.versions]] fullversion = "v1.10.3" version = "v1.10" @@ -91,7 +115,6 @@ githubbranch = "v1.6.8" docsbranch = "release-1.6" url = "https://v1-6.docs.kubernetes.io" - # Language definitions. [languages] @@ -108,4 +131,3 @@ languageName ="Chinese" weight = 2 contentDir = "content/cn" - diff --git a/layouts/index.headers b/layouts/index.headers new file mode 100644 index 0000000000000..3c7e9913b79aa --- /dev/null +++ b/layouts/index.headers @@ -0,0 +1,38 @@ +{{- $cssFilesFromConfig := .Site.Params.pushAssets.css -}} +{{- $jsFilesFromConfig := .Site.Params.pushAssets.js -}} +{{- $pages := .Site.RegularPages -}} +/* + X-Robots-Tag: noindex + Link: ; rel=preload; as=image + {{- range $cssFilesFromConfig -}} + {{- $cssUrl := printf "/css/%s.css" . }} + Link: <{{ $cssUrl }}>; rel=preload; as=style + {{- end -}} + {{- range $jsFilesFromConfig -}} + {{- $jsUrl := printf "/js/%s.js" . }} + Link: <{{ $jsUrl }}>; rel=preload; as=script + {{- end -}} +{{- range $pages }} +{{- if or (.Params.deprecated) (eq .Params.class "gridPage") (.Params.case_study_styles) (.Params.css) (.Params.js) }} +{{ .URL }} + {{- if .Params.deprecated }} + Link: ; rel=preload; as=style + {{- end -}} + {{- if eq .Params.class "gridPage" }} + Link: ; rel=preload; as=style + {{- end -}} + {{- if .Params.case_study_styles }} + Link: ; rel=preload; as=style + {{- end -}} + {{- with .Params.css -}} + {{- range (split . ",") }} + Link: <{{ trim . " " }}>; rel=preload; as=style + {{- end -}} + {{- end -}} + {{- with .Params.js -}} + {{- range (split . ",") }} + Link: <{{ trim . " " }}>; rel=preload; as=script + {{- end -}} + {{- end -}} +{{- end }} +{{- end -}} \ No newline at end of file diff --git a/netlify.toml b/netlify.toml index 904f6956c9b0f..13704d0eb274a 100644 --- a/netlify.toml +++ b/netlify.toml @@ -1,7 +1,6 @@ [build] -# This default build command adds the robots noindex directive to the site headers publish = "public" -command = "hugo && cp netlify_noindex_headers.txt public/_headers" +command = "hugo" [context.production.environment] HUGO_BASEURL = "https://kubernetes.io/" diff --git a/netlify_noindex_headers.txt b/netlify_noindex_headers.txt deleted file mode 100644 index c45a1be4250c0..0000000000000 --- a/netlify_noindex_headers.txt +++ /dev/null @@ -1,3 +0,0 @@ -# Prevent bots from indexing site -/* - X-Robots-Tag: noindex