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 +4 -4
- data/lib/markdown_server/app.rb +40 -0
- data/lib/markdown_server/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4810bebbf882744a15ecd5efd2a62c7041a4e82333090ff48a436263b8a7d72c
|
|
4
|
+
data.tar.gz: 4539d9a60c57059548e5a83ce48bd4a2308c786994a600cbc826c1ce966ac91d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 826f2424b808693da846ec0f8683440b811977c8901e3afe1a170941731c7e654905d6359a5bf58965d268d4c487f7a1b911254a5461f4bde1667fd13d46bd11
|
|
7
|
+
data.tar.gz: 58aaacd2425f0a229fefca93e0f6e0b30b062bde8ae0a25dc4e43f1c76ae8a849c44fc003516afc43f8dd09fdac3e70ba8364d8bf9adb5e5ee6dc093327d06f4
|
data/lib/markdown_server/app.rb
CHANGED
|
@@ -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)">🔊</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) }
|