s3_website 2.14.3 → 2.15.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 12868fe79f5723e84fb08c7e73d8349fedceb99e
4
- data.tar.gz: 54a74071dc921c0427c42776bf0bfb103740b349
3
+ metadata.gz: 3817c71cb9e62df94035abdb0c2a82518086f31f
4
+ data.tar.gz: f865711262a86542bbbbe79889fed47695f00ced
5
5
  SHA512:
6
- metadata.gz: d4ab32468213f00239e201c02bd0cf102e893576ca5772589b66fb0231225c2e0386b1c8251e4deed5c16f0aa4a1e1310fe11b2936b4d3b13e5306cc99a8b0c4
7
- data.tar.gz: 4c95f59e5f2cf98e1481b136cd09109ec772cca2bd82bbdf7e2a3f8e5127478818e44bc36d098e41e039f84bfd36cc78016b606074e3546f7c255defd5b17d99
6
+ metadata.gz: b8fdf4cc12c1e05ed5189e1ad0e447e83794c510f7347786eca40cc08d22336fafb6f5d88a439451f7fd7d1002529b8aab9407c064f065993c991b8d43cae4ee
7
+ data.tar.gz: 462f392810758a973b71aece6a052651d95978b98740ae421cb6b35373c5167bcccf31e4d1d19ee4643ba3a83335714dafd3fe551c1cf4b55e621e8d41e809c8
data/README.md CHANGED
@@ -146,6 +146,18 @@ cache_control:
146
146
  After changing the `cache_control` setting, push with the `--force` option.
147
147
  Force-pushing allows you to update the S3 object metadata of existing files.
148
148
 
149
+ ### Content type detection
150
+
151
+ By default, s3_website automatically detects the content type of a file with the help of Apache Tika.
152
+
153
+ For some file types Tika's auto detection does not work correctly. Should this problem affect you, use the `content_type`
154
+ setting to override Tika's decision:
155
+
156
+ ```yaml
157
+ content_type:
158
+ "*.myextension": application/my-custom-type
159
+ ```
160
+
149
161
  ### Gzip Compression
150
162
 
151
163
  If you choose, you can use compress certain file types before uploading them to
