Skip to content

Commit 888102b

Browse files
committed
calculate sourceUrl in shared model
1 parent be970e3 commit 888102b

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

plugins/base/src/main/kotlin/renderers/html/innerTemplating/DefaultTemplateModelFactory.kt

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,6 @@ public class DefaultTemplateModelFactory(
7171
}
7272
mapper["template_cmd"] = TemplateDirective(context.configuration, pathToRoot)
7373

74-
calculateSourceUrlFromSourceLinks()?.let { mapper["sourceUrl"] = it }
75-
7674
if (page is ContentPage) {
7775
val sourceSets = page.content.withDescendants()
7876
.flatMap { it.sourceSets }
@@ -88,18 +86,21 @@ public class DefaultTemplateModelFactory(
8886
return mapper
8987
}
9088

91-
override fun buildSharedModel(): TemplateMap = mapOf<String, Any>(
92-
"footerMessage" to (configuration?.footerMessage?.takeIf { it.isNotEmpty() }
93-
?: DokkaBaseConfiguration.defaultFooterMessage)
94-
)
89+
override fun buildSharedModel(): TemplateMap {
90+
val mapper = mutableMapOf<String, Any>()
91+
92+
mapper["footerMessage"] =
93+
(configuration?.footerMessage?.takeIf(String::isNotBlank) ?: DokkaBaseConfiguration.defaultFooterMessage)
9594

96-
private fun calculateSourceUrlFromSourceLinks(): String? {
97-
val githubLinkRegex = Regex("http(s)?://github\\.com/([\\w,\\-_]+)/([\\w,\\-_]+)/.*")
95+
calculateSourceUrlFromSourceLinks()?.let { mapper["sourceUrl"] = it }
9896

97+
return mapper
98+
}
99+
100+
private fun calculateSourceUrlFromSourceLinks(): String? {
99101
fun parseGithubInfo(link: String): Pair<String, String>? {
100102
val (
101103
_, // entire match
102-
_, // optional 's' in http
103104
owner,
104105
repo
105106
) = githubLinkRegex.find(link)?.groupValues ?: return null
@@ -153,6 +154,10 @@ public class DefaultTemplateModelFactory(
153154
append(resourceHtml)
154155
}
155156
}
157+
158+
private companion object {
159+
val githubLinkRegex = Regex("https?://github\\.com/([\\w,\\-_]+)/([\\w,\\-_]+)/.*")
160+
}
156161
}
157162

158163
private class PrintDirective(val generateData: () -> String) : TemplateDirectiveModel {

0 commit comments

Comments
 (0)