Skip to content

Commit

Permalink
Merge pull request #329 from lightbend/checkoutDuplicateAnchors2
Browse files Browse the repository at this point in the history
Check for duplicate anchors
  • Loading branch information
pvlugter authored Jun 27, 2019
2 parents bf8f3c7 + afa4210 commit 2b8ec0a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions core/src/main/scala/com/lightbend/paradox/ParadoxProcessor.scala
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class ParadoxProcessor(reader: Reader = new Reader, writer: Writer = new Writer)
def render(location: Option[Location[Page]], rendered: Seq[(File, String)] = Seq.empty): Seq[(File, String)] = location match {
case Some(loc) =>
val page = loc.tree.label
checkDuplicateAnchors(page)
val pageProperties = properties ++ page.properties.get
val currentMapping = Path.generateTargetFile(Path.relativeLocalPath(page.rootSrcPage, page.file.getPath), globalPageMappings)
val writerContext = Writer.Context(loc, pages, reader, writer, currentMapping, sourceSuffix, targetSuffix, groups, pageProperties)
Expand All @@ -84,6 +85,17 @@ class ParadoxProcessor(reader: Reader = new Reader, writer: Writer = new Writer)
createMetadata(outputDirectory, properties) :: (roots flatMap { root => render(Some(root.location)) })
}

private def checkDuplicateAnchors(page: Page): Unit = {
val anchors = (page.headers.flatMap(_.toSet) :+ page.h1).map(_.path) ++ page.anchors.map(_.path)
anchors
.filter(_ != "#")
.groupBy(identity)
.collect { case (anchor, n) if n.size > 1 => anchor }
.foreach { anchor =>
throw new IllegalStateException(s"Duplicate anchor [$anchor] on [${page.path}]")
}
}

private def createMetadata(outputDirectory: File, properties: Map[String, String]): (File, String) = {
val metadataFilename = "paradox.json"
val target = new File(outputDirectory, metadataFilename)
Expand Down

0 comments on commit 2b8ec0a

Please sign in to comment.