From e3acd99cd55d3c2375686ba5f3c3abfe105dfb6a Mon Sep 17 00:00:00 2001 From: Ostrzyciel Date: Wed, 22 Nov 2023 13:00:58 +0100 Subject: [PATCH] Fix nav generation with empty dirs Issue: https://github.com/RiverBench/RiverBench/issues/28 --- src/main/scala/commands/NavGenCommand.scala | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/main/scala/commands/NavGenCommand.scala b/src/main/scala/commands/NavGenCommand.scala index 671f9f4..2dfcd7c 100644 --- a/src/main/scala/commands/NavGenCommand.scala +++ b/src/main/scala/commands/NavGenCommand.scala @@ -132,10 +132,12 @@ object NavGenCommand extends Command: private def listDir(rootDir: Path, dir: String, prettify: Boolean = true): Seq[YamlValue] = rootDir.resolve(dir).toFile.listFiles() .flatMap { - case f if f.isDirectory => Some(YamlMap( - if prettify then prettifyName(f.getName) else f.getName.stripSuffix(".md"), - YamlList(listDir(rootDir, (dir + "/" + f.getName).stripPrefix("/"))) - )) + case f if f.isDirectory => + val list = YamlList(listDir(rootDir, (dir + "/" + f.getName).stripPrefix("/"))) + if list.v.isEmpty then None else Some(YamlMap( + if prettify then prettifyName(f.getName) else f.getName.stripSuffix(".md"), + list + )) case f if f.isFile && f.getName.endsWith(".md") => val localPath = dir + "/" + f.getName if f.getName == "index.md" then Some(YamlString(dir + "/index.md"))