Skip to content

Commit bd89625

Browse files
committed
Feat: Add a blog configuration with yaml
- Add input config, who allow to define the path import - Add output config, who allow to define the path destination - Add hidden, who allow to not generate the blog
1 parent 5c2efc5 commit bd89625

File tree

2 files changed

+33
-3
lines changed

2 files changed

+33
-3
lines changed

scaladoc/src/dotty/tools/scaladoc/site/StaticSiteContext.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ class StaticSiteContext(
2323
val docsPath = root.toPath.resolve("_docs")
2424
val blogPath = root.toPath.resolve("_blog")
2525

26+
def resolveNewBlogPath(stringPath: String): Path =
27+
if stringPath.nonEmpty then root.toPath.resolve(stringPath)
28+
else blogPath
29+
2630
def relativize(path: Path): Path =
2731
if args.apiSubdirectory then
2832
docsPath.relativize(path)

scaladoc/src/dotty/tools/scaladoc/site/StaticSiteLoader.scala

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,11 +113,37 @@ class StaticSiteLoader(val root: File, val args: Scaladoc.Args)(using StaticSite
113113
StaticSiteRoot(withBlog, mappings)
114114
}
115115

116+
var hiddenBlog = false
117+
118+
def readYml: (Option[Boolean], Option[Boolean], Option[Boolean], String) =
119+
val ymlPath = root.toPath.resolve("blog.yml")
120+
if (Files.exists(ymlPath)) then
121+
val yamlContent = Source.fromFile(ymlPath.toString).getLines().mkString("\n")
122+
val hidden = if (yamlContent.contains("hidden: true")) Some(true) else None
123+
val input = if (yamlContent.contains("input:")) Some(true) else None
124+
val output = if (yamlContent.contains("output:")) Some(true) else None
125+
(hidden, input, output, yamlContent)
126+
else
127+
(None, None, None, "")
128+
116129
def loadBlog(): Option[LoadedTemplate] = {
130+
val (hidden, input, output, yamlContent) = readYml
131+
val lines = yamlContent.split("\n")
132+
val rootPath = input.collect {
133+
case true =>
134+
lines.collectFirst { case line if line.contains("input:") => line.replaceFirst("input:", "").trim }
135+
.map(ctx.resolveNewBlogPath)
136+
.getOrElse(ctx.blogPath)
137+
}.getOrElse(ctx.blogPath)
138+
val defaultDirectory = output.collect {
139+
case true =>
140+
lines
141+
.collectFirst { case line if line.contains("output:") => line.replaceFirst("output:", "").trim }
142+
.getOrElse("blog")
143+
}.getOrElse("blog")
144+
hidden.collect { case true => hiddenBlog = true }
117145
type Date = (String, String, String)
118-
val rootPath = ctx.blogPath
119-
val defaultDirectory = "blog"
120-
if (!Files.exists(rootPath)) None
146+
if (!Files.exists(rootPath) || hiddenBlog) None
121147
else {
122148
val indexPageOpt = Seq(
123149
rootPath.resolve("index.md"),

0 commit comments

Comments
 (0)