distorted-jekyll 0.5.7 → 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,28 +1,61 @@
1
1
  require 'set'
2
2
 
3
- require 'distorted-jekyll/molecule/text'
4
- require 'distorted-jekyll/static/font'
3
+ require 'distorted/molecule/font'
4
+
5
5
 
6
6
  module Jekyll
7
7
  module DistorteD
8
8
  module Molecule
9
9
  module Font
10
10
 
11
- include Text
12
-
13
- DRIVER = Cooltrainer::DistorteD::Font
14
-
15
- MEDIA_TYPE = DRIVER::MEDIA_TYPE
16
- MIME_TYPES = DRIVER::MIME_TYPES
17
-
18
- ATTRS = DRIVER::ATTRS
19
- ATTRS_DEFAULT = DRIVER::ATTRS_DEFAULT
20
- ATTRS_VALUES = DRIVER::ATTRS_VALUES
21
-
11
+ include Cooltrainer::DistorteD::Font
12
+
13
+ def render_to_output_buffer(context, output)
14
+ super
15
+ begin
16
+ filez = files.keep_if{ |f|
17
+ # Strip out all non-displayable media-types, e.g. the actual text/whatever.
18
+ f.key?(:type) && f&.dig(:type)&.media_type == 'image'.freeze
19
+ }.keep_if{ |f|
20
+ # Strip out full-size images (will have `nil`) — only display thumbnail vers
21
+ f.key?(:width) or f.key?(:height)
22
+ }.map{ |f|
23
+ # Stringify to make Liquid happy
24
+ f.transform_values(&:to_s).transform_keys(&:to_s)
25
+ }
26
+ output << parse_template.render({
27
+ 'name' => @name,
28
+ 'path' => @relative_dest,
29
+ 'alt' => abstract(:alt),
30
+ 'title' => abstract(:title),
31
+ 'sources' => filez,
32
+ 'fallback_img' => fallback_img,
33
+ })
34
+ rescue Liquid::SyntaxError => l
35
+ unless Jekyll.env == 'production'.freeze
36
+ output << parse_template(name: 'error_code'.freeze).render({
37
+ 'message' => l.message,
38
+ })
39
+ end
40
+ end
41
+ output
42
+ end
22
43
 
23
- def static_file(*args)
24
- Jekyll::DistorteD::Static::Font.new(*args)
44
+ # Return the filename of the most-compatible output image
45
+ # for use as the fallback <img> tag inside our <picture>.
46
+ def fallback_img
47
+ best_ver = nil
48
+ files.keep_if{|f| f.key?(:type) && f&.dig(:type)&.media_type == 'image'.freeze}.each{ |f|
49
+ # PNG > WebP
50
+ if f&.dig(:type)&.sub_type == 'png'.freeze || best_ver.nil?
51
+ best_ver = f
52
+ end
53
+ }
54
+ # Return the filename of the biggest matched variation,
55
+ # otherwise use the original filename.
56
+ best_ver&.dig(:name) || @name
25
57
  end
58
+
26
59
  end # Font
27
60
  end # Molecule
28
61
  end # DistorteD
@@ -1,21 +1,14 @@
1
1
  require 'set'
2
2
 
3
- require 'distorted/image'
4
- require 'distorted-jekyll/static/image'
3
+ require 'distorted/molecule/image'
4
+
5
5
 
6
6
  module Jekyll
7
7
  module DistorteD
8
8
  module Molecule
9
9
  module Image
10
10
 
11
- # Reference these instead of reassigning them. Consistency is mandatory.
12
- MEDIA_TYPE = Cooltrainer::DistorteD::Image::MEDIA_TYPE
13
- MIME_TYPES = Cooltrainer::DistorteD::Image::MIME_TYPES
14
-
15
- ATTRS = Cooltrainer::DistorteD::Image::ATTRS
16
- ATTRS_DEFAULT = Cooltrainer::DistorteD::Image::ATTRS_DEFAULT
17
- ATTRS_VALUES = Cooltrainer::DistorteD::Image::ATTRS_VALUES
18
-
11
+ include Cooltrainer::DistorteD::Image
19
12
 
20
13
  # Returns the filename we should use in the oldschool <img> tag
21
14
  # as a fallback for <picture> sources. This file should be a cropped
