Skip to content

Commit 2436ea7

Browse files
committed
PoC for rendering blogposts in scala3doc
1 parent a6af74c commit 2436ea7

File tree

2 files changed

+12
-8
lines changed

2 files changed

+12
-8
lines changed

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

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ import org.jetbrains.dokka.model.DisplaySourceSet
1717
import scala.collection.JavaConverters._
1818

1919
class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
20-
val docsFile = new File(root, "docs")
2120

2221
def indexPage():Option[StaticPageNode] =
2322
val files = List(new File(root, "index.html"), new File(root, "index.md")).filter { _.exists() }
@@ -35,10 +34,12 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
3534
file.getName.endsWith(".html")
3635

3736

38-
private def loadTemplate(from: File): Option[LoadedTemplate] =
37+
private def loadTemplate(from: File, isBlog: Boolean = false): Option[LoadedTemplate] =
3938
if (!isValidTemplate(from)) None else
4039
try
41-
val (indexes, children) = Option(from.listFiles()).toSeq.flatten.flatMap(loadTemplate).partition(_.templateFile.isIndexPage())
40+
val topLevelFiles = if isBlog then Seq(from, new File(from, "_posts")) else Seq(from)
41+
val allFiles = topLevelFiles.filter(_.isDirectory).flatMap(_.listFiles())
42+
val (indexes, children) = allFiles.flatMap(loadTemplate(_)).partition(_.templateFile.isIndexPage())
4243
if (indexes.size > 1)
4344
println(s"ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}") // TODO (#14): provide proper error handling
4445

@@ -67,8 +68,12 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
6768
new PropertyContainer(JMap())
6869
)
6970

70-
def loadFiles(files: List[File], customChildren: List[PageNode] = Nil): List[StaticPageNode] =
71-
val all = files.flatMap(loadTemplate)
71+
def loadAllFiles() =
72+
def dir(name: String)= List(new File(root, name)).filter(_.isDirectory)
73+
loadFiles(dir("docs").flatMap(_.listFiles())) ++ loadFiles(dir("blog"), isBlog = true)
74+
75+
def loadFiles(files: List[File], isBlog: Boolean = false): List[StaticPageNode] =
76+
val all = files.flatMap(loadTemplate(_, isBlog))
7277
def flatten(it: LoadedTemplate): List[String] =
7378
List(it.relativePath(root)) ++ it.children.flatMap(flatten)
7479

@@ -92,7 +97,7 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
9297
content,
9398
JSet(dri),
9499
JList(),
95-
(myTemplate.children.map(templateToPage) ++ customChildren).asJava
100+
(myTemplate.children.map(templateToPage)).asJava
96101
)
97102

98103
all.map(templateToPage)

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,7 @@ class SitePagesCreator(ctx: Option[StaticSiteContext]) extends BaseStaticSitePro
9090
override def transform(input: RootPageNode, ctx: StaticSiteContext): RootPageNode =
9191
val (contentPage, others) = input.getChildren.asScala.toList.partition { _.isInstanceOf[ContentPage] }
9292
val modifiedModuleRoot = processRootPage(input, contentPage)
93-
val allFiles = Option(ctx.docsFile.listFiles()).toList.flatten
94-
val (indexes, children) = ctx.loadFiles(allFiles).partition(_.template.isIndexPage())
93+
val (indexes, children) = ctx.loadAllFiles().partition(_.template.isIndexPage())
9594
// TODO (#14): provide proper error handling
9695
if (indexes.size > 1) println("ERROR: Multiple index pages found $indexes}")
9796

0 commit comments

Comments
 (0)