From 99c4c54cb51094107d64c122d2745de77125a987 Mon Sep 17 00:00:00 2001 From: Qiming Date: Tue, 26 Jun 2018 03:25:21 +0800 Subject: [PATCH] [WIP] Attempt to consolidate YAML files (#8965) This is an attempt to consolidate YAML files so that: - They can remain untouched when we moving the documents around; - Contributors do not have to change the test cases each time a documentation is moved; - We can encourage referencing the existing YAMLs from different concept or task pages when possible. --- .../application}/deployment.yaml | 0 .../run-stateless-application-deployment.md | 4 +- layouts/shortcodes/codenew.html | 38 +++++++++++++++++++ test/examples_test.go | 4 +- 4 files changed, 43 insertions(+), 3 deletions(-) rename content/en/{docs/tasks/run-application => artifacts/application}/deployment.yaml (100%) create mode 100644 layouts/shortcodes/codenew.html diff --git a/content/en/docs/tasks/run-application/deployment.yaml b/content/en/artifacts/application/deployment.yaml similarity index 100% rename from content/en/docs/tasks/run-application/deployment.yaml rename to content/en/artifacts/application/deployment.yaml diff --git a/content/en/docs/tasks/run-application/run-stateless-application-deployment.md b/content/en/docs/tasks/run-application/run-stateless-application-deployment.md index 61b2f08f3d..27b9aafb89 100644 --- a/content/en/docs/tasks/run-application/run-stateless-application-deployment.md +++ b/content/en/docs/tasks/run-application/run-stateless-application-deployment.md @@ -36,12 +36,12 @@ You can run an application by creating a Kubernetes Deployment object, and you can describe a Deployment in a YAML file. For example, this YAML file describes a Deployment that runs the nginx:1.7.9 Docker image: -{{< code file="deployment.yaml" >}} +{{< codenew file="application/deployment.yaml" >}} 1. Create a Deployment based on the YAML file: - kubectl apply -f https://k8s.io/docs/tasks/run-application/deployment.yaml + kubectl apply -f https://k8s.io/docs/artifacts/application/deployment.yaml 1. Display information about the Deployment: diff --git a/layouts/shortcodes/codenew.html b/layouts/shortcodes/codenew.html new file mode 100644 index 0000000000..2224065aed --- /dev/null +++ b/layouts/shortcodes/codenew.html @@ -0,0 +1,38 @@ +{{ $p := .Page }} +{{ $file := .Get "file" }} +{{ $codelang := .Get "language" | default (path.Ext $file | strings.TrimPrefix ".") }} +{{ $fileDir := path.Split $file }} +{{ $bundlePath := path.Join .Page.Dir $fileDir.Dir }} +{{ $filename := printf "/content/%s/artifacts/%s" .Page.Lang $file | safeURL }} +{{ $ghlink := printf "https://%s/blob/master%s" .Page.Site.Params.githubWebsiteRepo $filename | safeURL }} +{{/* First assume this is a bundle and the file is inside it. */}} +{{ $resource := $p.Resources.GetMatch (printf "%s*" $file ) }} +{{ with $resource }} +{{ $.Scratch.Set "content" .Content }} +{{ else }} +{{/* Read the file relative to the content root. */}} +{{ $resource := readFile $filename}} +{{ with $resource }}{{ $.Scratch.Set "content" . }}{{ end }} +{{ end }} +{{ if not ($.Scratch.Get "content") }} +{{ errorf "[%s] %q not found in %q" $p.Site.Language.Lang $fileDir.File $bundlePath }} +{{ end }} +{{ with $.Scratch.Get "content" }} + + + + + + + + + + + +
+ {{ with $ghlink }}{{ end }} + {{ $file }} + {{ if $ghlink }}{{ end }} + +
{{ highlight . $codelang "" }}
+{{ end }} diff --git a/test/examples_test.go b/test/examples_test.go index ee744ec1e0..a72eb50132 100644 --- a/test/examples_test.go +++ b/test/examples_test.go @@ -440,8 +440,10 @@ func TestExampleObjectSchemas(t *testing.T) { "redis-pod": {&api.Pod{}}, "redis-service": {&api.Service{}}, }, - "docs/tasks/run-application": { + "artifacts/application": { "deployment": {&extensions.Deployment{}}, + }, + "docs/tasks/run-application": { "deployment-patch-demo": {&extensions.Deployment{}}, "deployment-scale": {&extensions.Deployment{}}, "deployment-update": {&extensions.Deployment{}},