-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
[scaladoc] fix: Only trim one newline when preprocessing the content of a markdown code snippet #21519
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
…of a markdown code snippet
KacperFKorban
commented
Aug 30, 2024
Comment on lines
+33
to
+98
val rootDocsPage: Option[Page] = staticSite match { | ||
case None => None | ||
case Some(siteContext) => | ||
val rootTemplate = siteContext.staticSiteRoot.rootTemplate | ||
|
||
// Below code is for walking in order the tree and modifing its nodes basing on its neighbours | ||
|
||
// We add dummy guards | ||
val notHidden: Seq[Option[LoadedTemplate]] = None +: siteContext.allTemplates.filterNot(_.hidden).map(Some(_)) :+ None | ||
|
||
// Let's gather the list of maps for each template with its in-order neighbours | ||
val newSettings: List[Map[String, Object]] = notHidden.sliding(size = 3, step = 1).map { | ||
case None :: None :: Nil => | ||
Map.empty | ||
case prev :: mid :: next :: Nil => | ||
def link(sibling: Option[LoadedTemplate]): Option[String] = | ||
def realPath(path: Path) = if Files.isDirectory(path) then Paths.get(path.toString, "index.html") else path | ||
sibling.map { n => | ||
val realMidPath = realPath(mid.get.file.toPath) | ||
val realSiblingPath = realPath(n.file.toPath) | ||
realMidPath.relativize(realSiblingPath).toString.stripPrefix("../") | ||
} | ||
List( | ||
for { | ||
link <- link(prev) | ||
p <- prev | ||
} yield ( | ||
"previous" -> Map( | ||
"title" -> p.templateFile.title.name, | ||
"url" -> link | ||
) | ||
), | ||
for { | ||
link <- link(next) | ||
n <- next | ||
} yield ( | ||
"next" -> Map( | ||
"title" -> n.templateFile.title.name, | ||
"url" -> link | ||
) | ||
), | ||
).flatten.toMap | ||
}.toList | ||
|
||
def updateSettings(templates: Seq[LoadedTemplate], additionalSettings: ListBuffer[Map[String, Object]]): List[LoadedTemplate] = | ||
val updatedTemplates = List.newBuilder[LoadedTemplate] | ||
for template <- templates do | ||
val head: Map[String, Object] = | ||
if template.hidden then Map.empty | ||
else additionalSettings.remove(0) | ||
val current: Map[String, Object] = template.templateFile.settings.getOrElse("page", Map.empty).asInstanceOf[Map[String, Object]] | ||
val updatedTemplateFile = template.templateFile.copy(settings = template.templateFile.settings.updated("page", head ++ current)) | ||
updatedTemplates += template.copy( | ||
templateFile = updatedTemplateFile, | ||
children = updateSettings(template.children, additionalSettings) | ||
) | ||
updatedTemplates.result() | ||
|
||
val newTemplates = updateSettings(Seq(rootTemplate), newSettings.to(ListBuffer)) | ||
val templatePages = newTemplates.map(templateToPage(_, siteContext)) | ||
|
||
val newRoot = newTemplates.head | ||
|
||
Some(newRoot).filter(r => r.children.nonEmpty || r.templateFile.rawCode.nonEmpty) | ||
.map(templateToPage(_, siteContext)) | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only changed a wrong indentation and added braces here.
hamzaremmal
approved these changes
Sep 19, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
fixes #21429