@@ -30,8 +23,8 @@ module Jekyll
30
23
 
31
24
  # Computes a Set of non-nil MIME::Type.sub_types for all MIME::Types
32
25
  # detected for the original media file.
33
- sub_types = @mime.keep_if{ |m|
34
- m.media_type == self.singleton_class.const_get(:MEDIA_TYPE)
26
+ sub_types = type_mars.keep_if{ |m|
27
+ m.media_type == 'image'.freeze
35
28
  }.map { |m|
36
29
  m.sub_type
37
30
  }.compact.to_set
@@ -76,12 +69,12 @@ module Jekyll
76
69
 
77
70
  output << parse_template.render({
78
71
  'name' => @name,
79
- 'path' => @dd_dest,
80
- 'alt' => attr_value(:alt),
81
- 'title' => attr_value(:title),
82
- 'href' => attr_value(:href),
83
- 'caption' => attr_value(:caption),
84
- 'loading' => attr_value(:loading),
72
+ 'path' => @relative_dest,
73
+ 'alt' => abstract(:alt),
74
+ 'title' => abstract(:title),
75
+ 'href' => abstract(:href),
76
+ 'caption' => abstract(:caption),
77
+ 'loading' => abstract(:loading),
85
78
  'sources' => filez,
86
79
  'fallback_img' => fallback_img,
87
80
  })
@@ -95,10 +88,6 @@ module Jekyll
95
88
  output
96
89
  end
97
90
 
98
- def static_file(*args)
99
- Jekyll::DistorteD::Static::Image.new(*args)
100
- end
101
-
102
91
  end
103
92
  end
104
93
  end
@@ -0,0 +1,51 @@
1
+ require 'set'
2
+
3
+ require 'distorted/checking_you_out'
4
+ require 'distorted/injection_of_love'
5
+
6
+ module Jekyll
7
+ module DistorteD
8
+ module Molecule
9
+ module LastResort
10
+
11
+
12
+ LOWER_WORLD = CHECKING::YOU::IN('application/x.distorted.last-resort')
13
+
14
+ ATTRIBUTES = Set[:alt, :title, :href, :caption]
15
+ ATTRIBUTES_DEFAULT = {}
16
+ ATTRIBUTES_VALUES = {}
17
+
18
+ # This is one of the few render methods that will be defined in JekyllLand.
19
+ define_method(CHECKING::YOU::IN('application/x.distorted.last-resort').first.distorted_method) { |*a, **k, &b|
20
+ copy_file(*a, **k, &b)
21
+ }
22
+
23
+ include Cooltrainer::DistorteD::InjectionOfLove
24
+
25
+
26
+ def render_to_output_buffer(context, output)
27
+ super
28
+ begin
29
+ output << parse_template.render({
30
+ 'name' => @name,
31
+ 'basename' => File.basename(@name, '.*'),
32
+ 'path' => @relative_dest,
33
+ 'alt' => abstract(:alt),
34
+ 'title' => abstract(:title),
35
+ 'href' => abstract(:href),
36
+ 'caption' => abstract(:caption),
37
+ })
38
+ rescue Liquid::SyntaxError => l
39
+ unless Jekyll.env == 'production'.freeze
40
+ output << parse_template(name: 'error_code'.freeze).render({
41
+ 'message' => l.message,
42
+ })
43
+ end
44
+ end
45
+ output
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -1,23 +1,49 @@
1
1
  require 'set'
2
2
 
3
- require 'distorted/pdf'
4
- require 'distorted-jekyll/static/pdf'
3
+ require 'distorted/molecule/pdf'
4
+
5
5
 
6
6
  module Jekyll
7
7
  module DistorteD
8
8
  module Molecule
9
9
  module PDF
10
10
 
11
- # Reference these instead of reassigning them. Consistency is mandatory.
12
- MEDIA_TYPE = Cooltrainer::DistorteD::PDF::MEDIA_TYPE
13
- SUB_TYPE = Cooltrainer::DistorteD::PDF::SUB_TYPE
14
- MIME_TYPES = Cooltrainer::DistorteD::PDF::MIME_TYPES
11
+ include Cooltrainer::DistorteD::PDF
15
12
 
16
- PDF_OPEN_PARAMS = Cooltrainer::DistorteD::PDF::PDF_OPEN_PARAMS
17
- ATTRS = Cooltrainer::DistorteD::PDF::ATTRS
18
- ATTRS_DEFAULT = Cooltrainer::DistorteD::PDF::ATTRS_DEFAULT
19
- ATTRS_VALUES = Cooltrainer::DistorteD::PDF::ATTRS_VALUES
20
13
 
14
+ # Generate a Hash of our PDF Open Params based on any given to the Liquid tag
15
+ # and any loaded from the defaults.
16
+ # https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
17
+ def pdf_open_params
18
+ PDF_OPEN_PARAMS.map{ |p|
19
+ if ATTRIBUTES_VALUES.dig(p) == BOOLEAN_ATTR_VALUES
20
+ # Support multiple ways people might want to express a boolean
21
+ if Set[0, '0'.freeze, false, 'false'.freeze].include?(abstract(p))
22
+ [p, '0'.freeze]
23
+ elsif Set[1, '1'.freeze, true, 'true'.freeze].include?(abstract(p))
24
+ [p, '1'.freeze]
25
+ end
26
+ else
27
+ [p, abstract(p)]
28
+ end
29
+ }.to_h
30
+ end
31
+
32
+ # Generate the URL fragment version of the PDF Open Params.
33
+ # This would be difficult / impossible to construct within Liquid
34
+ # from the individual variables, so let's just do it out here.
35
+ def pdf_open_params_url
36
+ pdf_open_params.keep_if{ |p,v|
37
+ v != nil && v != ""
38
+ }.map{ |k,v|
39
+ # The PDF Open Params docs specify `search` should be quoted.
40
+ if k == :search
41
+ "#{k}=\"#{v}\""
42
+ else
43
+ "#{k}=#{v}"
44
+ end
45
+ }.join('&')
46
+ end
21
47
 
22
48
  def render_to_output_buffer(context, output)
23
49
  super
@@ -27,45 +53,14 @@ module Jekyll
27
53
  # size of the container element.
28
54
  # We will need something like PDF.js in an <iframe> to handle this.
29
55
 
30
- # Generate a Hash of our PDF Open Params based on any given to the Liquid tag
31
- # and any loaded from the defaults.
32
- # https://www.adobe.com/content/dam/acom/en/devnet/acrobat/pdfs/pdf_open_parameters.pdf
33
- pdf_open_params = PDF_OPEN_PARAMS.map{ |p|
34
- if ATTRS_VALUES.dig(p) == Cooltrainer::DistorteD::PDF::BOOLEAN_SET
35
- # Support multiple ways people might want to express a boolean
36
- if Set[0, '0'.freeze, false, 'false'.freeze].include?(attr_value(p))
37
- [p, '0'.freeze]
38
- elsif Set[1, '1'.freeze, true, 'true'.freeze].include?(attr_value(p))
39
- [p, '1'.freeze]
40
- end
41
- else
42
- [p, attr_value(p)]
43
- end
44
- }.to_h
45
-
46
- # Generate the URL fragment version of the PDF Open Params.
47
- # This would be difficult / impossible to construct within Liquid
48
- # from the individual variables, so let's just do it out here.
49
- pdf_open_params_url = pdf_open_params.keep_if{ |p,v|
50
- v != nil && v != ""
51
- }.map{ |k,v|
52
- # The PDF Open Params docs specify `search` should be quoted.
53
- if k == :search
54
- "#{k}=\"#{v}\""
55
- else
56
- "#{k}=#{v}"
57
- end
58
- }.join('&')
59
- Jekyll.logger.debug("#{@name} PDF Open Params:", "#{pdf_open_params} #{"\u21e8".encode('utf-8').freeze} #{pdf_open_params_url}")
60
-
61
56
  output << parse_template.render({
62
57
  'name' => @name,
63
- 'path' => @dd_dest,
64
- 'alt' => attr_value(:alt),
65
- 'title' => attr_value(:title),
66
- 'height' => attr_value(:height),
67
- 'width' => attr_value(:width),
68
- 'caption' => attr_value(:caption),
58
+ 'path' => @relative_dest,
59
+ 'alt' => abstract(:alt),
60
+ 'title' => abstract(:title),
61
+ 'height' => abstract(:height),
62
+ 'width' => abstract(:width),
63
+ 'caption' => abstract(:caption),
69
64
  'pdf_open_params' => pdf_open_params_url,
70
65
  })
71
66
  rescue Liquid::SyntaxError => l
@@ -78,10 +73,6 @@ module Jekyll
78
73
  output
79
74
  end
80
75
 
81
- def static_file(*args)
82
- Jekyll::DistorteD::Static::PDF.new(*args)
83
- end
84
-
85
76
  end # PDF
86
77
  end # Molecule
87
78
  end # DistorteD
@@ -1,22 +1,14 @@
1
1
  require 'set'
2
2
 
3
- require 'distorted/svg'
4
- require 'distorted-jekyll/static/svg'
3
+ require 'distorted/molecule/svg'
4
+
5
5
 
6
6
  module Jekyll
7
7
  module DistorteD
8
8
  module Molecule
9
9
  module SVG
10
10
 
11
- # Reference these instead of reassigning them. Consistency is mandatory.
12
- MEDIA_TYPE = Cooltrainer::DistorteD::SVG::MEDIA_TYPE
13
- SUB_TYPE = Cooltrainer::DistorteD::SVG::SUB_TYPE
14
- MIME_TYPES = Cooltrainer::DistorteD::SVG::MIME_TYPES
15
-
16
- ATTRS = Cooltrainer::DistorteD::SVG::ATTRS
17
- ATTRS_DEFAULT = Cooltrainer::DistorteD::SVG::ATTRS_DEFAULT
18
- ATTRS_VALUES = Cooltrainer::DistorteD::SVG::ATTRS_VALUES
19
-
11
+ include Cooltrainer::DistorteD::SVG
20
12
 
21
13
  def render_to_output_buffer(context, output)
22
14
  super
@@ -30,12 +22,12 @@ module Jekyll
30
22
  }
