Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Specify charset=utf-8 for all text docs
- Loading branch information
|
@@ -96,7 +96,7 @@ object LocalFile { |
|
|
contentEncoding = localFile.encodingOnS3.map(_ => "gzip"), |
|
|
contentLength = sourceFile.length(), |
|
|
maxAge = maxAge, |
|
|
contentType = tika.detect(localFile.sourceFile), |
|
|
contentType = resolveContentType(localFile.sourceFile), |
|
|
openInputStream = () => new FileInputStream(sourceFile) |
|
|
) |
|
|
) |
|
@@ -108,6 +108,14 @@ object LocalFile { |
|
|
|
|
|
lazy val tika = new Tika() |
|
|
|
|
|
def resolveContentType(file: File) = { |
|
|
val mimeType = tika.detect(file) |
|
|
if (mimeType.startsWith("text/") || mimeType == "application/json") |
|
|
mimeType + "; charset=utf-8" |
|
|
else |
|
|
mimeType |
|
|
} |
|
|
|
|
|
def resolveLocalFiles(implicit site: Site): Either[ErrorReport, Seq[LocalFile]] = Try { |
|
|
val files = recursiveListFiles(new File(site.rootDirectory)).filterNot(_.isDirectory) |
|
|
files map { file => |
|
|
|
@@ -379,6 +379,26 @@ class S3WebsiteSpec extends Specification { |
|
|
sentPutObjectRequest.getKey must equalTo(".vimrc") |
|
|
} |
|
|
} |
|
|
|
|
|
"content type inference" should { |
|
|
"add charset=utf-8 to all html documents" in new SiteDirectory with MockAWS { |
|
|
implicit val site = siteWithFiles(localFiles = "file.html" :: Nil) |
|
|
Push.pushSite |
|
|
sentPutObjectRequest.getMetadata.getContentType must equalTo("text/html; charset=utf-8") |
|
|
} |
|
|
|
|
|
"add charset=utf-8 to all text documents" in new SiteDirectory with MockAWS { |
|
|
implicit val site = siteWithFiles(localFiles = "file.txt" :: Nil) |
|
|
Push.pushSite |
|
|
sentPutObjectRequest.getMetadata.getContentType must equalTo("text/plain; charset=utf-8") |
|
|
} |
|
|
|
|
|
"add charset=utf-8 to all json documents" in new SiteDirectory with MockAWS { |
|
|
implicit val site = siteWithFiles(localFiles = "file.json" :: Nil) |
|
|
Push.pushSite |
|
|
sentPutObjectRequest.getMetadata.getContentType must equalTo("application/json; charset=utf-8") |
|
|
} |
|
|
} |
|
|
|
|
|
trait MockAWS extends MockS3 with MockCloudFront with Scope |
|
|
|
|
|