Skip to content

Commit

Permalink
Merge pull request #615 from FlyrInc/fix/search-links
Browse files Browse the repository at this point in the history
fix: broken documentation indexing with correct URLs
  • Loading branch information
jenspav authored Oct 1, 2024
2 parents 94ef16e + 871f9be commit f947984
Show file tree
Hide file tree
Showing 9 changed files with 158 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,7 @@
package nl.avisi.structurizr.site.generatr.site.model

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
import nl.avisi.structurizr.site.generatr.site.model.indexing.*

class SearchViewModel(generatorContext: GeneratorContext) : PageViewModel(generatorContext) {
override val pageSubTitle = "Search results"
Expand All @@ -36,7 +27,19 @@ class SearchViewModel(generatorContext: GeneratorContext) : PageViewModel(genera
addAll(softwareSystemSections(it, this@SearchViewModel))
}
}
.mapNotNull { it },
.mapNotNull { it }
)
addAll(
includedSoftwareSystems
.flatMap {
buildList {
it.containers.forEach {
addAll(softwareSystemContainerSections(it, this@SearchViewModel))
addAll(softwareSystemContainerDecisions(it, this@SearchViewModel))
}
}
}
.mapNotNull { it }
)
}.mapNotNull { it }

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package nl.avisi.structurizr.site.generatr.site.model.indexing

import com.structurizr.model.Container
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.SoftwareSystemContainerDecisionPageViewModel
import nl.avisi.structurizr.site.generatr.site.model.contentText

fun softwareSystemContainerDecisions(container: Container, viewModel: PageViewModel) = container
.documentation
.decisions
.map { decision ->
Document(
SoftwareSystemContainerDecisionPageViewModel.url(
container,
decision
).asUrlToDirectory(viewModel.url),
"Container Decision",
"${container.name} | ${decision.title}",
"${decision.title} ${decision.contentText()}".trim()
)
}
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.Container
import nl.avisi.structurizr.site.generatr.site.asUrlToDirectory
import nl.avisi.structurizr.site.generatr.site.model.*

fun softwareSystemContainerSections(container: Container, viewModel: PageViewModel) = container
.documentation
.sections
.map { section ->
Document(
SoftwareSystemContainerSectionPageViewModel.url(
container,
section
).asUrlToDirectory(viewModel.url),
"Container Documentation",
"${container.name} | ${section.contentTitle()}",
"${section.contentTitle()} ${section.contentText()}".trim()
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ 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.SoftwareSystemDecisionPageViewModel
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",
SoftwareSystemDecisionPageViewModel.url(
softwareSystem,
decision
).asUrlToDirectory(viewModel.url),
"Software System Decision",
"${softwareSystem.name} | ${decision.title}",
"${decision.title} ${decision.contentText()}".trim()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,18 @@ 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
import nl.avisi.structurizr.site.generatr.site.model.*

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",
SoftwareSystemSectionPageViewModel.url(
softwareSystem,
section
).asUrlToDirectory(viewModel.url),
"Software System Documentation",
"${softwareSystem.name} | ${section.contentTitle()}",
"${section.contentTitle()} ${section.contentText()}".trim()
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ 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.WorkspaceDecisionPageViewModel
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),
WorkspaceDecisionPageViewModel.url(decision)
.asUrlToDirectory(viewModel.url),
"Workspace Decision",
decision.title,
"${decision.title} ${decision.contentText()}".trim()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ 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.WorkspaceDocumentationSectionPageViewModel
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),
WorkspaceDocumentationSectionPageViewModel.url(section)
.asUrlToDirectory(viewModel.url),
"Workspace Documentation",
section.contentTitle(),
"${section.contentTitle()} ${section.contentText()}".trim()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,7 @@ import assertk.assertions.isEqualTo
import assertk.assertions.isNull
import com.structurizr.documentation.Format
import com.structurizr.documentation.Section
import nl.avisi.structurizr.site.generatr.site.model.indexing.Document
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
import nl.avisi.structurizr.site.generatr.site.model.indexing.*
import kotlin.test.Test

