Permalink
Browse files

- Fix git-weirdness for post 1

- Add post 2: Strategic Scala Style
- Stage skeletons in `scratch/` folder for future posts
- Make headers render with IDs so they can be linked to
- Shorten page titles
- Better escaping
  • Loading branch information...
Li Haoyi
Li Haoyi committed Feb 13, 2016
1 parent 392aadb commit 00f45a23193e4545471a1ce4d3737ee67f657e79
View
@@ -8,13 +8,16 @@ import scalatags.Text.all.{width, height, _}
import scalatags.Text._
import ammonite.ops._
import collection.JavaConversions._
import org.pegdown.{PegDownProcessor, ToHtmlSerializer, LinkRenderer, Extensions}
import org.pegdown.ast.{VerbatimNode, ExpImageNode}
import org.pegdown.ast.{VerbatimNode, ExpImageNode, HeaderNode, TextNode}
val postsFolder = cwd/'posts
val targetFolder = cwd/'target
def sanitize(s: String): String = {
s.filter(_.isLetterOrDigit)
}
object DatesFor{
import ammonite.ops.ImplicitWd._
val commitChunks = %%('git, 'log, "--date=short").out.string.split("\n(?=commit)")
@@ -65,6 +68,20 @@ val posts = {
printer.print(" style=\"max-width: 100%; max-height: 500px\"")
printer.print(" /></div>")
}
override def visit(node: HeaderNode) = {
val tag = "h" + node.getLevel()
val id =
node
.getChildren
.collect{case t: TextNode => t.getText}
.mkString
val setId = s"id=${'"'+sanitize(id)+'"'}"
printer.print(s"<$tag $setId>")
visitChildren(node)
printer.print(s"</$tag>")
}
override def visit(node: VerbatimNode) = {
printer.println().print("<pre><code class=\"" + node.getType() + "\">");
@@ -109,7 +126,7 @@ def main(publish: Boolean = false) = {
for((name, rawHtmlContent, _, dates) <- posts){
write(
targetFolder/'post/s"${name.replace(" ", "")}.html",
targetFolder/'post/s"${sanitize(name)}.html",
postContent(name, rawHtmlContent, dates)
)
}
View
@@ -1,13 +1,15 @@
load.ivy("com.lihaoyi" %% "scalatags" % "0.5.3")
load.module(ammonite.ops.cwd/"styles.scala")
@
import scalatags.Text.all.{width, height, _}
import scalatags.Text._
import java.time.LocalDate
@
load.module(ammonite.ops.cwd/"styles.scala")
@
def pageChrome(titleText: Option[String], unNesting: String, contents: Frag): String = {
val pageTitle = titleText.getOrElse("Haoyi's Programming Blog")
val sheets = Seq(
"https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/css/bootstrap.min.css",
"https://maxcdn.bootstrapcdn.com/font-awesome/4.5.0/css/font-awesome.min.css",
@@ -23,7 +25,7 @@ def pageChrome(titleText: Option[String], unNesting: String, contents: Frag): St
meta(charset := "utf-8"),
for(sheet <- sheets)
yield link(href := sheet, rel := "stylesheet", `type` := "text/css" ),
tags2.title("lihaoyi.com" + titleText.map(": " + _).getOrElse("")),
tags2.title(pageTitle),
tags2.style(s"@media (min-width: 48em) {${WideStyles.styleSheetText}}"),
tags2.style(s"@media (max-width: 48em) {${NarrowStyles.styleSheetText}}"),
tags2.style(Styles.styleSheetText),
@@ -558,7 +558,9 @@ and generics in statically-typed languages are now table stakes, and
demonstrably improve the code from the awkward patterns that were necessary
back in 2004.
Hopefully you've enjoyed the journey!
Hopefully you've enjoyed the journey, and are as fascinated as I am by the
code and way the field has changed since then. What does the your earliest
surviving code look like? Put it on-line and post a link in the comments!
[Open-Source Scala]: https://github.com/lihaoyi
Oops, something went wrong.

0 comments on commit 00f45a2

Please sign in to comment.