Skip to content

Add top level index page #11575

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 11, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions scaladoc/src/dotty/tools/scaladoc/renderers/HtmlRenderer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
templateToPage(indexPage, siteContext).withNewChildren(newChildren)

val hiddenPages: Seq[Page] =
staticSite.toSeq.flatMap(c => c.orphanedTemplates.map(templateToPage(_, c)))
staticSite match
case None =>
Seq(navigablePage.copy( // Add index page that is a copy of api/index.html
link = navigablePage.link.copy(dri = docsRootDRI),
children = Nil
))
case Some(site) =>
site.orphanedTemplates.map(templateToPage(_, site))

val allPages = navigablePage +: hiddenPages

Expand Down Expand Up @@ -139,10 +146,10 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
case _ => Nil
}

def renderNested(nav: Page): (Boolean, AppliedTag) =
def renderNested(nav: Page, toplevel: Boolean = false): (Boolean, AppliedTag) =
val isSelected = nav.link.dri == pageLink.dri
def linkHtml(exapnded: Boolean = false) =
val attrs = if (isSelected) Seq(cls := "selected expanded") else Nil
val attrs = if (isSelected || toplevel) Seq(cls := "selected expanded") else Nil
val icon = nav.content match {
case m: Member => navigationIcon(m)
case _ => Nil
Expand All @@ -152,15 +159,16 @@ class HtmlRenderer(rootPackage: Member, val members: Map[DRI, Member])(using ctx
nav.children match
case Nil => isSelected -> div(linkHtml())
case children =>
val nested = children.map(renderNested)
val nested = children.map(renderNested(_))
val expanded = nested.exists(_._1) || nav.link == pageLink
val attr = if expanded || isSelected then Seq(cls := "expanded") else Nil
val attr =
if expanded || isSelected || toplevel then Seq(cls := "expanded") else Nil
(isSelected || expanded) -> div(attr)(
linkHtml(expanded),
span(cls := "ar"),
nested.map(_._2)
)
renderNested(navigablePage)._2
renderNested(navigablePage, toplevel = true)._2

private def hasSocialLinks = !args.socialLinks.isEmpty

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ trait Locations(using ctx: DocContext):
case dri =>
val loc = dri.location
val fqn = loc.split(Array('.')).toList match
case "<empty>" :: Nil => "index" :: Nil
case "<empty>" :: Nil => "_empty_" :: Nil
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't it just default case other => other?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My bad, I meant case "<empty>" :: tail => "_empty_" :: tail

case "<empty>" :: tail => "_empty_" :: tail
case other => other

Expand Down