Skip to content

Commit 513c934

Browse files
committed
Add blog posts summary index page
1 parent 59ef0f6 commit 513c934

File tree

4 files changed

+32
-7
lines changed

4 files changed

+32
-7
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import org.jetbrains.dokka.pages.{ContentNode, DCI, Style}
77
import org.jetbrains.dokka.base.resolvers.local.LocationProvider
88
import com.vladsch.flexmark.convert.html.FlexmarkHtmlParser
99
import org.jsoup.Jsoup
10+
import scala.collection.JavaConverters._
1011

1112
case class PartiallyRenderedContent(
1213
template: TemplateFile,

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

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,12 +78,16 @@ class StaticSiteContext(val root: File, sourceSets: Set[SourceSetWrapper]):
7878
if (indexes.size > 1)
7979
// TODO (https://github.com/lampepfl/scala3doc/issues/238): provide proper error handling
8080
println(s"ERROR: Multiple index pages for $from found in ${indexes.map(_.file)}")
81-
8281
def loadIndexPage(): TemplateFile =
8382
val indexFiles = from.listFiles { file =>file.getName == "index.md" || file.getName == "index.html" }
8483
indexFiles.size match
8584
case 0 => emptyTemplate(from, from.getName)
86-
case 1 => loadTemplateFile(indexFiles.head).copy(file = from)
85+
case 1 =>
86+
val index = loadTemplateFile(indexFiles.head)
87+
index.copy(
88+
file = from,
89+
settings = index.settings ++ Map("site" -> Map("posts" -> children.map(_.templateFile.settings("page"))))
90+
)
8791
case _ =>
8892
val msg = s"ERROR: Multiple index pages found under ${from.toPath}"
8993
throw new java.lang.RuntimeException(msg)

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -64,15 +64,15 @@ case class TemplateFile(
6464
val layoutTemplate = layout.map(name =>
6565
ctx.layouts.getOrElse(name, throw new RuntimeException(s"No layouts named $name in ${ctx.layouts}")))
6666

67-
def asJavaElement(k: String, v: Object): Object = v match
67+
def asJavaElement(o: Object): Object = o match
6868
case m: Map[_, _] => m.transform {
69-
case (k: String, v: Object) => asJavaElement(k, v)
69+
case (k: String, v: Object) => asJavaElement(v)
7070
}.asJava
71-
case l: List[_] => l.asJava
71+
case l: List[_] => l.map(x => asJavaElement(x.asInstanceOf[Object])).asJava
7272
case other => other
7373

7474
// Library requires mutable maps..
75-
val mutableProperties = HMap(ctx.properties.transform(asJavaElement).asJava)
75+
val mutableProperties = HMap(ctx.properties.transform((_, v) => asJavaElement(v)).asJava)
7676
val rendered = Template.parse(this.rawCode).render(mutableProperties)
7777
// We want to render markdown only if next template is html
7878
val code = if (isHtml || layoutTemplate.exists(!_.isHtml)) rendered else

scala3doc/src/dotty/renderers/ScalaHtmlRenderer.scala

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ import org.jetbrains.dokka.base.resolvers.local.LocationProvider
2323
import dotty.dokka.site.StaticPageNode
2424
import dotty.dokka.site.PartiallyRenderedContent
2525
import scala.util.Try
26+
import org.jsoup.Jsoup
2627

2728
class SignatureRenderer(pageContext: ContentPage, sourceSetRestriciton: JSet[DisplaySourceSet], locationProvider: LocationProvider):
2829
def link(dri: DRI): Option[String] = Option(locationProvider.resolve(dri, sourceSetRestriciton, pageContext))
@@ -248,7 +249,26 @@ class ScalaHtmlRenderer(ctx: DokkaContext) extends HtmlRenderer(ctx) {
248249
.flatMap(dri => Option(getLocationProvider.resolve(dri, sourceSets, page)))
249250
.getOrElse(str)
250251

251-
withHtml(context, prc.procsesHtml(url => Try(URL(url)).fold(_ => processLocalLink(url), _ => url)))
252+
val childrenContent = page.getChildren.asScala.collect {
253+
case p: StaticPageNode => p.getContent.asInstanceOf[PartiallyRenderedContent]//.resolved.code
254+
}
255+
256+
val html = prc.procsesHtml(url => Try(URL(url)).fold(_ => processLocalLink(url), _ => url))
257+
val htmlAst = Jsoup.parse(html)
258+
259+
childrenContent.foreach { c =>
260+
val code = Jsoup.parse(c.resolved.code)
261+
val brief = code.select("p").first()
262+
try {
263+
val li = htmlAst.select(s"li:contains(${c.template.title})")
264+
val div = li.select(s"div.excerpt")
265+
div.html(brief.toString)
266+
} catch {
267+
_ =>
268+
}
269+
}
270+
271+
withHtml(context, htmlAst.toString)
252272
case content =>
253273
build(content, context, page, /*sourceSetRestriction=*/null)
254274

0 commit comments

Comments
 (0)