Skip to content

Commit 7adbdc3

Browse files
committed
Add search page to site structure
1 parent ccb5973 commit 7adbdc3

File tree

4 files changed

+33
-4
lines changed

4 files changed

+33
-4
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
---
2+
layout: main
3+
---
4+
5+
<h1 id="searching-for"></h1>
6+
7+
<script>
8+
document.getElementById("searching-for").innerHTML =
9+
location.search;
10+
</script>

doc-tool/src/dotty/tools/dottydoc/staticsite/Site.scala

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,18 @@ case class Site(
206206
genDoc(pkg)
207207
pkg.children.foreach(genDoc)
208208
}
209+
210+
// generate search page:
211+
val target = mkdirs(fs.getPath(outDir.getAbsolutePath + "/api/search.html"))
212+
val searchPageParams = defaultParams(target.toFile).withPosts(blogInfo).toMap
213+
val searchPage = new HtmlPage("_layouts/search.html", layouts("search").content, searchPageParams, includes)
214+
render(searchPage).foreach { rendered =>
215+
Files.copy(
216+
new ByteArrayInputStream(rendered.getBytes(StandardCharsets.UTF_8)),
217+
target,
218+
REPLACE_EXISTING
219+
)
220+
}
209221
}
210222

211223
/** Generate HTML files from markdown and .html sources */
@@ -338,6 +350,7 @@ case class Site(
338350

339351
val defaultLayouts: Map[String, Layout] = Map(
340352
"main" -> "/_layouts/main.html",
353+
"search" -> "/_layouts/search.html",
341354
"doc-page" -> "/_layouts/doc-page.html",
342355
"api-page" -> "/_layouts/api-page.html",
343356
"blog-page" -> "/_layouts/blog-page.html",

doc-tool/test/SourceFileOps.scala

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,10 @@ import model.Package
1111

1212
trait SourceFileOps {
1313
import scala.collection.JavaConverters._
14-
val site = new Site(new java.io.File("../doc-tool/resources/"), "test-site", "v0.1", Map.empty)
14+
val site = new Site(
15+
new java.io.File("../doc-tool/resources/"),
16+
"test-site", "v0.1", "http://github.com/lampepfl/dotty", Map.empty
17+
)
1518

1619
def stringToSource(path: String, sourceCode: String): SourceFile = {
1720
val virtualFile = new VirtualFile(path, path)

doc-tool/test/dotty/tools/dottydoc/staticsite/SiteTests.scala

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ class SiteTests extends DottyDocTest with SourceFileOps {
1010
assert(site.root.exists && site.root.isDirectory,
1111
s"'${site.root.getName}' is not a directory")
1212

13-
val expectedLayouts = Set("main", "index", "blog-page", "doc-page", "api-page")
13+
val expectedLayouts = Set("main", "index", "blog-page", "doc-page", "api-page", "search")
1414
assert(site.layouts.keys == expectedLayouts,
1515
s"Incorrect layouts in: ${site.layouts.keys}, expected: $expectedLayouts")
1616
}
@@ -99,9 +99,12 @@ class SiteTests extends DottyDocTest with SourceFileOps {
9999
"index.md"
100100
)
101101

102+
def printSet(xs: Set[String]): String =
103+
xs.toList.sorted.mkString("\n{\n ", ",\n ", "\n}")
104+
102105
assert(expectedAssets == assets,
103-
s"assets incorrect, found: $assets - expected $expectedAssets")
106+
s"assets incorrect, found: ${ printSet(assets) } - expected ${ printSet(expectedAssets) }")
104107
assert(expectedCompd == compd,
105-
s"compilable files incorrect, found: $compd - expected $expectedCompd")
108+
s"compilable files incorrect, found: ${ printSet(compd) } - expected ${ printSet(expectedCompd) }")
106109
}
107110
}

0 commit comments

Comments
 (0)