From acb59cfe3a21d9a099e3b0cfc94807c306460b8a Mon Sep 17 00:00:00 2001 From: Anton Vikulov Date: Fri, 16 Sep 2022 19:56:00 +0500 Subject: [PATCH 1/3] fix(services/tocs): fix format title --- src/services/tocs.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/services/tocs.ts b/src/services/tocs.ts index ef188559..b414f534 100644 --- a/src/services/tocs.ts +++ b/src/services/tocs.ts @@ -50,7 +50,7 @@ async function add(path: string) { ...vars, }; - if (typeof parsedToc.title === 'string') { + if (parsedToc.title) { parsedToc.title = firstFilterTextItems( parsedToc.title, combinedVars, From 1bb0525f2647c455e67d73ea1c48f6b2b3f37eb2 Mon Sep 17 00:00:00 2001 From: Anton Vikulov Date: Mon, 19 Sep 2022 09:19:48 +0500 Subject: [PATCH 2/3] add tests --- tests/e2e/include-toc.test.ts | 25 +++++++++++++++++++ .../include-toc/test4/expected-output/a1.md | 1 + .../test4/expected-output/index.yaml | 9 +++++++ .../test4/expected-output/toc.yaml | 6 +++++ tests/mocks/include-toc/test4/input/a1.md | 1 + .../mocks/include-toc/test4/input/index.yaml | 20 +++++++++++++++ tests/mocks/include-toc/test4/input/toc.yaml | 9 +++++++ 7 files changed, 71 insertions(+) create mode 100644 tests/mocks/include-toc/test4/expected-output/a1.md create mode 100644 tests/mocks/include-toc/test4/expected-output/index.yaml create mode 100644 tests/mocks/include-toc/test4/expected-output/toc.yaml create mode 100644 tests/mocks/include-toc/test4/input/a1.md create mode 100644 tests/mocks/include-toc/test4/input/index.yaml create mode 100644 tests/mocks/include-toc/test4/input/toc.yaml diff --git a/tests/e2e/include-toc.test.ts b/tests/e2e/include-toc.test.ts index da276966..96d8f688 100644 --- a/tests/e2e/include-toc.test.ts +++ b/tests/e2e/include-toc.test.ts @@ -50,4 +50,29 @@ describe('Include toc', () => { expect(expectedContent).toEqual(outputContent); } }); + + test('Toc with expressions', () => { + const testRootPath = 'mocks/include-toc/test4'; + const {inputPath, outputPath, expectedOutputPath} = getTestPaths(testRootPath); + + const vars = { + type: 'a', + a: 'A', + b: 'B', + }; + + runYfmDocs(inputPath, outputPath, { + args: `--vars='${JSON.stringify(vars)}'`, + }); + + const compareResult = compareDirectories(outputPath, expectedOutputPath); + + if (typeof compareResult === 'boolean') { + expect(true).toEqual(compareResult); + } else { + const {expectedContent, outputContent} = compareResult; + + expect(expectedContent).toEqual(outputContent); + } + }); }); diff --git a/tests/mocks/include-toc/test4/expected-output/a1.md b/tests/mocks/include-toc/test4/expected-output/a1.md new file mode 100644 index 00000000..ec2a6cff --- /dev/null +++ b/tests/mocks/include-toc/test4/expected-output/a1.md @@ -0,0 +1 @@ +This is the /a1.md file content. diff --git a/tests/mocks/include-toc/test4/expected-output/index.yaml b/tests/mocks/include-toc/test4/expected-output/index.yaml new file mode 100644 index 00000000..d9ac6a5f --- /dev/null +++ b/tests/mocks/include-toc/test4/expected-output/index.yaml @@ -0,0 +1,9 @@ +title: Title A +description: + - Desc A +meta: + title: Meta A +links: + - title: A1 + description: A1 desc + href: a1 diff --git a/tests/mocks/include-toc/test4/expected-output/toc.yaml b/tests/mocks/include-toc/test4/expected-output/toc.yaml new file mode 100644 index 00000000..fd3fa268 --- /dev/null +++ b/tests/mocks/include-toc/test4/expected-output/toc.yaml @@ -0,0 +1,6 @@ +title: Title A +href: index.yaml +items: + - name: A1 + href: a1.md +base: . diff --git a/tests/mocks/include-toc/test4/input/a1.md b/tests/mocks/include-toc/test4/input/a1.md new file mode 100644 index 00000000..ec2a6cff --- /dev/null +++ b/tests/mocks/include-toc/test4/input/a1.md @@ -0,0 +1 @@ +This is the /a1.md file content. diff --git a/tests/mocks/include-toc/test4/input/index.yaml b/tests/mocks/include-toc/test4/input/index.yaml new file mode 100644 index 00000000..8b20bb3c --- /dev/null +++ b/tests/mocks/include-toc/test4/input/index.yaml @@ -0,0 +1,20 @@ +title: + - text: "Title {% if type == 'a' %}{{ a }}{% else %}{{ b }}{% endif %}" + when: type == "a" + - text: "Title {% if type == 'a' %}{{ a }}{% else %}{{ b }}{% endif %}" + when: type == "b" +description: + - text: "Desc {{ a }}" + when: type == "a" + - text: "Desc {{ b }}" + when: type == "b" +meta: + title: + - text: "Meta {{ a }}" + when: type == "a" + - text: "Meta {{ b }}" + when: type == "b" +links: + - title: A1 + description: A1 desc + href: a1 diff --git a/tests/mocks/include-toc/test4/input/toc.yaml b/tests/mocks/include-toc/test4/input/toc.yaml new file mode 100644 index 00000000..f74cb826 --- /dev/null +++ b/tests/mocks/include-toc/test4/input/toc.yaml @@ -0,0 +1,9 @@ +title: + - text: "Title {% if type == 'a' %}{{ a }}{% else %}{{ b }}{% endif %}" + when: type == "a" + - text: "Title {% if type == 'a' %}{{ a }}{% else %}{{ b }}{% endif %}" + when: type == "b" +href: index.yaml +items: + - name: A1 + href: a1.md From 7772d7f1ee78fcb4b359c390b7048092ad658309 Mon Sep 17 00:00:00 2001 From: Anton Vikulov Date: Tue, 20 Sep 2022 07:35:18 +0500 Subject: [PATCH 3/3] fix test --- tests/e2e/include-toc.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/e2e/include-toc.test.ts b/tests/e2e/include-toc.test.ts index 96d8f688..f669a8ed 100644 --- a/tests/e2e/include-toc.test.ts +++ b/tests/e2e/include-toc.test.ts @@ -62,7 +62,7 @@ describe('Include toc', () => { }; runYfmDocs(inputPath, outputPath, { - args: `--vars='${JSON.stringify(vars)}'`, + args: `--vars="${JSON.stringify(vars).replace(/(")/g, '\\$1')}"`, }); const compareResult = compareDirectories(outputPath, expectedOutputPath);