mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Fix doc dependency link (#1078)
This commit is contained in:
@@ -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 {
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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>
|
||||
|
||||
Reference in New Issue
Block a user