31
23
  output << parse_template.render({
32
24
  'name' => @name,
33
- 'path' => @dd_dest,
34
- 'alt' => attr_value(:alt),
35
- 'title' => attr_value(:title),
36
- 'href' => attr_value(:href),
37
- 'caption' => attr_value(:caption),
38
- 'loading' => attr_value(:loading),
25
+ 'path' => @relative_dest,
26
+ 'alt' => abstract(:alt),
27
+ 'title' => abstract(:title),
28
+ 'href' => abstract(:href),
29
+ 'caption' => abstract(:caption),
30
+ 'loading' => abstract(:loading),
39
31
  'sources' => filez,
40
32
  'fallback_img' => @name,
41
33
  })
@@ -49,10 +41,6 @@ module Jekyll
49
41
  output
50
42
  end
51
43
 
52
- def static_file(*args)
53
- Jekyll::DistorteD::Static::SVG.new(*args)
54
- end
55
-
56
44
  end
57
45
  end
58
46
  end
@@ -1,22 +1,14 @@
1
1
  require 'set'
2
2
 
3
- require 'distorted/text'
4
- require 'distorted-jekyll/static/text'
3
+ require 'distorted/molecule/text'
4
+
5
5
 
6
6
  module Jekyll
7
7
  module DistorteD
