Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix list of documents in index.html and added strict filter on Markdownfiles #2

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions src/main/kotlin/it/_7bits/doc_builder/Documentation.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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()

Expand All @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion src/main/kotlin/it/_7bits/doc_builder/IndexRenderer.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
9 changes: 7 additions & 2 deletions src/main/kotlin/it/_7bits/doc_builder/SiteGenerator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,18 @@ object SiteGenerator {
fileReader = fileReader,
fileNameBuilder = fileNameBuilder,
writer = writer,
renderer = renderer
renderer = renderer,
pattern = options.pattern
)

val docs = doc.build()
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)
}
}
2 changes: 1 addition & 1 deletion src/main/resources/templates/index.jade
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ html(lang='en')
article
header
h3
a(href=doc) #{doc.getFileName()}
a(href=doc.toString()) #{doc.toString()}