From fa90184ad342f42af658fe10c9312735425dfa7f Mon Sep 17 00:00:00 2001 From: Andrea Frittoli Date: Mon, 9 Nov 2020 16:59:24 +0000 Subject: [PATCH] Add the tkn reference to the CLI docs Add the doc/cmd folder to add the tkn reference docs to the CLI documentation. Add support for defaulting page title and link title to the filename, if not set, which works OK for tkn. Fixes #118 Signed-off-by: Andrea Frittoli --- sync/config/cli.yaml | 12 ++++++++++++ sync/sync.py | 6 ++++++ sync/test_sync.py | 7 ++++++- 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/sync/config/cli.yaml b/sync/config/cli.yaml index 272982ed0..37a67b048 100644 --- a/sync/config/cli.yaml +++ b/sync/config/cli.yaml @@ -39,6 +39,12 @@ tags: docs: index: README.md include: ['*.md'] + docs/cmd: + index: tkn.md + include: ['*.md'] + target: 'cmd' + header: + description: The `tkn` CLI reference - name: v0.12.1 # The name to display on tekton.dev. # helper.py will use this value in the version switcher and other places. @@ -75,3 +81,9 @@ tags: docs: index: README.md include: ['*.md'] + docs/cmd: + index: tkn.md + include: ['*.md'] + target: 'cmd' + header: + description: The `tkn` CLI reference \ No newline at end of file diff --git a/sync/sync.py b/sync/sync.py index ce231b0c0..384a5a643 100755 --- a/sync/sync.py +++ b/sync/sync.py @@ -176,7 +176,13 @@ def transform_doc(doc, source_folder, target, target_folder, header, target = os.path.join(site_target_folder, target) with open(target, 'w+') as target_doc: # If there is an header configured, write it (in YAML) + # If there is no title set, use the filename + # If there is not linkTitle set, use the title if header: + filename, _ = os.path.splitext(doc.name) + header['title'] = header.get('title', filename) + header['linkTitle'] = header.get('linkTitle', + header.get('title', filename)) target_doc.write(YAML_SEPARATOR) YAML().dump(header, target_doc) target_doc.write(YAML_SEPARATOR) diff --git a/sync/test_sync.py b/sync/test_sync.py index 83e75a573..25203c799 100644 --- a/sync/test_sync.py +++ b/sync/test_sync.py @@ -313,6 +313,8 @@ def test_transform_doc(self): "test1: abc\n" "test2: 1\n" "test3: true\n" + "title: content\n" + "linkTitle: content\n" "---\n" ) actual_result = transform_doc( @@ -345,9 +347,12 @@ def test_transform_docs(self): "---\n" "test1: abc\n" "weight: {weight}\n" + "title: {name}\n" + "linkTitle: {name}\n" "---\n" ) - expected_contents = [template.format(weight=idx) for idx in range(2)] + expected_contents = [template.format(weight=idx, name=name) + for idx, name in zip(range(2), ['content', 'test'])] actual_results = transform_docs( self.gitrepo, self.tagname, folders_config, site_dir, '/doc/test', 'http://test.com/test/tree')