-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #189 from jp7677/search
Add search functionality
- Loading branch information
Showing
25 changed files
with
986 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/ContentText.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model | ||
|
||
import com.structurizr.documentation.Decision | ||
import com.structurizr.documentation.Format | ||
import com.structurizr.documentation.Section | ||
import com.vladsch.flexmark.ast.Heading | ||
import com.vladsch.flexmark.ast.Paragraph | ||
import com.vladsch.flexmark.parser.Parser | ||
|
||
private val parser = Parser.builder().build() | ||
|
||
fun Decision.contentText(): String { | ||
if (format != Format.Markdown) | ||
return "" | ||
|
||
return extractText(content) | ||
} | ||
|
||
fun Section.contentText(): String { | ||
if (format != Format.Markdown) | ||
return "" | ||
|
||
return extractText(content) | ||
} | ||
|
||
private fun extractText(content: String): String { | ||
val document = parser.parse(content) | ||
if (!document.hasChildren()) | ||
return "" | ||
|
||
return document | ||
.children | ||
.filterIsInstance<Heading>() | ||
.drop(1) // ignore title | ||
.joinToString(" ") { it.text.toString() } | ||
.plus(" ") | ||
.plus( | ||
document | ||
.children | ||
.filterIsInstance<Paragraph>() | ||
.joinToString(" ") { it.chars.toString().trim() } | ||
) | ||
.trim() | ||
} |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/SearchViewModel.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model | ||
|
||
import nl.avisi.structurizr.site.generatr.includedSoftwareSystem | ||
import nl.avisi.structurizr.site.generatr.site.GeneratorContext | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.home | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemComponents | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemContainers | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemContext | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemDecisions | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemHome | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemRelationships | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.softwareSystemSections | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.workspaceDecisions | ||
import nl.avisi.structurizr.site.generatr.site.model.indexing.workspaceSections | ||
|
||
class SearchViewModel(generatorContext: GeneratorContext) : PageViewModel(generatorContext) { | ||
override val pageSubTitle = "Search results" | ||
override val url = url() | ||
|
||
val language: String = generatorContext.workspace.views | ||
.configuration.properties.getOrDefault("structurizr.style.search.language", "") | ||
|
||
val documents = buildList { | ||
add(home(generatorContext.workspace.documentation, this@SearchViewModel)) | ||
addAll(workspaceDecisions(generatorContext.workspace.documentation, this@SearchViewModel)) | ||
addAll(workspaceSections(generatorContext.workspace.documentation, this@SearchViewModel)) | ||
addAll( | ||
generatorContext.workspace.model.softwareSystems | ||
.filter { it.includedSoftwareSystem } | ||
.flatMap { | ||
buildList { | ||
add(softwareSystemHome(it, this@SearchViewModel)) | ||
add(softwareSystemContext(it, this@SearchViewModel)) | ||
add(softwareSystemContainers(it, this@SearchViewModel)) | ||
add(softwareSystemComponents(it, this@SearchViewModel)) | ||
add(softwareSystemRelationships(it, this@SearchViewModel)) | ||
addAll(softwareSystemDecisions(it, this@SearchViewModel)) | ||
addAll(softwareSystemSections(it, this@SearchViewModel)) | ||
} | ||
} | ||
.mapNotNull { it }, | ||
) | ||
}.mapNotNull { it } | ||
|
||
companion object { | ||
fun url() = "/search" | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/Document.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class Document(val href: String, val type: String, val title: String, val text: String) |
18 changes: 18 additions & 0 deletions
18
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/Home.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.documentation.Documentation | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.HomePageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.contentText | ||
import nl.avisi.structurizr.site.generatr.site.model.contentTitle | ||
|
||
fun home(documentation: Documentation, viewModel: PageViewModel) = documentation.sections.firstOrNull() | ||
?.let { section -> | ||
Document( | ||
HomePageViewModel.url().asUrlToDirectory(viewModel.url), | ||
"Home", | ||
section.contentTitle(), | ||
"${section.contentTitle()} ${section.contentText()}".trim() | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
...kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemComponents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.model.SoftwareSystem | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel | ||
|
||
fun softwareSystemComponents(softwareSystem: SoftwareSystem, viewModel: PageViewModel) = softwareSystem.containers | ||
.sortedBy { it.name } | ||
.flatMap { container -> | ||
container.components | ||
.sortedBy { it.name } | ||
.flatMap { component -> | ||
listOf(component.name, component.description, component.technology) | ||
} | ||
} | ||
.filter { it != null && it.isNotBlank() } | ||
.joinToString(" ") | ||
.ifBlank { null } | ||
?.let { | ||
Document( | ||
SoftwareSystemPageViewModel.url(softwareSystem, SoftwareSystemPageViewModel.Tab.COMPONENT) | ||
.asUrlToDirectory(viewModel.url), | ||
"Component views", | ||
"${softwareSystem.name} | Component views", | ||
it | ||
) | ||
} |
24 changes: 24 additions & 0 deletions
24
...kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContainers.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.model.SoftwareSystem | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel | ||
|
||
fun softwareSystemContainers(softwareSystem: SoftwareSystem, viewModel: PageViewModel) = softwareSystem.containers | ||
.sortedBy { it.name } | ||
.flatMap { container -> | ||
listOf(container.name, container.description, container.technology) | ||
} | ||
.filter { it != null && it.isNotBlank() } | ||
.joinToString(" ") | ||
.ifBlank { null } | ||
?.let { | ||
Document( | ||
SoftwareSystemPageViewModel.url(softwareSystem, SoftwareSystemPageViewModel.Tab.CONTAINER) | ||
.asUrlToDirectory(viewModel.url), | ||
"Container views", | ||
"${softwareSystem.name} | Container views", | ||
it | ||
) | ||
} |
14 changes: 14 additions & 0 deletions
14
...in/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemContext.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.model.SoftwareSystem | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel | ||
|
||
fun softwareSystemContext(softwareSystem: SoftwareSystem, viewModel: PageViewModel) = Document( | ||
SoftwareSystemPageViewModel.url(softwareSystem, SoftwareSystemPageViewModel.Tab.SYSTEM_CONTEXT) | ||
.asUrlToDirectory(viewModel.url), | ||
"Context views", | ||
"${softwareSystem.name} | Context views", | ||
"${softwareSystem.name} ${softwareSystem.description}".trim() | ||
) |
23 changes: 23 additions & 0 deletions
23
.../kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemDecisions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.model.SoftwareSystem | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.contentText | ||
|
||
fun softwareSystemDecisions(softwareSystem: SoftwareSystem, viewModel: PageViewModel) = softwareSystem.documentation | ||
.decisions | ||
.map { decision -> | ||
Document( | ||
"${ | ||
SoftwareSystemPageViewModel.url( | ||
softwareSystem, | ||
SoftwareSystemPageViewModel.Tab.HOME | ||
) | ||
}/decisions/${decision.id}".asUrlToDirectory(viewModel.url), | ||
"Decision", | ||
"${softwareSystem.name} | ${decision.title}", | ||
"${decision.title} ${decision.contentText()}".trim() | ||
) | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemHome.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.model.SoftwareSystem | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.contentText | ||
import nl.avisi.structurizr.site.generatr.site.model.contentTitle | ||
|
||
fun softwareSystemHome(softwareSystem: SoftwareSystem, viewModel: PageViewModel): Document? { | ||
val (contentTitle, contentText) = softwareSystem.section() | ||
val propertyValues = softwareSystem.propertyValues() | ||
|
||
if (contentTitle.isBlank() && contentText.isBlank() && propertyValues.isBlank()) | ||
return null | ||
|
||
return Document( | ||
SoftwareSystemPageViewModel.url(softwareSystem, SoftwareSystemPageViewModel.Tab.HOME) | ||
.asUrlToDirectory(viewModel.url), | ||
"Software System Info", | ||
"${softwareSystem.name} | ${contentTitle.ifEmpty { "Info" }}", | ||
"$contentTitle $contentText $propertyValues".trim(), | ||
) | ||
} | ||
|
||
private fun SoftwareSystem.section() = documentation.sections.firstOrNull()?.let { | ||
it.contentTitle() to it.contentText() | ||
} ?: ("" to "") | ||
|
||
private fun SoftwareSystem.propertyValues() = properties.values.joinToString(" ") |
38 changes: 38 additions & 0 deletions
38
...lin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemRelationships.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.model.SoftwareSystem | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel | ||
|
||
fun softwareSystemRelationships(softwareSystem: SoftwareSystem, viewModel: PageViewModel) = softwareSystem.relationships | ||
.filter { r -> r.source == softwareSystem } | ||
.sortedBy { it.destination.name } | ||
.flatMap { relationship -> | ||
listOf(relationship.destination.name, relationship.description, relationship.technology) | ||
} | ||
.plus( | ||
softwareSystem.model.softwareSystems | ||
.sortedBy { it.name } | ||
.filterNot { system -> system == softwareSystem } | ||
.flatMap { other -> | ||
other.relationships | ||
.filter { r -> r.destination == softwareSystem } | ||
.sortedBy { it.source.name } | ||
.flatMap { relationship -> | ||
listOf(relationship.source.name, relationship.description, relationship.technology) | ||
} | ||
} | ||
) | ||
.filter { it != null && it.isNotBlank() } | ||
.joinToString(" ") | ||
.ifBlank { null } | ||
?.let { | ||
Document( | ||
SoftwareSystemPageViewModel.url(softwareSystem, SoftwareSystemPageViewModel.Tab.DEPENDENCIES) | ||
.asUrlToDirectory(viewModel.url), | ||
"Dependencies", | ||
"${softwareSystem.name} | Dependencies", | ||
it | ||
) | ||
} |
25 changes: 25 additions & 0 deletions
25
...n/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/SoftwareSystemSections.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.model.SoftwareSystem | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.SoftwareSystemPageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.contentText | ||
import nl.avisi.structurizr.site.generatr.site.model.contentTitle | ||
|
||
fun softwareSystemSections(softwareSystem: SoftwareSystem, viewModel: PageViewModel) = softwareSystem.documentation | ||
.sections | ||
.drop(1) // Drop software system home | ||
.map { section -> | ||
Document( | ||
"${ | ||
SoftwareSystemPageViewModel.url( | ||
softwareSystem, | ||
SoftwareSystemPageViewModel.Tab.HOME | ||
) | ||
}/sections/${section.order}".asUrlToDirectory(viewModel.url), | ||
"Documentation", | ||
"${softwareSystem.name} | ${section.contentTitle()}", | ||
"${section.contentTitle()} ${section.contentText()}".trim() | ||
) | ||
} |
16 changes: 16 additions & 0 deletions
16
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceDecisions.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.documentation.Documentation | ||
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory | ||
import nl.avisi.structurizr.site.generatr.site.model.PageViewModel | ||
import nl.avisi.structurizr.site.generatr.site.model.contentText | ||
|
||
fun workspaceDecisions(documentation: Documentation, viewModel: PageViewModel) = documentation.decisions | ||
.map { decision -> | ||
Document( | ||
"/decisions/${decision.id}".asUrlToDirectory(viewModel.url), | ||
"Workspace Decision", | ||
decision.title, | ||
"${decision.title} ${decision.contentText()}".trim() | ||
) | ||
} |
Oops, something went wrong.