-
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.
This is based on Lunrjs. We assemble documents when generating the site, then Lunr builds an index on the client on page load and we search through that.
- Loading branch information
Showing
19 changed files
with
676 additions
and
0 deletions.
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
45 changes: 45 additions & 0 deletions
45
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,45 @@ | ||
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 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 }, | ||
) | ||
} | ||
|
||
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()}" | ||
) | ||
} |
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}" | ||
) |
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()}" | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
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,20 @@ | ||
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) = softwareSystem.documentation | ||
.sections.firstOrNull() | ||
?.let { section -> | ||
Document( | ||
SoftwareSystemPageViewModel.url(softwareSystem, SoftwareSystemPageViewModel.Tab.HOME) | ||
.asUrlToDirectory(viewModel.url), | ||
"Software System Info", | ||
"${softwareSystem.name} | ${section.contentTitle()}", | ||
"${section.contentTitle()} ${section.contentText()}" | ||
) | ||
} |
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()}" | ||
) | ||
} |
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()}" | ||
) | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/kotlin/nl/avisi/structurizr/site/generatr/site/model/indexing/WorkspaceSections.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,19 @@ | ||
package nl.avisi.structurizr.site.generatr.site.model.indexing | ||
|
||
import com.structurizr.documentation.Documentation | ||
import nl.avisi.structurizr.site.generatr.normalize | ||
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 | ||
import nl.avisi.structurizr.site.generatr.site.model.contentTitle | ||
|
||
fun workspaceSections(documentation: Documentation, viewModel: PageViewModel) = documentation.sections | ||
.drop(1) // Drop home | ||
.map { section -> | ||
Document( | ||
"/${section.contentTitle().normalize()}".asUrlToDirectory(viewModel.url), | ||
"Workspace Documentation", | ||
section.contentTitle(), | ||
"${section.contentTitle()} ${section.contentText()}" | ||
) | ||
} |
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
Oops, something went wrong.