@@ -513,42 +525,7 @@ Creux](https://github.com/pcreux) on
513
525
  [jekyll-s3](https://github.com/laurilehmijoki/jekyll-s3), this project would not
514
526
  exist.
515
527
 
516
- Contributors (in alphabetical order)
517
- * Akshay Karle
518
- * Alan deLevie
519
- * Almir Sarajčić
520
- * Andrew T. Baker
521
- * Cory Kaufman-Schofield
522
- * Chris Kelly
523
- * Chris Moos
524
- * Christian Grobmeier
525
- * Christopher Petersen
526
- * David Michael Barr
527
- * David Raffensperger
528
- * Douglas Teoh
529
- * Greg Karékinian
530
- * Ian Hattendorf
531
- * John Allison
532
- * Jon Frisby
533
- * Jordan White
534
- * Justin Latimer
535
- * László Bácsi
536
- * Mason Turner
537
- * Michael Bleigh
538
- * maxberger
539
- * Philip I. Thomas
540
- * Philippe Creux
541
- * Piotr Janik
542
- * PJ Kelly
543
- * Rodrigo Reis
544
- * Ross Hunter
545
- * Shigeaki Matsumura
546
- * stanislas
547
- * Tate Johnson
548
- * Toby Marsden
549
- * Tom Bell
550
- * Trevor Fitzgerald
551
- * Zee Spencer
528
+ See the [Contributors](https://github.com/laurilehmijoki/s3_website/graphs/contributors).
552
529
 
553
530
  ## Community articles
554
531
 
data/changelog.md CHANGED
@@ -2,9 +2,15 @@
2
2
 
3
3
  This project uses [Semantic Versioning](http://semver.org).
4
4
 
5
+ ## 2.15.0
6
+
7
+ * Add new setting `content_type`
8
+
9
+ See <https://github.com/laurilehmijoki/s3_website/issues/232> for discussion
10
+
5
11
  ## 2.14.3
6
12
 
7
- Fix mime type of an already-gzipped .json file
13
+ * Fix mime type of an already-gzipped .json file
8
14
 
9
15
  See <https://github.com/laurilehmijoki/s3_website/pull/231>
10
16
 
@@ -1,3 +1,3 @@
1
1
  module S3Website
2
- VERSION = '2.14.3'
2
+ VERSION = '2.15.0'
3
3
  end
@@ -26,6 +26,7 @@ case class Config(
26
26
  s3_reduced_redundancy: Option[Boolean],
27
27
  cloudfront_distribution_id: Option[String],
28
28
  cloudfront_invalidate_root: Option[Boolean],
29
+ content_type: Option[S3KeyGlob[String]],
29
30
  redirects: Option[Map[S3Key, String]],
30
31
  concurrency_level: Int,
31
32
  cloudfront_wildcard_invalidation: Option[Boolean],
@@ -112,6 +113,23 @@ object Config {
112
113
  yamlValue getOrElse Left(ErrorReport(s"The key $key has to have a string or (string -> string) value"))
113
114
  }
114
115
 
116
+ def loadContentType(implicit unsafeYaml: UnsafeYaml): Either[ErrorReport, Option[S3KeyGlob[String]]] = {
117
+ val key = "content_type"
118
+ val yamlValue = for {
119
+ contentTypeOption <- loadOptionalValue(key)
120
+ } yield {
121
+ // TODO below we are using an unsafe call to asInstance of – we should implement error handling
122
+ Right(contentTypeOption.map { xs =>
123
+ val globs: Map[String, String] = xs.asInstanceOf[util.Map[String, String]].toMap
124
+ S3KeyGlob(globs)
125
+ }
126
+ )
127
+ }
128
+
129
+ yamlValue getOrElse Left(ErrorReport(s"The key $key has to have a string or (string -> string) value"))
130
+ }
131
+
132
+
115
133
  def loadEndpoint(implicit unsafeYaml: UnsafeYaml): Either[ErrorReport, Option[S3Endpoint]] =
116
134
  loadOptionalString("s3_endpoint").right flatMap { endpointString =>
117
135
  endpointString.map(S3Endpoint.forString) match {
@@ -49,6 +49,7 @@ object Site {
49
49
  s3_reduced_redundancy <- loadOptionalBoolean("s3_reduced_redundancy").right
50
50
  cloudfront_distribution_id <- loadOptionalString("cloudfront_distribution_id").right
51
51
  cloudfront_invalidate_root <- loadOptionalBoolean("cloudfront_invalidate_root").right
52
+ content_type <- loadContentType.right
52
53
  concurrency_level <- loadOptionalInt("concurrency_level").right
53
54
  cloudfront_wildcard_invalidation <- loadOptionalBoolean("cloudfront_wildcard_invalidation").right
54
55
  redirects <- loadRedirects(s3_key_prefix).right
@@ -77,6 +78,7 @@ object Site {
77
78
  s3_reduced_redundancy,
78
79
  cloudfront_distribution_id,
79
80
  cloudfront_invalidate_root,
81
+ content_type,
80
82
  redirects,
81
83
  concurrency_level.fold(20)(_ max 20),
82
84
  cloudfront_wildcard_invalidation,
@@ -74,7 +74,10 @@ case class Upload(originalFile: File, uploadType: UploadType)(implicit site: Sit
74
74
  } else {
75
75
  originalFile
76
76
  }
77
- val mimeType = tika.detect(file)
77
+ val mimeType =
78
+ site.config.content_type
79
+ .flatMap { _.globMatch(s3Key) }
80
+ .getOrElse { tika.detect(file) }
78
81
  if (mimeType.startsWith("text/") || mimeType == "application/json")
79
82
  mimeType + "; charset=utf-8"
80
83
  else
@@ -1052,6 +1052,18 @@ class S3WebsiteSpec extends Specification {
1052
1052
  }
1053
1053
  }
1054
1054
 
1055
+ "content_type in config file" should {
1056
+ "override tika's opinion" in new BasicSetup {
1057
+ config = """
1058
+ |content_type:
1059
+ | "*.html": text/foobar
1060
+ """.stripMargin
1061
+ setLocalFileWithContent(("index.html", "<html><body><h1>hi</h1></body></html>"))
1062
+ push()
1063
+ sentPutObjectRequest.getMetadata.getContentType must equalTo("text/foobar; charset=utf-8")
1064
+ }
1065
+ }
1066
+
1055
1067
  "ERB in config file" should {
1056
1068
  "be evaluated" in new BasicSetup {
1057
1069
  config = """
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: s3_website
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.14.3
4
+ version: 2.15.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lauri Lehmijoki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-08-06 00:00:00.000000000 Z
11
+ date: 2016-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor