src/main/scala/s3/website/model/push.scala in s3_website-2.9.0 vs src/main/scala/s3/website/model/push.scala in s3_website-2.10.0
- old
+ new
@@ -92,9 +92,32 @@
}
)
}
}
+ lazy val cacheControl: Option[String] = {
+ type GlobsMap = Map[String, String]
+ site.config.cache_control.flatMap { (intOrGlobs: Either[String, GlobsMap]) =>
+ type GlobsSeq = Seq[(String, String)]
+ def respectMostSpecific(globs: GlobsMap): GlobsSeq = globs.toSeq.sortBy(_._1.length).reverse
+ intOrGlobs
+ .right.map(respectMostSpecific)
+ .fold(
+ (cacheCtrl: String) => Some(cacheCtrl),
+ (globs: GlobsSeq) => {
+ val matchingCacheControl = (glob: String, cacheControl: String) =>
+ rubyRuntime.evalScriptlet(
+ s"""|# encoding: utf-8
+ |File.fnmatch('$glob', "$s3Key")""".stripMargin)
+ .toJava(classOf[Boolean])
+ .asInstanceOf[Boolean]
+ val fileGlobMatch = globs find Function.tupled(matchingCacheControl)
+ fileGlobMatch map (_._2)
+ }
+ )
+ }
+ }
+
/**
* May throw an exception, so remember to call this in a Try or Future monad
*/
lazy val md5 = Upload md5 originalFile
}