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

@@ -7,7 +7,7 @@
"fruities": {
"uri": "package://localhost:0/fruit@1.0.5",
"checksums": {
"sha256": "34a15b02346e6acb85da5bd71d8b0738a79008b38a7fc805e5869d9129ad27d2"
"sha256": "8ff80e5ac882650e817f261c8af024bf0db9b07888c9d18c20017457e04ffe06"
}
}
},

View File

@@ -9,7 +9,6 @@
"sha256": "$computedChecksum"
},
"sourceCode": "https://example.com/fruit",
"documentation": "https://example.com/fruit-docs",
"license": "UNLICENSED",
"authors": [
"apple-1@example.com",

View File

@@ -44,8 +44,8 @@ import kotlin.io.path.*
@OptIn(ExperimentalPathApi::class)
class PackageServer : AutoCloseable {
companion object {
const val BIRDS_SHA = "6f18af649b47986530cd6dc39abe17888db2701bc5381c385fb86a32fda2685e"
const val FRUIT_SHA = "34a15b02346e6acb85da5bd71d8b0738a79008b38a7fc805e5869d9129ad27d2"
const val BIRDS_SHA = "b27206b80f4f227752b6f02143887f3ea41e554542cec38f7b572b987566c4de"
const val FRUIT_SHA = "8ff80e5ac882650e817f261c8af024bf0db9b07888c9d18c20017457e04ffe06"
const val FRUIT_1_1_SHA = "8d982761d182f2185e4180c82190791d9a60c721cb3393bb2e946fab90131e8c"
fun populateCacheDir(cacheDir: Path) {

View File

@@ -16,7 +16,7 @@ examples {
import("package://localhost:0/birds@0.5.0#/catalog/Ostrich.pkl")
}
["importing while specifying checksum"] {
import("package://localhost:0/birds@0.5.0::sha256:6f18af649b47986530cd6dc39abe17888db2701bc5381c385fb86a32fda2685e#/catalog/Swallow.pkl")
import("package://localhost:0/birds@0.5.0::sha256:b27206b80f4f227752b6f02143887f3ea41e554542cec38f7b572b987566c4de#/catalog/Swallow.pkl")
}
["reads"] {
read("package://localhost:0/birds@0.5.0#/Bird.pkl")

View File

@@ -20,6 +20,6 @@ examples {
import("package://localhost:0/birds@0.5.0#/allFruit.pkl").fruitFiles
}
["glob import while specifying checksum"] {
import*("package://localhost:0/birds@0.5.0::sha256:6f18af649b47986530cd6dc39abe17888db2701bc5381c385fb86a32fda2685e#/catalog/*.pkl")
import*("package://localhost:0/birds@0.5.0::sha256:b27206b80f4f227752b6f02143887f3ea41e554542cec38f7b572b987566c4de#/catalog/*.pkl")
}
}

View File

@@ -5,7 +5,7 @@
"type": "remote",
"uri": "projectpackage://localhost:0/fruit@1.0.5",
"checksums": {
"sha256": "34a15b02346e6acb85da5bd71d8b0738a79008b38a7fc805e5869d9129ad27d2"
"sha256": "8ff80e5ac882650e817f261c8af024bf0db9b07888c9d18c20017457e04ffe06"
}
}
}

View File

@@ -118,13 +118,13 @@ examples {
}
["glob import while specifying checksum"] {
new {
["package://localhost:0/birds@0.5.0::sha256:6f18af649b47986530cd6dc39abe17888db2701bc5381c385fb86a32fda2685e#/catalog/Ostrich.pkl"] {
["package://localhost:0/birds@0.5.0::sha256:b27206b80f4f227752b6f02143887f3ea41e554542cec38f7b572b987566c4de#/catalog/Ostrich.pkl"] {
name = "Ostrich"
favoriteFruit {
name = "Orange"
}
}
["package://localhost:0/birds@0.5.0::sha256:6f18af649b47986530cd6dc39abe17888db2701bc5381c385fb86a32fda2685e#/catalog/Swallow.pkl"] {
["package://localhost:0/birds@0.5.0::sha256:b27206b80f4f227752b6f02143887f3ea41e554542cec38f7b572b987566c4de#/catalog/Swallow.pkl"] {
name = "Swallow"
favoriteFruit {
name = "Apple"

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(

View File

@@ -39,7 +39,7 @@
<dt class="">Issue tracker:</dt>
<dd><a href="https://issues.apple.com/package1/">https://issues.apple.com/package1/</a></dd>
<dt class="">Dependencies:</dt>
<dd><a href="../../com.package2/4.5.6/index.html">com.package2:4.5.6</a>, <a href="https://example.com/docs/externalpackage/">com.externalpackage:7.8.9</a></dd>
<dd><a href="../../com.package2/4.5.6/index.html">com.package2:4.5.6</a>, <span>com.externalpackage:7.8.9</span></dd>
<dt class="runtime-data hidden">Known usages:</dt>
<dd id="known-usages" class="runtime-data hidden"></dd>
<dt class="runtime-data hidden">All versions:</dt>

View File

@@ -74,7 +74,7 @@
<div class="member-modifiers"></div>
</div>
<div class="member-main">
<div class="member-signature"><span class="name-decl">favoriteFruit</span>: <a href="https://example.com/Fruit/index.html" class="name-ref">Fruit</a><a class="member-source-link" href="https://example.com/birds/v0.5.0/blob/Bird.pkl#L123-L456">Source</a></div>
<div class="member-signature"><span class="name-decl">favoriteFruit</span>: <a href="../../../../fruit/1.0.5/Fruit/index.html" class="name-ref">Fruit</a><a class="member-source-link" href="https://example.com/birds/v0.5.0/blob/Bird.pkl#L123-L456">Source</a></div>
</div>
</div>
</li>

View File

@@ -37,9 +37,9 @@
<dt class="">Issue tracker:</dt>
<dd><a href="https://example.com/birds/issues">https://example.com/birds/issues</a></dd>
<dt class="">Dependencies:</dt>
<dd><a href="https://example.com/fruit-docs">fruit:1.0.5</a></dd>
<dd><a href="../../fruit/1.0.5/index.html">fruit:1.0.5</a></dd>
<dt class="">Checksum:</dt>
<dd>6f18af649b47986530cd6dc39abe17888db2701bc5381c385fb86a32fda2685e</dd>
<dd>b27206b80f4f227752b6f02143887f3ea41e554542cec38f7b572b987566c4de</dd>
<dt class="runtime-data hidden">Known usages:</dt>
<dd id="known-usages" class="runtime-data hidden"></dd>
<dt class="runtime-data hidden">All versions:</dt>