From: Nick Bowler Date: Mon, 14 Jun 2021 03:43:46 +0000 (-0400) Subject: Solar Eclipse in Ottawa on 2021-06-10. X-Git-Url: https://git.draconx.ca/gitweb/homepage.git/commitdiff_plain/86d0dac7b5713b9d312dd8fea8da80132829d6e6 Solar Eclipse in Ottawa on 2021-06-10. --- diff --git a/Rules b/Rules index d3247cb..26bcb40 100644 --- a/Rules +++ b/Rules @@ -100,6 +100,7 @@ postprocess do # Find output reps corresponding to this key, if any item.reps.each do |rep| + next if rep.raw_path.nil? next unless FileUtils.identical?(item.raw_filename, rep.raw_path) @@ -179,11 +180,21 @@ compile '/license/cc*.xhtml' do end compile '/images/*.jpg', rep: :large do + w, h = FastImage.size(item.raw_filename) filename = item.identifier.without_ext + '-t1200.' + item.identifier.ext - filter :imgresize, width: 1200, height: 1200, cache: filename + filter :imgresize, width: [w, 1200].min, height: [h, 1200].min, cache: filename write filename end +compile '/images/*.jpg', rep: :medium do + w, h = FastImage.size(item.raw_filename) + filename = item.identifier.without_ext + '-t800.' + item.identifier.ext + if w > 900 or h > 900 + filter :imgresize, width: 800, height: 800, cache: filename + write filename + end +end + compile '/images/*.jpg', rep: :info do filter :imginfo layout '/imginfo.xsl' diff --git a/content/images/eclipse-20210610-clouds.jpg b/content/images/eclipse-20210610-clouds.jpg new file mode 120000 index 0000000..0fb46fb --- /dev/null +++ b/content/images/eclipse-20210610-clouds.jpg @@ -0,0 +1 @@ +../../.git/annex/objects/jf/z5/SHA512-s257188--05f166f1b15bb984ed150ea4a87e369f58dccdb3a561ae0ec2975da1e194bffc4da0a36dc14d2c6d881bc1424d1eff66241701291bab666f2a95beac66412415/SHA512-s257188--05f166f1b15bb984ed150ea4a87e369f58dccdb3a561ae0ec2975da1e194bffc4da0a36dc14d2c6d881bc1424d1eff66241701291bab666f2a95beac66412415 \ No newline at end of file diff --git a/content/images/eclipse-20210610-clouds.yaml b/content/images/eclipse-20210610-clouds.yaml new file mode 100644 index 0000000..dd687fa --- /dev/null +++ b/content/images/eclipse-20210610-clouds.yaml @@ -0,0 +1,7 @@ +--- +title: 2021-06-10 Partial Eclipse Through Clouds +copyright: 2021 Nick Bowler +license: cc-by-sa-4.0 +description: | + Almost 20 minutes after the maximum eclipse, the clouds begin to come back + to rejoin the fun. diff --git a/content/images/eclipse-20210610-farewell.jpg b/content/images/eclipse-20210610-farewell.jpg new file mode 120000 index 0000000..4131a74 --- /dev/null +++ b/content/images/eclipse-20210610-farewell.jpg @@ -0,0 +1 @@ +../../.git/annex/objects/00/F8/SHA512-s107816--4e990963d97828f1d68bca567d8f5ebd95cbca92106d7b185c3fe32d0bb7ee0f402273f1854929181526c98b0c0a83f8c6befb63bf4855be39e617814c70f38c/SHA512-s107816--4e990963d97828f1d68bca567d8f5ebd95cbca92106d7b185c3fe32d0bb7ee0f402273f1854929181526c98b0c0a83f8c6befb63bf4855be39e617814c70f38c \ No newline at end of file diff --git a/content/images/eclipse-20210610-farewell.yaml b/content/images/eclipse-20210610-farewell.yaml new file mode 100644 index 0000000..a5ce817 --- /dev/null +++ b/content/images/eclipse-20210610-farewell.yaml @@ -0,0 +1,6 @@ +--- +title: 2021-06-10 Fare Thee Well, Eclipse +copyright: 2021 Nick Bowler +license: cc-by-sa-4.0 +description: | + The spectacle is mostly over as the sun returns to hiding behind some clouds. diff --git a/content/images/eclipse-20210610-max.jpg b/content/images/eclipse-20210610-max.jpg new file mode 120000 index 0000000..4a36ece --- /dev/null +++ b/content/images/eclipse-20210610-max.jpg @@ -0,0 +1 @@ +../../.git/annex/objects/Qv/71/SHA512-s456326--212c721a3ee49a09a1b7f55fd3a7db962cec291f2e1c9274b954e029bf41451476d5aef545596af7f1bce45132541a7a9760357bdc7b03ff50a8bf83d40b9d80/SHA512-s456326--212c721a3ee49a09a1b7f55fd3a7db962cec291f2e1c9274b954e029bf41451476d5aef545596af7f1bce45132541a7a9760357bdc7b03ff50a8bf83d40b9d80 \ No newline at end of file diff --git a/content/images/eclipse-20210610-max.yaml b/content/images/eclipse-20210610-max.yaml new file mode 100644 index 0000000..535ac54 --- /dev/null +++ b/content/images/eclipse-20210610-max.yaml @@ -0,0 +1,7 @@ +--- +title: 2021-06-10 Maximum Eclipse from Ottawa +copyright: 2021 Nick Bowler +license: cc-by-sa-4.0 +description: | + Greatest eclipse as seen from Ottawa on 2021-06-10, with approximately 80% of + the sun obscured. diff --git a/content/images/eclipse-20210610-sunrise.jpg b/content/images/eclipse-20210610-sunrise.jpg new file mode 120000 index 0000000..c511776 --- /dev/null +++ b/content/images/eclipse-20210610-sunrise.jpg @@ -0,0 +1 @@ +../../.git/annex/objects/V5/kz/SHA512-s55143--bb4418266b4e21b6a4b3f39f7aec3deb6593ce0fdaf3b7d60feca81e7398165315b69e989012e583352ad2d4960f890099bd570f39d7e286b14a07bcf6a70534/SHA512-s55143--bb4418266b4e21b6a4b3f39f7aec3deb6593ce0fdaf3b7d60feca81e7398165315b69e989012e583352ad2d4960f890099bd570f39d7e286b14a07bcf6a70534 \ No newline at end of file diff --git a/content/images/eclipse-20210610-sunrise.yaml b/content/images/eclipse-20210610-sunrise.yaml new file mode 100644 index 0000000..c85adbb --- /dev/null +++ b/content/images/eclipse-20210610-sunrise.yaml @@ -0,0 +1,7 @@ +--- +title: 2021-06-10 Sunrise from Ottawa +copyright: 2021 Nick Bowler +license: cc-by-sa-4.0 +description: | + The eclipse is well under way at sunrise. Some clouds obscure the horizon + but after about 10 minutes the sun begins to rise above them. diff --git a/content/style.scss b/content/style.scss index a550ea2..a5cffbe 100644 --- a/content/style.scss +++ b/content/style.scss @@ -44,15 +44,39 @@ body { margin: 1em; } -a:link { color: $linkdefaultcolour; } -a:visited { color: $linkvisitedcolour; } -a:active { color: $linkactivecolour; } +a:link { color: $linkdefaultcolour; border-color: $linkdefaultcolour; } +a:visited { color: $linkvisitedcolour; border-color: $linkvisitedcolour; } +a:active { color: $linkactivecolour; border-color: $linkactivecolour; } h1 { @include header_size(60em, 2em); } h2 { @include header_size(60em, 1.5em); } h5 { @include header_size(60em, 1em); } -p>img { max-width: 40em; width: 100%; height: auto; } +p.img { + text-align: center; + + img { + vertical-align: bottom; + max-width: 40em; + width: 100%; + height: auto; + } + + a { + text-decoration: none; + display: inline-block; + border: solid 2px; + } + + small { + color: $foregroundcolour; + text-align: justify; + @media (max-width: 24em) { text-align: left; } + padding: 0.5ex; + display: block; + font-size: 0.9em; + } +} p, dt, dd, li { text-align: justify; diff --git a/content/weblog/eclipse-20210610.md b/content/weblog/eclipse-20210610.md new file mode 100644 index 0000000..2563fb1 --- /dev/null +++ b/content/weblog/eclipse-20210610.md @@ -0,0 +1,26 @@ +--- +title: Solar Eclipse in Ottawa on 2021-06-10 +copyright: 2021 Nick Bowler +license: cc-by-sa-4.0 +published: 2021-06-13T23:43:47-0400 +--- + +On June 10, 2021, I tried to take some photos of the sun, but the moon +kept getting in the way. + +<%= item_to_img(@items["/images/eclipse-20210610-sunrise.jpg"], caption: < +<%= item_to_img(@items["/images/eclipse-20210610-max.jpg"], caption: < +<%= item_to_img(@items["/images/eclipse-20210610-clouds.jpg"], caption: < +<%= item_to_img(@items["/images/eclipse-20210610-farewell.jpg"], caption: < diff --git a/layouts/copyright.xml b/layouts/copyright.xml new file mode 100644 index 0000000..a3153bb --- /dev/null +++ b/layouts/copyright.xml @@ -0,0 +1,29 @@ +<% +s = ' ' * (@indent || 2) +copyyears = {} +copyauthors = {} +[@item.fetch(:copyright, [])].flatten.each do |copyright| %> +<%=s%><%= copyright %><% +x = expand_copyright(copyright) +x[:years].each do |y| copyyears[y] = 1 end +copyauthors[x[:name]] = 1 +end +copyyears.keys.sort.each do |y| %> +<%=s%><%= y %><% +end +copyauthors.keys.sort.each do |i| %> +<%=s%><%= i %><% +end + if @item[:license] then + licref = @item[:license].split + lic = find_license(licref[0]) %> +<%=s%> +<%=s%> <%= File::basename(lic.identifier.without_ext) %> +<%=s%> <%= license_shortname(lic) %> +<%=s%> <%= [lic[:title], licref[1..-1]].compact.join(" ").strip %> +<%=s%> <%= item_uri(lic) %> +<%=s%> <%= + lic[:"modification-allowed"] == true ? "yes" : "no" + %> +<%=s%><% +end %> diff --git a/layouts/default.xml b/layouts/default.xml index 949290a..2e003ae 100644 --- a/layouts/default.xml +++ b/layouts/default.xml @@ -27,23 +27,16 @@ doc_header = doc.xpath("string(//xhtml:h1)", Xmlns) end %> - <%= @item.fetch(:title, doc_header) %> -<% [@item.fetch(:copyright, [])].flatten.each do |copyright| -%> <%= copyright %> -<% end - if @item[:license] then - licref = @item[:license].split - lic = find_license(licref[0]) -%> - <%= File::basename(lic.identifier.without_ext) %> - <%= [lic[:title], licref[1..-1]].compact.join(" ").strip %> - <%= item_uri(lic) %> - <%= - lic[:"modification-allowed"] == true ? "yes" : "no" - %> - -<% end -%> + <%= @item.fetch(:title, doc_header) %><%= +render '/copyright.xml' %><% +find_images.each do |item| %> + + <%= item[:attrname] || item[:title] %> + <%= item_uri(item, rep: :info) %><%= +render '/copyright.xml', :item => item, :indent => 4 +%> <% +end %> + <% if @item.raw_filename %> <%= item_source(@item) %> <% elsif File.basename(@item.identifier) == "index.lst" %> diff --git a/layouts/default.xsl b/layouts/default.xsl index a97f784..2e14ce8 100644 --- a/layouts/default.xsl +++ b/layouts/default.xsl @@ -22,8 +22,9 @@ xmlns:xhtml='http://www.w3.org/1999/xhtml' xmlns:xsl='http://www.w3.org/1999/XSL/Transform' xmlns:func='http://exslt.org/functions' + xmlns:exslt='http://exslt.org/common' xmlns:f='http://draconx.ca/my-functions' - extension-element-prefixes='func f' + extension-element-prefixes='exslt func f' exclude-result-prefixes='xhtml'> @@ -45,6 +46,12 @@ + + + + + + + + + + + + + + img + + + + + @@ -444,6 +468,9 @@ diff --git a/layouts/imginfo.xsl b/layouts/imginfo.xsl index 7859d8b..e39c07d 100644 --- a/layouts/imginfo.xsl +++ b/layouts/imginfo.xsl @@ -30,7 +30,7 @@ - + @@ -39,6 +39,7 @@ +

