From 2ad6529ef3b629dd3a1695f815c17c19da0ef517 Mon Sep 17 00:00:00 2001 From: Alexander Ionov Date: Thu, 30 May 2019 11:28:44 +0600 Subject: [PATCH 1/2] disabled generation of global index.html for all docs versions --- src/main/kotlin/it/_7bits/doc_builder/IndexRenderer.kt | 3 ++- src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt | 6 +++++- src/main/resources/templates/index.jade | 2 +- 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/it/_7bits/doc_builder/IndexRenderer.kt b/src/main/kotlin/it/_7bits/doc_builder/IndexRenderer.kt index 97839f7..67a9bd4 100644 --- a/src/main/kotlin/it/_7bits/doc_builder/IndexRenderer.kt +++ b/src/main/kotlin/it/_7bits/doc_builder/IndexRenderer.kt @@ -11,7 +11,8 @@ class IndexRenderer( try { val file = target.resolve("index.html").toFile() file.createNewFile() - indexWriter.write(mapOf("docs" to docs.toList()), file.writer()) + val fileNames = docs.toList().map { it.fileName.toString() } + indexWriter.write(mapOf("docs" to fileNames), file.writer()) } catch (e: Exception) { log.error("Can't create index file.", e) } diff --git a/src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt b/src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt index d05987d..bdeb200 100644 --- a/src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt +++ b/src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt @@ -32,6 +32,10 @@ object SiteGenerator { indexRenderer.createIndex(docs.map { destination.fileName.resolve(it) }, destination) } - indexRenderer.createIndex(versions.map { it.fileName }, options.destination) +// TODO: disabled for reason described below +// As for now, DocBuilder is unable to go through all git branches and generate documentations. +// val versions contains only one version. In the end, index.html with wrong reference ends up being broken. +// This feature needs to be fixed, but not now. As for now, we need to have functional index.html +// indexRenderer.createIndex(versions.map { it.fileName }, options.destination) } } \ No newline at end of file diff --git a/src/main/resources/templates/index.jade b/src/main/resources/templates/index.jade index 2eb4917..fb32a77 100644 --- a/src/main/resources/templates/index.jade +++ b/src/main/resources/templates/index.jade @@ -11,4 +11,4 @@ html(lang='en') article header h3 - a(href=doc) #{doc.getFileName()} \ No newline at end of file + a(href=doc.toString()) #{doc.toString()} \ No newline at end of file From 47fc6a27a358c3e886e969a5ed7ab19ceec5a212 Mon Sep 17 00:00:00 2001 From: Alexander Ionov Date: Thu, 30 May 2019 11:52:07 +0600 Subject: [PATCH 2/2] added strict filter on found Markdown files with regex --- src/main/kotlin/it/_7bits/doc_builder/Documentation.kt | 7 +++++-- src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt | 3 ++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/main/kotlin/it/_7bits/doc_builder/Documentation.kt b/src/main/kotlin/it/_7bits/doc_builder/Documentation.kt index 2328972..63fdb21 100644 --- a/src/main/kotlin/it/_7bits/doc_builder/Documentation.kt +++ b/src/main/kotlin/it/_7bits/doc_builder/Documentation.kt @@ -6,6 +6,7 @@ import java.io.File import java.nio.file.Files import java.nio.file.Path import java.nio.file.Paths +import java.util.regex.Pattern class Documentation( @@ -14,7 +15,8 @@ class Documentation( private val fileReader: IFileReader = LocalFilesReader(), private val writer: IWriter = JadeWriter("templates/layout"), private val renderer: IRenderer = MarkdownRenderer(), - private val fileNameBuilder: FileNameBuilder = FileNameBuilder() + private val fileNameBuilder: FileNameBuilder = FileNameBuilder(), + private val pattern: Pattern ) { private val log = logger() @@ -32,7 +34,8 @@ class Documentation( log.error("Can't create destination at path '${destination.toAbsolutePath()}'.", e) } - return fileReader.all(source).mapNotNull { + return fileReader.all(source).filter { pattern.matcher(it.path.toString()).find() } + .mapNotNull { try { log.info(it.path.toString()) val content = renderer.render(it.reader) diff --git a/src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt b/src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt index bdeb200..11e5ff2 100644 --- a/src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt +++ b/src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt @@ -25,7 +25,8 @@ object SiteGenerator { fileReader = fileReader, fileNameBuilder = fileNameBuilder, writer = writer, - renderer = renderer + renderer = renderer, + pattern = options.pattern ) val docs = doc.build()