@@ -30,71 +30,72 @@ abstract class Renderer(rootPackage: Member, val members: Map[DRI, Member], prot
30
30
31
31
val rootApiPage : Option [Page ] = Some (memberPage(rootPackage)).filter(_.children.nonEmpty).map(_.withTitle(ctx.args.name))
32
32
33
- val rootDocsPage : Option [Page ] = staticSite match
34
- case None => None
35
- case Some (siteContext) =>
36
- val rootTemplate = siteContext.staticSiteRoot.rootTemplate
37
-
38
- // Below code is for walking in order the tree and modifing its nodes basing on its neighbours
39
-
40
- // We add dummy guards
41
- val notHidden : Seq [Option [LoadedTemplate ]] = None +: siteContext.allTemplates.filterNot(_.hidden).map(Some (_)) :+ None
42
-
43
- // Let's gather the list of maps for each template with its in-order neighbours
44
- val newSettings : List [Map [String , Object ]] = notHidden.sliding(size = 3 , step = 1 ).map {
45
- case None :: None :: Nil =>
46
- Map .empty
47
- case prev :: mid :: next :: Nil =>
48
- def link (sibling : Option [LoadedTemplate ]): Option [String ] =
49
- def realPath (path : Path ) = if Files .isDirectory(path) then Paths .get(path.toString, " index.html" ) else path
50
- sibling.map { n =>
51
- val realMidPath = realPath(mid.get.file.toPath)
52
- val realSiblingPath = realPath(n.file.toPath)
53
- realMidPath.relativize(realSiblingPath).toString.stripPrefix(" ../" )
54
- }
55
- List (
56
- for {
57
- link <- link(prev)
58
- p <- prev
59
- } yield (
60
- " previous" -> Map (
61
- " title" -> p.templateFile.title.name,
62
- " url" -> link
63
- )
64
- ),
65
- for {
66
- link <- link(next)
67
- n <- next
68
- } yield (
69
- " next" -> Map (
70
- " title" -> n.templateFile.title.name,
71
- " url" -> link
72
- )
73
- ),
74
- ).flatten.toMap
75
- }.toList
76
-
77
- def updateSettings (templates : Seq [LoadedTemplate ], additionalSettings : ListBuffer [Map [String , Object ]]): List [LoadedTemplate ] =
78
- val updatedTemplates = List .newBuilder[LoadedTemplate ]
79
- for template <- templates do
80
- val head : Map [String , Object ] =
81
- if template.hidden then Map .empty
82
- else additionalSettings.remove(0 )
83
- val current : Map [String , Object ] = template.templateFile.settings.getOrElse(" page" , Map .empty).asInstanceOf [Map [String , Object ]]
84
- val updatedTemplateFile = template.templateFile.copy(settings = template.templateFile.settings.updated(" page" , head ++ current))
85
- updatedTemplates += template.copy(
86
- templateFile = updatedTemplateFile,
87
- children = updateSettings(template.children, additionalSettings)
88
- )
89
- updatedTemplates.result()
90
-
91
- val newTemplates = updateSettings(Seq (rootTemplate), newSettings.to(ListBuffer ))
92
- val templatePages = newTemplates.map(templateToPage(_, siteContext))
93
-
94
- val newRoot = newTemplates.head
95
-
96
- Some (newRoot).filter(r => r.children.nonEmpty || r.templateFile.rawCode.nonEmpty)
97
- .map(templateToPage(_, siteContext))
33
+ val rootDocsPage : Option [Page ] = staticSite match {
34
+ case None => None
35
+ case Some (siteContext) =>
36
+ val rootTemplate = siteContext.staticSiteRoot.rootTemplate
37
+
38
+ // Below code is for walking in order the tree and modifing its nodes basing on its neighbours
39
+
40
+ // We add dummy guards
41
+ val notHidden : Seq [Option [LoadedTemplate ]] = None +: siteContext.allTemplates.filterNot(_.hidden).map(Some (_)) :+ None
42
+
43
+ // Let's gather the list of maps for each template with its in-order neighbours
44
+ val newSettings : List [Map [String , Object ]] = notHidden.sliding(size = 3 , step = 1 ).map {
45
+ case None :: None :: Nil =>
46
+ Map .empty
47
+ case prev :: mid :: next :: Nil =>
48
+ def link (sibling : Option [LoadedTemplate ]): Option [String ] =
49
+ def realPath (path : Path ) = if Files .isDirectory(path) then Paths .get(path.toString, " index.html" ) else path
50
+ sibling.map { n =>
51
+ val realMidPath = realPath(mid.get.file.toPath)
52
+ val realSiblingPath = realPath(n.file.toPath)
53
+ realMidPath.relativize(realSiblingPath).toString.stripPrefix(" ../" )
54
+ }
55
+ List (
56
+ for {
57
+ link <- link(prev)
58
+ p <- prev
59
+ } yield (
60
+ " previous" -> Map (
61
+ " title" -> p.templateFile.title.name,
62
+ " url" -> link
63
+ )
64
+ ),
65
+ for {
66
+ link <- link(next)
67
+ n <- next
68
+ } yield (
69
+ " next" -> Map (
70
+ " title" -> n.templateFile.title.name,
71
+ " url" -> link
72
+ )
73
+ ),
74
+ ).flatten.toMap
75
+ }.toList
76
+
77
+ def updateSettings (templates : Seq [LoadedTemplate ], additionalSettings : ListBuffer [Map [String , Object ]]): List [LoadedTemplate ] =
78
+ val updatedTemplates = List .newBuilder[LoadedTemplate ]
79
+ for template <- templates do
80
+ val head : Map [String , Object ] =
81
+ if template.hidden then Map .empty
82
+ else additionalSettings.remove(0 )
83
+ val current : Map [String , Object ] = template.templateFile.settings.getOrElse(" page" , Map .empty).asInstanceOf [Map [String , Object ]]
84
+ val updatedTemplateFile = template.templateFile.copy(settings = template.templateFile.settings.updated(" page" , head ++ current))
85
+ updatedTemplates += template.copy(
86
+ templateFile = updatedTemplateFile,
87
+ children = updateSettings(template.children, additionalSettings)
88
+ )
89
+ updatedTemplates.result()
90
+
91
+ val newTemplates = updateSettings(Seq (rootTemplate), newSettings.to(ListBuffer ))
92
+ val templatePages = newTemplates.map(templateToPage(_, siteContext))
93
+
94
+ val newRoot = newTemplates.head
95
+
96
+ Some (newRoot).filter(r => r.children.nonEmpty || r.templateFile.rawCode.nonEmpty)
97
+ .map(templateToPage(_, siteContext))
98
+ }
98
99
99
100
val redirectPages : Seq [Page ] = staticSite.fold(Seq .empty)(siteContext => siteContext.redirectTemplates.map {
100
101
case (template, driFrom, driTo) =>
0 commit comments