Fix doc dependency link (#1078)

This commit is contained in:
Islon Scherer
2025-05-28 18:08:38 +02:00
committed by GitHub
parent 021f43bec4
commit a19e6bf684
13 changed files with 44 additions and 24 deletions

View File

@@ -23,6 +23,7 @@ import org.pkl.core.Member.SourceLocation
import org.pkl.core.PModule
import org.pkl.core.PObject
import org.pkl.core.TypeAlias
import org.pkl.core.packages.PackageUri
/** API equivalent of standard library module `pkl.DocPackageInfo`. */
data class DocPackageInfo(
@@ -198,6 +199,12 @@ data class DocPackageInfo(
) {
internal val prefix = "$name."
val qualifiedName: String =
if (uri != null) {
val packageUri = PackageUri(uri)
"${uri.authority}${packageUri.pathWithoutVersion}"
} else name
/** Note: Returns an absolute URI, or an URI relative to the current site. */
internal fun getModuleDocUrl(moduleName: String): URI? =
when {

View File

@@ -35,7 +35,7 @@ internal sealed class DocScope {
abstract val parent: DocScope?
private val siteScope: SiteScope? by lazy {
val siteScope: SiteScope? by lazy {
var scope = this
while (scope !is SiteScope) {
scope = scope.parent ?: return@lazy null
@@ -122,7 +122,7 @@ internal abstract class PageScope : DocScope() {
// equality is identity
internal class SiteScope(
docPackages: List<DocPackage>,
val docPackages: List<DocPackage>,
private val overviewImports: Map<String, URI>,
private val importResolver: (URI) -> ModuleSchema,
outputDir: Path,
@@ -259,6 +259,11 @@ internal class PackageScope(
override val url: URI by lazy { parent.url.resolve("./${name.pathEncoded}/$version/index.html") }
fun urlForVersionRelativeTo(scope: DocScope, version: String): URI {
val myVersion = parent.url.resolve("./${name.pathEncoded}/$version/index.html")
return IoUtils.relativize(myVersion, scope.url)
}
override val dataUrl: URI by lazy {
parent.url.resolve("./data/${name.pathEncoded}/$version/index.js")
}

View File

@@ -525,15 +525,16 @@ internal abstract class PageGenerator<out S>(
var first = true
for (dep in dependencies) {
if (first) first = false else +", "
a {
href =
dep.documentation?.toString()
?: pageScope.relativeSiteUrl
.resolve("${dep.name}/${dep.version}/index.html")
.toString()
+dep.name
+":"
+dep.version
val link = getDependencyLink(dep)
if (link != null) {
a {
href = link
+dep.name
+":"
+dep.version
}
} else {
span { +"${dep.name}:${dep.version}" }
}
}
}
@@ -556,6 +557,14 @@ internal abstract class PageGenerator<out S>(
return result
}
private fun getDependencyLink(dep: DocPackageInfo.PackageDependency): String? {
val siteScope = pageScope.siteScope ?: return null
return siteScope.packageScopes.values
.find { it.name == dep.qualifiedName }
?.urlForVersionRelativeTo(pageScope, dep.version)
?.toString()
}
protected class MemberInfoKey(val name: String, val classes: Set<String> = setOf())
protected fun collectMemberInfo(