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: broken documentation indexing with correct URLs #615

Merged
merged 4 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
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,19 @@ 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",

Copy link
Collaborator

@jenspav jenspav Sep 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, missed this one earlier, could you please remove this empty line? Everything else LGTM!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jenspav done!

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
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would you mind adding tests for no container sections, no container decisions, indexes container decisions and indexes container sections, similar like the existing ones for software systems?

While at it, no software system documentation should be named no container sections.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jenspav added, please review.

I didn't quite catch the last comment, this is actually testing no software system documentation and has nothing to do with containers, so I'm unsure what you referring there.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't quite catch the last comment, this is actually testing no software system documentation and has nothing to do with containers, so I'm unsure what you referring there.

Sry, typo on my side, what I meant was: Could you please also rename this function https://github.com/avisi-cloud/structurizr-site-generatr/blob/main/src/test/kotlin/nl/avisi/structurizr/site/generatr/site/model/IndexingTest.kt#L282 to no software system section for consistency with the other tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@jenspav done, please review now.

Original file line number Diff line number Diff line change
Expand Up @@ -265,13 +265,13 @@ 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"
)
Expand Down Expand Up @@ -307,14 +307,14 @@ 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"
)
Expand Down
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
Loading