From b592102e760b892f33a2476ca18f0cf2cc4832d2 Mon Sep 17 00:00:00 2001 From: Mykola Golubyev Date: Wed, 1 May 2024 06:10:52 -0400 Subject: [PATCH] flow: page auto title ignores specified extension (#1203) --- .../znai/structure/TocNameAndOpts.java | 4 +++- .../znai/structure/TocItemTest.groovy | 9 +++++++++ .../1.69/fix-2024-04-30-auto-title-with-custom-ext.md | 1 + 3 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 znai-docs/znai/release-notes/1.69/fix-2024-04-30-auto-title-with-custom-ext.md diff --git a/znai-core/src/main/java/org/testingisdocumenting/znai/structure/TocNameAndOpts.java b/znai-core/src/main/java/org/testingisdocumenting/znai/structure/TocNameAndOpts.java index 4692771b1..64723d6ce 100644 --- a/znai-core/src/main/java/org/testingisdocumenting/znai/structure/TocNameAndOpts.java +++ b/znai-core/src/main/java/org/testingisdocumenting/znai/structure/TocNameAndOpts.java @@ -81,6 +81,8 @@ private String buildHumanReadableName() { return title.toString(); } - return NameUtils.dashToCamelCaseWithSpaces(givenName); + int dotIdx = givenName.indexOf('.'); + String withoutExtension = dotIdx == -1 ? givenName : givenName.substring(0, dotIdx); + return NameUtils.dashToCamelCaseWithSpaces(withoutExtension); } } diff --git a/znai-core/src/test/groovy/org/testingisdocumenting/znai/structure/TocItemTest.groovy b/znai-core/src/test/groovy/org/testingisdocumenting/znai/structure/TocItemTest.groovy index 7c7cd1c59..951c885de 100644 --- a/znai-core/src/test/groovy/org/testingisdocumenting/znai/structure/TocItemTest.groovy +++ b/znai-core/src/test/groovy/org/testingisdocumenting/znai/structure/TocItemTest.groovy @@ -40,6 +40,15 @@ class TocItemTest { tocItem.fileExtension.should == "mdx" } + @Test + void "should create title from file name ignoring extension"() { + def tocItem = new TocItem('dir-name', 'file-name.mdx', 'md') + tocItem.dirName.should == "dir-name" + tocItem.fileNameWithoutExtension.should == "file-name" + tocItem.pageTitle.should == "File Name" + tocItem.fileExtension.should == "mdx" + } + @Test void "should extract optional file name extension"() { def tocItem = new TocItem('dir-name', 'file-name.mdx', 'md') diff --git a/znai-docs/znai/release-notes/1.69/fix-2024-04-30-auto-title-with-custom-ext.md b/znai-docs/znai/release-notes/1.69/fix-2024-04-30-auto-title-with-custom-ext.md new file mode 100644 index 000000000..10c481ce4 --- /dev/null +++ b/znai-docs/znai/release-notes/1.69/fix-2024-04-30-auto-title-with-custom-ext.md @@ -0,0 +1 @@ +* Fix: [auto title](flow/names) now correctly ignores specified extension. \ No newline at end of file