@@ -31,11 +31,13 @@ import util.syntax._
3131
3232case class Site (
3333 root : JFile ,
34+ outDir : JFile ,
3435 projectTitle : String ,
3536 projectVersion : String ,
3637 projectUrl : Option [String ],
3738 projectLogo : Option [String ],
38- documentation : Map [String , Package ]
39+ documentation : Map [String , Package ],
40+ baseUrl : String
3941) extends ResourceFinder {
4042 /** Documentation serialized to java maps */
4143 private val docs : JList [_] = {
@@ -101,7 +103,7 @@ case class Site(
101103 .flatMap { file =>
102104 val BlogPost .extract(year, month, day, name, ext) = file.getName
103105 val sourceFile = toSourceFile(file)
104- val params = defaultParams(file, 2 ).withUrl(s " /blog/ $year/ $month/ $day/ $name.html " ).toMap
106+ val params = defaultParams(file).withUrl(s " /blog/ $year/ $month/ $day/ $name.html " ).toMap
105107 val page =
106108 if (ext == " md" )
107109 new MarkdownPage (file.getPath, sourceFile, params, includes, documentation)
@@ -128,11 +130,8 @@ case class Site(
128130 new SourceFile (virtualFile, Codec .UTF8 )
129131 }
130132
131- /** Copy static files to `outDir` */
132- private [this ] val defaultOutDir = new JFile (root.getAbsolutePath + JFile .separator + " _site" )
133-
134- def copyStaticFiles (outDir : JFile = defaultOutDir)(implicit ctx : Context ): this .type =
135- createOutput (outDir) {
133+ def copyStaticFiles ()(implicit ctx : Context ): this .type =
134+ createOutput {
136135 // Copy user-defined static assets
137136 staticAssets.foreach { asset =>
138137 val target = mkdirs(fs.getPath(outDir.getAbsolutePath, stripRoot(asset)))
@@ -169,15 +168,8 @@ case class Site(
169168 }
170169
171170 /** Generate default params included in each page */
172- private def defaultParams (pageLocation : JFile , additionalDepth : Int = 0 ): DefaultParams = {
171+ private def defaultParams (pageLocation : JFile ): DefaultParams =
173172 val pathFromRoot = stripRoot(pageLocation)
174- val baseUrl : String = {
175- val rootLen = root.toPath.toAbsolutePath.normalize.getNameCount
176- val assetLen = pageLocation.toPath.toAbsolutePath.normalize.getNameCount
177- " ../" * (assetLen - rootLen - 1 + additionalDepth) + " ."
178- // -1 because for root/index.html the root is the current directory (.) not its parent (../.)
179- }
180-
181173 DefaultParams (
182174 docs, docsFlattened, documentation, PageInfo (pathFromRoot),
183175 SiteInfo (
@@ -186,19 +178,18 @@ case class Site(
186178 ),
187179 sidebar
188180 )
189- }
190181
191182 /* Creates output directories if allowed */
192- private def createOutput (outDir : JFile )( op : => Unit )(implicit ctx : Context ): this .type = {
183+ private def createOutput (op : => Unit )(implicit ctx : Context ): this .type = {
193184 if (! outDir.isDirectory) outDir.mkdirs()
194185 if (! outDir.isDirectory) ctx.docbase.error(s " couldn't create output folder: $outDir" )
195186 else op
196187 this
197188 }
198189
199190 /** Generate HTML for the API documentation */
200- def generateApiDocs (outDir : JFile = defaultOutDir )(implicit ctx : Context ): this .type =
201- createOutput(outDir) {
191+ def generateApiDocs ()(implicit ctx : Context ): this .type =
192+ createOutput {
202193 def genDoc (e : model.Entity ): Unit = {
203194 ctx.docbase.echo(s " Generating doc page for: ${e.path.mkString(" ." )}" )
204195 // Suffix is index.html for packages and therefore the additional depth
@@ -212,7 +203,7 @@ case class Site(
212203 else
213204 e.path
214205 val target = mkdirs(fs.getPath(outDir.getAbsolutePath + sep + " api" + sep + path.mkString(sep) + suffix))
215- val params = defaultParams(target.toFile, - 1 ).withPosts(blogInfo).withEntity(Some (e)).toMap
206+ val params = defaultParams(target.toFile).withPosts(blogInfo).withEntity(Some (e)).toMap
216207 val page = new HtmlPage (" _layouts" + sep + " api-page.html" , layouts(" api-page" ).content, params, includes)
217208
218209 render(page).foreach { rendered =>
@@ -231,7 +222,7 @@ case class Site(
231222
232223 // generate search page:
233224 val target = mkdirs(fs.getPath(outDir.getAbsolutePath + sep + " api" + sep + " search.html" ))
234- val searchPageParams = defaultParams(target.toFile, - 1 ).withPosts(blogInfo).toMap
225+ val searchPageParams = defaultParams(target.toFile).withPosts(blogInfo).toMap
235226 val searchPage = new HtmlPage (" _layouts" + sep + " search.html" , layouts(" search" ).content, searchPageParams, includes)
236227 render(searchPage).foreach { rendered =>
237228 Files .copy(
@@ -243,8 +234,8 @@ case class Site(
243234 }
244235
245236 /** Generate HTML files from markdown and .html sources */
246- def generateHtmlFiles (outDir : JFile = defaultOutDir )(implicit ctx : Context ): this .type =
247- createOutput(outDir) {
237+ def generateHtmlFiles ()(implicit ctx : Context ): this .type =
238+ createOutput {
248239 compilableFiles.foreach { asset =>
249240 val pathFromRoot = stripRoot(asset)
250241 val sourceFile = toSourceFile(asset)
@@ -263,13 +254,13 @@ case class Site(
263254 }
264255
265256 /** Generate blog from files in `blog/_posts` and output in `outDir` */
266- def generateBlog (outDir : JFile = defaultOutDir )(implicit ctx : Context ): this .type =
267- createOutput(outDir) {
257+ def generateBlog ()(implicit ctx : Context ): this .type =
258+ createOutput {
268259 blogposts.foreach { file =>
269260 val BlogPost .extract(year, month, day, name, ext) = file.getName
270261 val sourceFile = toSourceFile(file)
271262 val date = s " $year- $month- $day 00:00:00 "
272- val params = defaultParams(file, 2 ).withPosts(blogInfo).withDate(date).toMap
263+ val params = defaultParams(file).withPosts(blogInfo).withDate(date).toMap
273264
274265 // Output target
275266 val target = mkdirs(fs.getPath(outDir.getAbsolutePath, " blog" , year, month, day, name + " .html" ))
0 commit comments