class IndexingTest : ViewModelTest() {
Expand Down Expand Up @@ -265,29 +255,29 @@ class IndexingTest : ViewModelTest() {
assertThat(documents).containsAtLeast(
Document(
"../software-system-1/decisions/1/",
"Decision",
"Software System Decision",
"Software System 1 | Decision 1",
"Decision 1 Decision 1 content"
),
Document(
"../software-system-1/decisions/2/",
"Decision",
"Software System Decision",
"Software System 1 | Decision 2",
"Decision 2 Decision 2 content"
)
)
}

@Test
fun `no software system documentation`() {
fun `no software system sections`() {
workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all")
val documents = softwareSystemSections(workspace.model.softwareSystems.single(), this.pageViewModel())

assertThat(documents).isEmpty()
}

@Test
fun `only software system documentation for software system home`() {
fun `only software system section for software system home`() {
workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all").apply {
documentation.addSection(Section(Format.Markdown, "# Introduction\nSome info"))
}
Expand All @@ -307,17 +297,86 @@ class IndexingTest : ViewModelTest() {

assertThat(documents).containsAtLeast(
Document(
"../software-system-1/sections/2/",
"Documentation",
"../software-system-1/sections/usage/",
"Software System Documentation",
"Software System 1 | Usage",
"Usage That's how it works"
),
Document(
"../software-system-1/sections/3/",
"Documentation",
"../software-system-1/sections/history/",
"Software System Documentation",
"Software System 1 | History",
"History That's how we got here"
)
)
}

@Test
fun `no container sections`() {
val softwareSystem = workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all")
softwareSystem.addContainer("Container 1", "a container")
val documents = softwareSystemContainerSections(softwareSystem.containers.single(), this.pageViewModel())

assertThat(documents).isEmpty()
}

@Test
fun `no container decisions`() {
val softwareSystem = workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all")
softwareSystem.addContainer("Container 1", "a container")
val documents = softwareSystemContainerDecisions(softwareSystem.containers.single(), this.pageViewModel())

assertThat(documents).isEmpty()
}

@Test
fun `indexes container decisions`() {
val softwareSystem = workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all")
val container = softwareSystem.addContainer("Container 1", "a container").apply {
documentation.addDecision(createDecision("1"))
documentation.addDecision(createDecision("2"))
}
val documents = softwareSystemContainerDecisions(container, this.pageViewModel())

assertThat(documents).containsAtLeast(
Document(
"../software-system-1/decisions/container-1/1/",
"Container Decision",
"Container 1 | Decision 1",
"Decision 1 Decision 1 content"
),
Document(
"../software-system-1/decisions/container-1/2/",
"Container Decision",
"Container 1 | Decision 2",
"Decision 2 Decision 2 content"
)
)
}

@Test
fun `indexes container sections`() {
val softwareSystem = workspace.model.addSoftwareSystem("Software System 1", "One system to rule them all")
val container = softwareSystem.addContainer("Container 1", "a container").apply {
documentation.addSection(Section(Format.Markdown, "# Introduction\nSome info"))
documentation.addSection(Section(Format.Markdown, "# Usage\nThat's how it works"))
documentation.addSection(Section(Format.Markdown, "# History\nThat's how we got here"))
}
val documents = softwareSystemContainerSections(container, this.pageViewModel())

assertThat(documents).containsAtLeast(
Document(
"../software-system-1/sections/container-1/usage/",
"Container Documentation",
"Container 1 | Usage",
"Usage That's how it works"
),
Document(
"../software-system-1/sections/container-1/history/",
"Container Documentation",
"Container 1 | History",
"History That's how we got here"
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,8 @@ class SearchViewModelTest : ViewModelTest() {
documentation.addSection(Section(Format.Markdown, "# Introduction\nSome info"))
addContainer("Container 1", "a container").apply {
addComponent("Component 1", "a component")
documentation.addDecision(createDecision("1"))
documentation.addSection(Section(Format.Markdown, "# Component Usage\nThat's how it works"))
}
documentation.addDecision(createDecision("1"))
documentation.addSection(Section(Format.Markdown, "# Usage\nThat's how it works"))
Expand All @@ -94,8 +96,10 @@ class SearchViewModelTest : ViewModelTest() {
"Context views",
"Container views",
"Component views",
"Decision",
"Documentation"
"Software System Decision",
"Software System Documentation",
"Container Documentation",
"Container Decision"
)
}

Expand Down

0 comments on commit f947984

Please sign in to comment.