Skip to content

Commit ef83b79

Browse files
committed
Migrate renderer away from dokka
1 parent 23ba6c3 commit ef83b79

34 files changed

+916
-233
lines changed

scala3doc/resources/dotty_res/images/scala_logo.svg

Lines changed: 0 additions & 32 deletions
This file was deleted.

scala3doc/src/dotty/dokka/DottyDokkaPlugin.scala

Lines changed: 1 addition & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@ import org.jetbrains.dokka.base.resolvers.shared._
2727
import dotty.dokka.site.NavigationCreator
2828
import dotty.dokka.site.SitePagesCreator
2929
import dotty.dokka.site.StaticSiteContext
30-
import dotty.dokka.site.SiteResourceManager
3130
import dotty.dokka.site.StaticSiteLocationProviderFactory
3231

3332
/** Main Dokka plugin for the doctool.
@@ -62,20 +61,6 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
6261
.overrideExtension(dokkaBase.getModulesAndPackagesDocumentation)
6362
)
6463

65-
val scalaResourceInstaller = extend(
66-
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
67-
.fromRecipe{ case ctx @ given DokkaContext => new ScalaResourceInstaller }
68-
.name("scalaResourceInstaller")
69-
.after(dokkaBase.getCustomResourceInstaller)
70-
)
71-
72-
val scalaEmbeddedResourceAppender = extend(
73-
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
74-
.fromInstance(new ScalaEmbeddedResourceAppender())
75-
.after(dokkaBase.getCustomResourceInstaller)
76-
.name("scalaEmbeddedResourceAppender")
77-
)
78-
7964
val scalaDocumentableToPageTranslator = extend(
8065
_.extensionPoint(CoreExtensions.INSTANCE.getDocumentableToPageTranslator)
8166
.fromRecipe { case ctx @ given DokkaContext =>
@@ -90,7 +75,7 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
9075

9176
val ourRenderer = extend(
9277
_.extensionPoint(CoreExtensions.INSTANCE.getRenderer)
93-
.fromRecipe { case ctx @ given DokkaContext => new ScalaHtmlRenderer }
78+
.fromRecipe { case ctx @ given DokkaContext => new DokkaScalaHtmlRenderer }
9479
.overrideExtension(dokkaBase.getHtmlRenderer)
9580
)
9681

@@ -129,16 +114,6 @@ class DottyDokkaPlugin extends DokkaJavaPlugin:
129114
.overrideExtension(dokkaBase.getNavigationPageInstaller)
130115
)
131116

132-
val customDocumentationResources = extend(
133-
_.extensionPoint(dokkaBase.getHtmlPreprocessors)
134-
.fromRecipe{ case c @ given DokkaContext => new SiteResourceManager }
135-
.name("customDocumentationResources")
136-
.after(
137-
scalaEmbeddedResourceAppender.getValue,
138-
customDocumentationProvider.getValue
139-
)
140-
)
141-
142117
val locationProvider = extend(
143118
_.extensionPoint(dokkaBase.getLocationProviderFactory)
144119
.fromRecipe { case c @ given DokkaContext => new StaticSiteLocationProviderFactory }

scala3doc/src/dotty/dokka/ScalaModuleCreator.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ class ScalaModuleProvider(using ctx: DocContext) extends SourceToDocumentableTra
4545
JMap(),
4646
null,
4747
sourceSet.toSet,
48-
PropertyContainer.Companion.empty() plus ModuleExtension(result.flatMap(flattenMember).toMap)
48+
PropertyContainer.Companion.empty() plus ModuleExtension(flattenMember(topLevelPackage).toMap)
4949
)
5050

5151
transformers.foldLeft(module)( (module, transformer) => transformer(module) )

scala3doc/src/dotty/dokka/compat.scala

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import java.util.Collections
1515
import org.jetbrains.dokka.plugability._
1616
import kotlin.jvm.JvmClassMappingKt.getKotlinClass
1717
import org.jetbrains.dokka.links._
18+
import java.nio.file.Path
1819

1920
val U: kotlin.Unit = kotlin.Unit.INSTANCE
2021

@@ -42,6 +43,8 @@ extension (dri: DRI)
4243
extra = Option(dri.getExtra).fold(null)(e => raw"\[origin:(.*)\]".r.replaceAllIn(e, ""))
4344
)
4445

46+
def isStaticFile = dri.getExtra == staticFileExtra
47+
4548
def location: String = dri.getPackageName
4649

4750
def anchor: Option[String] = Option(dri.getClassNames).filterNot(_.isEmpty)
@@ -57,7 +60,11 @@ extension (dri: DRI)
5760
extra: String = dri.extra
5861
) = new DRI(location, anchor.getOrElse(""), null, target, extra)
5962

63+
val staticFileExtra = "___staticFile___"
64+
6065
object DRI:
66+
def forPath(path: Path) = apply(location = path.toString, extra = staticFileExtra)
67+
6168
def apply(
6269
location: String = "",
6370
anchor: Option[String] = None,

scala3doc/src/dotty/dokka/preprocessors/ScalaEmbeddedResourceApppender.scala

Lines changed: 0 additions & 46 deletions
This file was deleted.

scala3doc/src/dotty/dokka/preprocessors/ScalaResourceInstaller.scala

Lines changed: 0 additions & 38 deletions
This file was deleted.

scala3doc/src/dotty/dokka/site/SiteResourceManager.scala

Lines changed: 0 additions & 49 deletions
This file was deleted.

scala3doc/src/dotty/dokka/site/StaticPageNode.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ case class StaticPageNode(
2222
def title(): String = template.title
2323
def hasFrame(): Boolean = template.hasFrame
2424

25+
def dri = getDri.iterator.next()
26+
2527
override def modified(
2628
name: String,
2729
content: ContentNode,

scala3doc/src/dotty/dokka/site/StaticSiteContext.scala

Lines changed: 44 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,16 @@ class StaticSiteContext(
2828

2929
var memberLinkResolver: String => Option[DRI] = _ => None
3030

31-
def indexPage(): Option[StaticPageNode] =
31+
def indexTemplate(): Seq[LoadedTemplate] =
3232
val files = List(new File(root, "index.html"), new File(root, "index.md")).filter { _.exists() }
3333

3434
if files.size > 1 then
3535
val msg = s"ERROR: Multiple root index pages found: ${files.map(_.getAbsolutePath)}"
3636
report.error(msg)
3737

38-
files.flatMap(loadTemplate(_, isBlog = false)).headOption.map(templateToPage)
38+
files.flatMap(loadTemplate(_, isBlog = false)).take(1)
39+
40+
def indexPage(): Option[StaticPageNode] = indexTemplate().headOption.map(templateToPage)
3941

4042
lazy val layouts: Map[String, TemplateFile] =
4143
val layoutRoot = new File(root, "_layouts")
@@ -49,6 +51,27 @@ class StaticSiteContext(
4951

5052
lazy val templates: Seq[LoadedTemplate] = sideBarConfig.fold(loadAllFiles())(_.map(loadSidebarContent))
5153

54+
lazy val orphanedTemplates: Seq[LoadedTemplate] = {
55+
def doFlatten(t: LoadedTemplate): Seq[Path] =
56+
t.file.toPath +: t.children.flatMap(doFlatten)
57+
val mainFiles = templates.flatMap(doFlatten)
58+
59+
val allPaths =
60+
if !Files.exists(docsPath) then Nil
61+
else Files.walk(docsPath, FileVisitOption.FOLLOW_LINKS).iterator().asScala.toList
62+
63+
val orphanedFiles = allPaths.filterNot { p =>
64+
def name = p.getFileName.toString
65+
def isMain = name == "index.html" || name == "index.md"
66+
mainFiles.contains(p) || (isMain && mainFiles.contains(p.getParent))
67+
}.filter { p =>
68+
val name = p.getFileName.toString
69+
name.endsWith(".md") || name.endsWith(".html")
70+
}
71+
72+
orphanedFiles.flatMap(p => loadTemplate(p.toFile, isBlog = false))
73+
}
74+
5275
lazy val mainPages: Seq[StaticPageNode] = templates.map(templateToPage)
5376

5477
val docsPath = root.toPath.resolve("docs")
@@ -168,7 +191,25 @@ class StaticSiteContext(
168191
pathsDri.getOrElse(memberLinkResolver(link).toList)
169192

170193
def driFor(dest: Path): DRI =
171-
DRI(location = root.toPath.relativize(dest).iterator.asScala.mkString("."))
194+
val rawFilePath = root.toPath.relativize(dest)
195+
val pageName = dest.getFileName.toString
196+
val dotIndex = pageName.lastIndexOf('.')
197+
198+
val relativePath =
199+
if rawFilePath.startsWith(Paths.get("blog","_posts")) then
200+
val regex = raw"(\d*)-(\d*)-(\d*)-(.*)\..*".r
201+
pageName.toString match
202+
case regex(year, month, day, name) =>
203+
rawFilePath.getParent.resolveSibling(Paths.get(year, month, day, name))
204+
case _ =>
205+
val msg = s"Relative path for blog: $rawFilePath doesn't match `yyy-mm-dd-name.md` format."
206+
report.warn(msg, dest.toFile)
207+
rawFilePath.resolveSibling(pageName.substring(0, dotIndex))
208+
else
209+
if (dotIndex < 0) rawFilePath.resolve("index")
210+
else rawFilePath.resolveSibling(pageName.substring(0, dotIndex))
211+
212+
DRI.forPath(relativePath)
172213

173214
def relativePath(myTemplate: LoadedTemplate) = root.toPath.relativize(myTemplate.file.toPath)
174215

scala3doc/src/dotty/dokka/site/common.scala

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,24 @@ abstract class BaseStaticSiteProcessor(using ctx: DocContext)
125125

126126
protected def transform(input: RootPageNode, ctx: StaticSiteContext): RootPageNode
127127

128+
// Needed until we will migrate away from dokka
129+
case class FakeContentPage(
130+
dri: DRI,
131+
override val getContent: ContentNode) extends ContentPage:
132+
override val getName: String = ""
133+
override val getChildren: JList[PageNode] = JList()
134+
override val getEmbeddedResources: JList[String] = JList()
135+
override def getDocumentable: Documentable = null
136+
override def modified(
137+
name: String,
138+
content: ContentNode,
139+
dri: JSet[DRI],
140+
embeddedResources: JList[String],
141+
children: JList[_ <: PageNode]
142+
): ContentPage = this
143+
override def modified(name: String, children: JList[_ <: PageNode]): PageNode = this
144+
override val getDri: JSet[DRI] = JSet(dri)
145+
128146
case class AContentPage(
129147
override val getName: String,
130148
override val getChildren: JList[PageNode],

0 commit comments

Comments
 (0)