Skip to content

Scala3doc: Adjust generated links for blogs to avoid 404 errors #10507

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
Nov 26, 2020
Merged
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
24 changes: 20 additions & 4 deletions scala3doc/src/dotty/dokka/site/StaticSiteLocationProvider.scala
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import org.jetbrains.dokka.pages.RootPageNode
import org.jetbrains.dokka.plugability.DokkaContext

import scala.collection.JavaConverters._
import java.nio.file.Paths
import java.nio.file.Path

class StaticSiteLocationProviderFactory(private val ctx: DokkaContext) extends LocationProviderFactory:
override def getLocationProvider(pageNode: RootPageNode): LocationProvider =
Expand All @@ -24,11 +26,23 @@ class StaticSiteLocationProvider(ctx: DokkaContext, pageNode: RootPageNode)
val rawFilePath = context.root.toPath.relativize(page.template.file.toPath)
val pageName = page.template.file.getName
val dotIndex = pageName.lastIndexOf('.')
val newPath =
if (dotIndex < 0) rawFilePath.resolve("index")
else rawFilePath.resolveSibling(pageName.substring(0, dotIndex))

newPath.iterator.asScala.map(_.toString).toList.asJava
if (isBlogPostPath(rawFilePath)) {
val regex = raw"(\d*)-(\d*)-(\d*)-(.*)\..*".r
val blogPostPath = pageName.toString match {
case regex(year, month, day, name) =>
rawFilePath.getParent.resolveSibling(Paths.get(year, month, day, name))
case _ =>
println(s"Blog file at path: $rawFilePath doesn't match desired format.")
rawFilePath.resolveSibling(pageName.substring(0, dotIndex))
}
blogPostPath.iterator.asScala.map(_.toString).toList.asJava
} else {
val newPath =
if (dotIndex < 0) rawFilePath.resolve("index")
else rawFilePath.resolveSibling(pageName.substring(0, dotIndex))
newPath.iterator.asScala.map(_.toString).toList.asJava
}
}

case page: ContentPage if page.getDri.contains(docsDRI) =>
Expand All @@ -43,6 +57,8 @@ class StaticSiteLocationProvider(ctx: DokkaContext, pageNode: RootPageNode)
case _ =>
jpath

private def isBlogPostPath(path: Path): Boolean = path.startsWith(Paths.get("blog","_posts"))

override val getPathsIndex: JMap[PageNode, JList[String]] =
super.getPathsIndex.asScala.mapValuesInPlace(updatePageEntry).asJava

Expand Down