8
8
  module Molecule
9
9
  module Text
10
10
 
11
- DRIVER = Cooltrainer::DistorteD::Text
12
-
13
- MEDIA_TYPE = DRIVER::MEDIA_TYPE
14
- MIME_TYPES = DRIVER::MIME_TYPES
15
-
16
- ATTRS = DRIVER::ATTRS
17
- ATTRS_DEFAULT = DRIVER::ATTRS_DEFAULT
18
- ATTRS_VALUES = DRIVER::ATTRS_VALUES
19
-
11
+ include Cooltrainer::DistorteD::Text
20
12
 
21
13
  def render_to_output_buffer(context, output)
22
14
  super
@@ -33,9 +25,9 @@ module Jekyll
33
25
  }
34
26
  output << parse_template.render({
35
27
  'name' => @name,
36
- 'path' => @dd_dest,
37
- 'alt' => attr_value(:alt),
38
- 'title' => attr_value(:title),
28
+ 'path' => @relative_dest,
29
+ 'alt' => abstract(:alt),
30
+ 'title' => abstract(:title),
39
31
  'sources' => filez,
40
32
  'fallback_img' => fallback_img,
41
33
  })
@@ -64,10 +56,6 @@ module Jekyll
64
56
  best_ver&.dig(:name) || @name