Metadata

@@ -46,50 +47,42 @@ - - + - - - + + - - - + + - - + + - - + + - - - + + - - + + - - - + + - - - + + - - - + + - - - + + - +
AttributeValue
diff --git a/lib/helpers.rb b/lib/helpers.rb index c9a1cc3..cc0bf04 100644 --- a/lib/helpers.rb +++ b/lib/helpers.rb @@ -16,9 +16,11 @@ # along with this program. If not, see . require 'nokogiri' +require 'fastimage' -use_helper Nanoc::Helpers::Breadcrumbs use_helper Nanoc::Helpers::Blogging +use_helper Nanoc::Helpers::Breadcrumbs +use_helper Nanoc::Helpers::Rendering Xmlns = { 'xhtml' => 'http://www.w3.org/1999/xhtml' @@ -75,6 +77,81 @@ def counter(name = :default, item = @item) name.to_s.capitalize + " " + ($counters[item][name] += 1).to_s end +def img_rep_fallback(item, rep) + return rep unless item.reps[rep].raw_path.nil? + return :large +end + +def item_to_img(item, rep: :large, alt: nil, caption: nil) + unless item + return "[image not found]" + end + + alt ||= item[:title] + caption ||= alt + caption = caption.strip + caption.gsub!(/\s+/, " ") + + rep = img_rep_fallback(item, rep) + attrs = { :src => item_uri(item, rep: rep), :alt => item[:title] } + attrs[:width], attrs[:height] = FastImage.size(item.reps[rep].raw_path) + + b = Nokogiri::XML::Builder.new do |xml| + xml.a(:href => item_uri(item, rep: :info)) { + xml.img(attrs) + unless caption.empty? + xml << " ⁠" + xml.small { + xml << caption + } + end + } + end + b.to_xml(:save_with => Nokogiri::XML::Node::SaveOptions::NO_DECLARATION) +end + +def expand_copyright(copyright) + result = { :years => {} } + + /^([-–[:digit:][:space:],]*)(.*)$/.match(copyright) do |m| + m[1].split(/\s*,\s*/).each do |range| + lo, hi = range.split(/[^[:digit:]]+/) + for y in (lo..hi||lo) + result[:years][y] = 1 + end + end + + result[:years] = result[:years].keys.sort + result[:name] = m[2] + return result + end + + return nil +end + +def path_to_rep(path) + @items.find_all(File::dirname(path) + "/*").each do |item| + item.reps.each do |rep| + return rep if rep.path == path + end + end + return nil +end + +def find_images(item = @item) + return [] if item.binary? + + result = {} + doc = Nokogiri::HTML(item.compiled_content(snapshot: :pre)) + doc.xpath("//img/@src").each do |imgsrc| + rep = path_to_rep(imgsrc.value) + if rep + result[rep.item.identifier] ||= rep.item + end + end + return result.values +end + def human_filesize(size) units = ["B", "KiB", "MiB", "GiB"] prec = 0 @@ -90,3 +167,7 @@ def human_filesize(size) sprintf("%.*f %s", prec, size + 0.05, unit) end + +def license_shortname(item) + item.fetch(:shortname, File::basename(item.identifier.without_ext).upcase) +end diff --git a/lib/imginfo.rb b/lib/imginfo.rb index 13d6b01..668cd5a 100644 --- a/lib/imginfo.rb +++ b/lib/imginfo.rb @@ -25,17 +25,18 @@ class ImgInfoFilter < Nanoc::Filter def do_variant(xml, name, item = @item, rep: :default) file = item.reps[rep].raw_path + unless file.nil? + w, h = FastImage.size(file) + sz = File.size(file) - w, h = FastImage.size(file) - sz = File.size(file) - - xml.variant { - xml.name(name) - xml.uri(item_uri(item, rep: rep)) - xml.width(w) - xml.height(h) - xml.filesize(human_filesize(sz)) - } + xml.variant { + xml.name(name) + xml.uri(item_uri(item, rep: rep)) + xml.width(w) + xml.height(h) + xml.filesize(human_filesize(sz)) + } + end end def run(filename, params = {}) @@ -44,6 +45,7 @@ class ImgInfoFilter < Nanoc::Filter b = Nokogiri::XML::Builder.new do |xml| xml.image { do_variant(xml, "Large", rep: :large) + do_variant(xml, "Medium", rep: :medium) do_variant(xml, "Original")