markdownr 0.6.7 → 0.6.8

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ecda563bb6ae0b22bb608e65f195cb9008db45856aa2027710fbfd34a0d61808
4
- data.tar.gz: c92343f2c54e0d48d2f754f81b81f86a92dd30ac872eaa5ca1b5390b003131b1
3
+ metadata.gz: 4810bebbf882744a15ecd5efd2a62c7041a4e82333090ff48a436263b8a7d72c
4
+ data.tar.gz: 4539d9a60c57059548e5a83ce48bd4a2308c786994a600cbc826c1ce966ac91d
5
5
  SHA512:
6
- metadata.gz: 930394dda20505d2b3e0e21188563000a5481bcf5423992491b3f8cc080ff6403c63084b4083c2069d6995bff25b7353bd1591cb2bdf16083126f498b9e69dbe
7
- data.tar.gz: 3acb3a0135fe081c1827c4994df0f376c8afb7a9d65a0b1c335825ba00327ffb64516099b6f4cf2c2763a10d617bc73a0f43c6be9d87ba7f28ea4327fe87762d
6
+ metadata.gz: 826f2424b808693da846ec0f8683440b811977c8901e3afe1a170941731c7e654905d6359a5bf58965d268d4c487f7a1b911254a5461f4bde1667fd13d46bd11
7
+ data.tar.gz: 58aaacd2425f0a229fefca93e0f6e0b30b062bde8ae0a25dc4e43f1c76ae8a849c44fc003516afc43f8dd09fdac3e70ba8364d8bf9adb5e5ee6dc093327d06f4
@@ -827,6 +827,24 @@ module MarkdownServer
827
827
  end
828
828
  end
829
829
 
830
+ def inject_pronunciation_icon(html, meta)
831
+ return html unless meta.is_a?(Hash) && meta["strongs"] && meta["language"]
832
+ strongs = meta["strongs"].to_s.strip
833
+ lang = meta["language"].to_s.strip.downcase
834
+ return html unless strongs.match?(/\A[GH]\d+\z/i) && %w[hebrew greek].include?(lang)
835
+
836
+ icon = %(<button class="pronunciation-btn" data-strongs="#{h(strongs.upcase)}" ) +
837
+ %(title="Play pronunciation" ) +
838
+ %(style="background:none;border:none;cursor:pointer;padding:0 0 0 6px;font-size:1.1em;vertical-align:middle;line-height:1;color:#888;" ) +
839
+ %(onclick="(function(btn){if(btn._loading)return;var a=btn._audio;if(a){a.currentTime=0;a.play();return;}btn._loading=true;btn.style.opacity='0.4';\
840
+ fetch('/pronunciation?strongs='+btn.dataset.strongs).then(function(r){return r.json()}).then(function(d){\
841
+ if(d.audio){a=new Audio(d.audio);btn._audio=a;a.play();}btn._loading=false;btn.style.opacity='1';}).catch(function(){\
842
+ btn._loading=false;btn.style.opacity='1';});})(this)">&#128266;</button>)
843
+
844
+ # Insert before the closing tag of the first <h2>
845
+ html.sub(%r{</h2>}) { " #{icon}</h2>" }
846
+ end
847
+
830
848
  # Returns true when serving an HTML file that should have popup assets injected.
831
849
  # Add additional path prefixes here as needed.
832
850
  def inject_assets_for_html_path?(_relative_path)
@@ -1085,6 +1103,7 @@ module MarkdownServer
1085
1103
  title = (meta.is_a?(Hash) && meta["title"]) || File.basename(real, ".md")
1086
1104
  @current_wiki_dir = File.dirname(real)
1087
1105
  html = render_markdown(body)
1106
+ html = inject_pronunciation_icon(html, meta)
1088
1107
 
1089
1108
  frontmatter_html = ""
1090
1109
  if meta && !meta.empty?
@@ -1097,6 +1116,26 @@ module MarkdownServer
1097
1116
  JSON.dump({ title: title.to_s, html: html, frontmatter_html: frontmatter_html })
1098
1117
  end
1099
1118
 
1119
+ get "/pronunciation" do
1120
+ content_type :json
1121
+ strongs = params[:strongs].to_s.strip.upcase
1122
+ halt 400, '{"error":"invalid strongs"}' unless strongs.match?(/\A[GH]\d+\z/)
1123
+
1124
+ prefix = strongs.start_with?("H") ? "wlc" : "tr"
1125
+ blb_url = "https://www.blueletterbible.org/lexicon/#{strongs.downcase}/nasb20/#{prefix}/0-1/"
1126
+ html = fetch_external_page(blb_url)
1127
+ halt 502, '{"error":"fetch failed"}' unless html
1128
+
1129
+ data_pronunc = html[/data-pronunc="([a-fA-F0-9]{20,})"/i, 1]
1130
+ halt 404, '{"error":"no audio found"}' unless data_pronunc
1131
+
1132
+ audio_url = "https://www.blueletterbible.org/lang/lexicon/lexPronouncePlayer.cfm?skin=#{data_pronunc}"
1133
+ headers "Cache-Control" => "public, max-age=86400"
1134
+ JSON.dump({ audio: audio_url })
1135
+ rescue StandardError
1136
+ halt 502, '{"error":"fetch failed"}'
1137
+ end
1138
+
1100
1139
  get "/fetch-json" do
1101
1140
  content_type :json
1102
1141
  url = params[:url].to_s.strip
@@ -1240,6 +1279,7 @@ module MarkdownServer
1240
1279
  @meta, body = parse_frontmatter(content)
1241
1280
  @current_wiki_dir = File.dirname(real_path)
1242
1281
  @content = render_markdown(body)
1282
+ @content = inject_pronunciation_icon(@content, @meta)
1243
1283
  relative_dir = File.dirname(relative_path)
1244
1284
  relative_dir = "" if relative_dir == "."
1245
1285
  listing = -> { inline_directory_html(File.dirname(real_path), relative_dir) }
@@ -1,3 +1,3 @@
1
1
  module MarkdownServer
2
- VERSION = "0.6.7"
2
+ VERSION = "0.6.8"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: markdownr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.7
4
+ version: 0.6.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brian Dunn