@@ -3,7 +3,8 @@ package site
3
3
4
4
import java .io .File
5
5
import java .nio .file .Files
6
-
6
+ import java .nio .file .Path
7
+ import java .nio .file .Paths
7
8
8
9
import org .jetbrains .dokka .base .parsers .MarkdownParser
9
10
import org .jetbrains .dokka .base .transformers .pages .comments .DocTagToContentConverter
@@ -15,14 +16,16 @@ import org.jetbrains.dokka.pages.{ContentKind, ContentNode, DCI, PageNode}
15
16
import org .jetbrains .dokka .plugability .DokkaContext
16
17
import org .jetbrains .dokka .pages .Style
17
18
import org .jetbrains .dokka .model .DisplaySourceSet
19
+ import util .Try
18
20
19
21
import scala .collection .JavaConverters ._
20
22
21
23
class StaticSiteContext (val root : File , sourceSets : Set [SourceSetWrapper ]):
22
24
23
25
def indexPage (): Option [StaticPageNode ] =
24
26
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)}" )
26
29
files.flatMap(loadTemplate(_, isBlog = false )).headOption.map(templateToPage)
27
30
28
31
lazy val layouts : Map [String , TemplateFile ] =
@@ -52,7 +55,8 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
52
55
val allFiles = topLevelFiles.filter(_.isDirectory).flatMap(_.listFiles())
53
56
val (indexes, children) = allFiles.flatMap(loadTemplate(_)).partition(_.templateFile.isIndexPage())
54
57
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)}" )
56
60
57
61
def loadIndexPage (): TemplateFile =
58
62
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]):
68
72
Some (LoadedTemplate (templateFile, children.toList, from))
69
73
catch
70
74
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()
72
77
None
73
78
74
79
def asContent (doctag : DocTag , dri : DRI ) = new DocTagToContentConverter ().buildContent(
@@ -95,9 +100,15 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
95
100
dir(" docs" ).flatMap(_.listFiles()).flatMap(loadTemplate(_, isBlog = false ))
96
101
++ dir(" blog" ).flatMap(loadTemplate(_, isBlog = true ))
97
102
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
+
98
110
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)
101
112
val content = new PartiallyRenderedContent (
102
113
myTemplate.templateFile,
103
114
this ,
0 commit comments