@@ -3,7 +3,8 @@ package site
33
44import java .io .File
55import java .nio .file .Files
6-
6+ import java .nio .file .Path
7+ import java .nio .file .Paths
78
89import org .jetbrains .dokka .base .parsers .MarkdownParser
910import org .jetbrains .dokka .base .transformers .pages .comments .DocTagToContentConverter
@@ -15,14 +16,16 @@ import org.jetbrains.dokka.pages.{ContentKind, ContentNode, DCI, PageNode}
1516import org .jetbrains .dokka .plugability .DokkaContext
1617import org .jetbrains .dokka .pages .Style
1718import org .jetbrains .dokka .model .DisplaySourceSet
19+ import util .Try
1820
1921import scala .collection .JavaConverters ._
2022
2123class StaticSiteContext (val root : File , sourceSets : Set [SourceSetWrapper ]):
2224
2325 def indexPage (): Option [StaticPageNode ] =
2426 val files = List (new File (root, " index.html" ), new File (root, " index.md" )).filter { _.exists() }
25- if (files.size > 1 ) println(s " ERROR: Multiple root index pages found: ${files.map(_.getAbsolutePath)}" ) // TODO (#14): provide proper error handling
27+ // TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
28+ if (files.size > 1 ) println(s " ERROR: Multiple root index pages found: ${files.map(_.getAbsolutePath)}" )
2629 files.flatMap(loadTemplate(_, isBlog = false )).headOption.map(templateToPage)
2730
2831 lazy val layouts : Map [String , TemplateFile ] =
@@ -52,7 +55,8 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
5255 val allFiles = topLevelFiles.filter(_.isDirectory).flatMap(_.listFiles())
5356 val (indexes, children) = allFiles.flatMap(loadTemplate(_)).partition(_.templateFile.isIndexPage())
5457 if (indexes.size > 1 )
55- println(s " ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}" ) // TODO (#14): provide proper error handling
58+ // TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
59+ println(s " ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}" )
5660
5761 def loadIndexPage (): TemplateFile =
5862 val indexFiles = from.listFiles { file => file.getName == " index.md" || file.getName == " index.html" }
@@ -68,7 +72,8 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
6872 Some (LoadedTemplate (templateFile, children.toList, from))
6973 catch
7074 case e : RuntimeException =>
71- e.printStackTrace() // TODO (#14): provide proper error handling
75+ // TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
76+ e.printStackTrace()
7277 None
7378
7479 def asContent (doctag : DocTag , dri : DRI ) = new DocTagToContentConverter ().buildContent(
@@ -95,9 +100,15 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
95100 dir(" docs" ).flatMap(_.listFiles()).flatMap(loadTemplate(_, isBlog = false ))
96101 ++ dir(" blog" ).flatMap(loadTemplate(_, isBlog = true ))
97102
103+ def driForLink (template : TemplateFile , link : String ): Try [DRI ] = Try (driFor(
104+ if link.startsWith(" /" ) then root.toPath.resolve(link.drop(1 ))
105+ else template.file.toPath.getParent().resolve(link)
106+ ))
107+
108+ private def driFor (dest : Path ): DRI = mkDRI(s " _. ${root.toPath.relativize(dest)}" )
109+
98110 def templateToPage (myTemplate : LoadedTemplate ): StaticPageNode =
99- def pathToDRI (path : String ) = mkDRI(s " _. $path" )
100- val dri = pathToDRI(myTemplate.relativePath(root))
111+ val dri = driFor(myTemplate.file.toPath)
101112 val content = new PartiallyRenderedContent (
102113 myTemplate.templateFile,
103114 this ,
0 commit comments