65
57
  end
66
58
 
67
- def static_file(*args)
68
- Jekyll::DistorteD::Static::Text.new(*args)
69
- end
70
-
71
59
  end # Text
72
60
  end # Molecule
73
61
  end # DistorteD
@@ -1,18 +1,12 @@
1
- require 'distorted/video'
2
- require 'distorted-jekyll/static/video'
1
+ require 'distorted/molecule/video'
2
+
3
3
 
4
4
  module Jekyll
5
5
  module DistorteD
6
6
  module Molecule
7
7
  module Video
8
8
 
9
- # Reference these instead of reassigning them. Consistency is mandatory.
10
- MEDIA_TYPE = Cooltrainer::DistorteD::Video::MEDIA_TYPE
11
- MIME_TYPES = Cooltrainer::DistorteD::Video::MIME_TYPES
12
-
13
- ATTRS = Cooltrainer::DistorteD::Video::ATTRS
14
- ATTRS_DEFAULT = Cooltrainer::DistorteD::Video::ATTRS_DEFAULT
15
- ATTRS_VALUES = Cooltrainer::DistorteD::Video::ATTRS_VALUES
9
+ include Cooltrainer::DistorteD::Video
16
10
 
17
11
  def render_to_output_buffer(context, output)
18
12
  super
@@ -21,7 +15,7 @@ module Jekyll
21
15
  'name' => @name,
22
16
  'basename' => File.basename(@name, '.*'),
23
17
  'path' => @url,
24
- 'caption' => attr_value(:caption),
18
+ 'caption' => abstract(:caption),
25
19
  })
26
20
  rescue Liquid::SyntaxError => l
27
21
  unless Jekyll.env == 'production'.freeze
@@ -33,8 +27,56 @@ module Jekyll
33
27
  output
34
28
  end
35
29
 
36
- def static_file(*args)
37
- Jekyll::DistorteD::Static::Video.new(*args)
30
+ # Return a Set of extant video variations due to inability/unwillingness
31
+ # to exactly predict GStreamer's HLS/DASH segment output naming
32
+ # even if we are controlling all variables like segment length etc.
33
+ # This implementation may give stale segments but will at least speed
34
+ # up site generation by not having to regenerate the video every time.
35
+ def destinations(dest)
36
+ wanted = Set[]
37
+ if Dir.exist?(File.join(dest, @relative_dest))
38
+ hls_dir = File.join(dest, @relative_dest, "#{basename}.hls")
39
+ if Dir.exist?(hls_dir)
40
+ wanted.merge(Dir.entries(hls_dir).to_set.map{|f| File.join(hls_dir, f)})
41
+ end
42
+ end
43
+ wanted
44
+ end
45
+
46
+ def modified?
47
+ # We can't use the standard Static::State#modified? here until
48
+ # I figure out how to cleanly get a duplicate of what would be
49
+ # the generated filenames from GStreamer's sink.
50
+ #
51
+ # For now for the sake of speeding up my site generation
52
+ # I'll assume not-modified that if the output variant (e.g. DASH/HLS)
53
+ # container dir exists and contains at least two files:
54
+ # the playlist and at least one segment.
55
+ #
56
+ # Hacky HLS-only right now until dashsink2 lands in upstream Gst.
57
+ #
58
+ # Assume modified for the sake of freshness :)
59
+ modified = true
60
+
61
+ site_dest = Jekyll::DistorteD::Floor::config(:destination).to_s
62
+ if Dir.exist?(site_dest)
63
+
64
+ dd_dest = File.join(site_dest, @relative_dest)
65
+ if Dir.exist?(dd_dest)
66
+
67
+ hls_dir = File.join(dd_dest, "#{basename}.hls")
68
+ if Dir.exist?(hls_dir)
69
+ need_filez = Set["#{basename}.m3u8"]
70
+ var_filez = Dir.entries(hls_dir).to_set
71
+ if need_filez.subset?(var_filez) and var_filez.count > 2
72
+ modified = false
73
+ end
74
+ end
75
+
76
+ end
77
+ end
78
+ Jekyll.logger.debug("#{@name} modified?", modified)
79
+ modified
38
80
  end
39
81
 
40
82
  end