From 787e703fa05654a58e71e3ca3645803221eb455f Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Thu, 8 Jul 2021 18:11:32 +0200 Subject: [PATCH 1/3] Add `api-reference` shortcode --- layouts/shortcodes/api-reference.html | 7 +++++++ 1 file changed, 7 insertions(+) create mode 100644 layouts/shortcodes/api-reference.html diff --git a/layouts/shortcodes/api-reference.html b/layouts/shortcodes/api-reference.html new file mode 100644 index 00000000000..6fdceef8385 --- /dev/null +++ b/layouts/shortcodes/api-reference.html @@ -0,0 +1,7 @@ +{{ $base := "docs/reference/kubernetes-api" }} +{{ $pageArg := .Get "page" }} +{{ $anchorArg := .Get "anchor" }} +{{ $textArg := .Get "text" }} +{{ $page := site.GetPage "page" (printf "%s/%s" $base $pageArg) }} +{{ $metadata := $page.Params.api_metadata }} +{{if $textArg}}{{ $textArg }}{{else if $anchorArg}}{{ $anchorArg }}{{else}}{{ $metadata.kind }}{{end}} \ No newline at end of file From 216b34a3d10ad82c1b76eb75db29aa9399da5322 Mon Sep 17 00:00:00 2001 From: Philippe Martin Date: Thu, 8 Jul 2021 18:11:57 +0200 Subject: [PATCH 2/3] Update script to check api-reference links --- scripts/linkchecker.py | 64 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 63 insertions(+), 1 deletion(-) diff --git a/scripts/linkchecker.py b/scripts/linkchecker.py index 6a5ea7d089e..5bc63e1d7fb 100755 --- a/scripts/linkchecker.py +++ b/scripts/linkchecker.py @@ -35,6 +35,8 @@ # + /docs/bar : is a redirect entry, or # + /docs/bar : is something we don't understand # +# + {{ < api-reference page="" anchor="" ... > }} +# + {{ < api-reference page="" > }} import argparse import glob @@ -72,7 +74,8 @@ ARGS = None RESULT = {} # Cached redirect entries REDIRECTS = {} - +# Cached anchors in target pages +ANCHORS = {} def new_record(level, message, target): """Create new checking record. @@ -330,6 +333,44 @@ def check_target(page, anchor, target): msg = "Link may be wrong for the anchor [%s]" % anchor return new_record("WARNING", msg, target) +def check_anchor(target_page, anchor): + """Check if an anchor is defined in the target page + + :param target_page: The target page to check + :param anchor: Anchor string to find in the target page + """ + if target_page not in ANCHORS: + try: + with open(target_page, "r") as f: + data = f.readlines() + except Exception as ex: + print("[Error] failed in reading markdown file: " + str(ex)) + return + content = "\n".join(strip_comments(data)) + anchor_pattern1 = r" Date: Tue, 14 Sep 2021 15:51:58 +0200 Subject: [PATCH 3/3] Add shortcode doc --- .../contribute/style/hugo-shortcodes/index.md | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) diff --git a/content/en/docs/contribute/style/hugo-shortcodes/index.md b/content/en/docs/contribute/style/hugo-shortcodes/index.md index 2a836ffb913..fa3932f17d9 100644 --- a/content/en/docs/contribute/style/hugo-shortcodes/index.md +++ b/content/en/docs/contribute/style/hugo-shortcodes/index.md @@ -83,6 +83,33 @@ You can also include a full definition: which renders as: {{< glossary_definition term_id="cluster" length="all" >}} +## Links to API Reference + +You can link to a page of the Kubernetes API reference using the `api-reference` shortcode, for example to the {{< api-reference page="workload-resources/pod-v1" >}} reference: + +``` +{{}} +``` + +The content of the `page` parameter is the suffix of the URL of the API reference page. + + +You can link to a specific place into a page by specifying an `anchor` parameter, for example to the {{< api-reference page="workload-resources/pod-v1" anchor="PodSpec" >}} reference or the {{< api-reference page="workload-resources/pod-v1" anchor="environment-variables" >}} section of the page: + +``` +{{}} +{{}} +``` + + +You can change the text of the link by specifying a `text` parameter, for example by linking to the {{< api-reference page="workload-resources/pod-v1" anchor="environment-variables" text="Environment Variables">}} section of the page: + +``` +{{}} +``` + + + ## Table captions You can make tables more accessible to screen readers by adding a table caption. To add a [caption](https://www.w3schools.com/tags/tag_caption.asp) to a table, enclose the table with a `table` shortcode and specify the caption with the `caption` parameter.