Skip to content

Commit

Permalink
fix(services/tocs): fix format title (#183)
Browse files Browse the repository at this point in the history
  • Loading branch information
Feverqwe authored Sep 20, 2022
1 parent d8142e5 commit 9d2ab53
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/services/tocs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ async function add(path: string) {
...vars,
};

if (typeof parsedToc.title === 'string') {
if (parsedToc.title) {
parsedToc.title = firstFilterTextItems(
parsedToc.title,
combinedVars,
Expand Down
25 changes: 25 additions & 0 deletions tests/e2e/include-toc.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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).replace(/(")/g, '\\$1')}"`,
});

const compareResult = compareDirectories(outputPath, expectedOutputPath);

if (typeof compareResult === 'boolean') {
expect(true).toEqual(compareResult);
} else {
const {expectedContent, outputContent} = compareResult;

expect(expectedContent).toEqual(outputContent);
}
});
});
1 change: 1 addition & 0 deletions tests/mocks/include-toc/test4/expected-output/a1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the /a1.md file content.
9 changes: 9 additions & 0 deletions tests/mocks/include-toc/test4/expected-output/index.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
title: Title A
description:
- Desc A
meta:
title: Meta A
links:
- title: A1
description: A1 desc
href: a1
6 changes: 6 additions & 0 deletions tests/mocks/include-toc/test4/expected-output/toc.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
title: Title A
href: index.yaml
items:
- name: A1
href: a1.md
base: .
1 change: 1 addition & 0 deletions tests/mocks/include-toc/test4/input/a1.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
This is the /a1.md file content.
20 changes: 20 additions & 0 deletions tests/mocks/include-toc/test4/input/index.yaml
Original file line number Diff line number Diff line change
@@ -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
9 changes: 9 additions & 0 deletions tests/mocks/include-toc/test4/input/toc.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 9d2ab53

Please sign in to comment.