-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Add support for mapping blog directory. Set blog directory to 'blog' #14483
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
index: index.md | ||
subsection: | ||
- title: Blog | ||
directory: blog | ||
- title: Usage | ||
directory: docs/usage | ||
subsection: | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -89,7 +89,23 @@ class StaticSiteLoader(val root: File, val args: Scaladoc.Args)(using StaticSite | |
val templateFile = loadTemplateFile(file, title) | ||
LoadedTemplate(templateFile, List.empty, pathFromRoot.resolve(file.getName).toFile, hidden) | ||
} | ||
val rootTemplate = LoadedTemplate(rootIndex, yamlRoot.nested.map(c => loadChild(ctx.docsPath)(c)) ++ loadBlog(), rootDest) | ||
val blogDirectory = yamlRoot.nested.collect { | ||
case blog @ Sidebar.Category(optionTitle, optionIndexPath, nested, dir) | ||
if optionTitle.exists(_ == "Blog") => blog | ||
}.headOption.flatMap(_.directory) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. FYI, you could use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Or, maybe it could improve maintainability to use |
||
|
||
val rootChildrenWithoutBlog = yamlRoot.nested.filter { | ||
case Sidebar.Category(optionTitle, optionIndexPath, nested, dir) | ||
if optionTitle.exists(_ == "Blog") => false | ||
case _ => true | ||
} | ||
|
||
val rootTemplate = | ||
LoadedTemplate( | ||
rootIndex, | ||
rootChildrenWithoutBlog.map(c => loadChild(ctx.docsPath)(c)) ++ loadBlog(blogDirectory), | ||
rootDest | ||
) | ||
val mappings = createMapping(rootTemplate) | ||
StaticSiteRoot(rootTemplate, mappings) | ||
} | ||
|
@@ -113,8 +129,9 @@ class StaticSiteLoader(val root: File, val args: Scaladoc.Args)(using StaticSite | |
StaticSiteRoot(withBlog, mappings) | ||
} | ||
|
||
def loadBlog(): Option[LoadedTemplate] = { | ||
def loadBlog(directory: Option[String] = None): Option[LoadedTemplate] = { | ||
type Date = (String, String, String) | ||
val destDirectory = directory.getOrElse("_blog") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find it weird to use |
||
val rootPath = ctx.blogPath | ||
if (!Files.exists(rootPath)) None | ||
else { | ||
|
@@ -131,7 +148,7 @@ class StaticSiteLoader(val root: File, val args: Scaladoc.Args)(using StaticSite | |
val indexTemplateOpt = indexPageOpt.map(p => loadTemplateFile(p.toFile)) | ||
|
||
val indexPage = indexTemplateOpt.getOrElse(emptyTemplate(rootPath.resolve("index.html").toFile, "Blog")) | ||
val indexDest = ctx.docsPath.resolve("_blog").resolve("index.html") | ||
val indexDest = ctx.docsPath.resolve(destDirectory).resolve("index.html") | ||
val regex = raw"(\d*)-(\d*)-(\d*)-(.*)".r | ||
def splitDateName(tf: TemplateFile): (Date, String) = tf.file.getName match | ||
case regex(year, month, day, name) => ((year, month, day), name) | ||
|
@@ -150,7 +167,7 @@ class StaticSiteLoader(val root: File, val args: Scaladoc.Args)(using StaticSite | |
.map { postFile => | ||
val templateFile = loadTemplateFile(postFile) | ||
val ((year, month, day), name) = splitDateName(templateFile) | ||
val destPath = ctx.docsPath.resolve("_blog").resolve(year).resolve(month).resolve(day).resolve(name) | ||
val destPath = ctx.docsPath.resolve(destDirectory).resolve(year).resolve(month).resolve(day).resolve(name) | ||
val date = dateFrom(templateFile, s"$year-$month-$day") | ||
date -> LoadedTemplate(templateFile, List.empty, destPath.toFile) | ||
}.sortBy(_._1).reverse.map(_._2) | ||
|
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.
What do you think of relaxing the requirement of providing a
directory
(and usingblog
as a default value)?What happens if someone creates a directory
_blog
but no entrytitle: Blog
in the sidebar? Conversely, is it possible to create an entry withtitle: Blog
andindex: _news/index.html
, for instance (to read the blog posts from the_news
directory)?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.
There I also have some doubts. It's nice to be able to map blog directory but on the other hand it creates additional complexity to configuration. My idea was to generate blog regardless of presence Blog subsection in YAML (The only condition would be existence of "_blog" directory) but it might be misleading since we use YAML to define which static sites appear. I see two solutions here:
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.
I think it’s good to allow the users to define the blog entry in their sidebar so that they can control where it appears in the navigation menu. Yes, the blog is a special entry. Maybe it requires a special AST node as well to make this clearer in the logic?
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.
Do you think we should control whether blog should be rendered with yaml config?
Uh oh!
There was an error while loading. Please reload this page.
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.
I think for now we should just repair dotty.epfl.ch (implement the second solution) and create an issue about customizing Blog with YAML. Especially since we want to make the default blog directory to 'blog'.