|
1 |
| -local Path = require("core.path") |
2 |
| -local utils = require("core.utils") |
| 1 | +local crazywall = require("crazywall") |
| 2 | +local utils = crazywall.utils |
| 3 | +local Path = crazywall.Path |
3 | 4 |
|
4 |
| ----@type table<string, PartialConfigTable> |
5 |
| -local configs = { |
| 5 | +local config = { |
6 | 6 |
|
7 |
| - bible = { |
8 |
| - note_schema = { |
9 |
| - { "verses", "{{ ", " }}" }, |
10 |
| - }, |
| 7 | + note_schema = { |
| 8 | + { "verses", "{{ ", " }}" }, |
| 9 | + }, |
11 | 10 |
|
12 |
| - resolve_path = function() |
13 |
| - return Path.void() |
14 |
| - end, |
| 11 | + resolve_path = function() |
| 12 | + return Path.void() |
| 13 | + end, |
15 | 14 |
|
16 |
| - transform_lines = function() |
17 |
| - return {} |
18 |
| - end, |
| 15 | + transform_lines = function() |
| 16 | + return {} |
| 17 | + end, |
19 | 18 |
|
20 |
| - resolve_reference = function(section) |
21 |
| - local line = section:get_lines()[1] |
22 |
| - local book, chapter, starting_verse, ending_verse, version = |
23 |
| - line:match("(%d*%s*%w*) (%d+):(%d+)-(%d+) ?(%w*)") |
24 |
| - if not book then |
25 |
| - book, chapter, starting_verse, version = line:match("(%d*%s*%w*) (%d+):(%d+) ?(%w*)") |
26 |
| - ending_verse = starting_verse |
27 |
| - end |
28 |
| - if not book then |
29 |
| - --- Restore the section if it was unable to be parsed. |
30 |
| - return section:open_tag() .. section:get_lines() .. section:close_tag() |
31 |
| - end |
32 |
| - version = #version > 0 and version or "ASV" |
33 |
| - local check_jq = "(jq --version >/dev/null 2>/dev/null)" |
34 |
| - local jq_not_installed_msg = "echo 'Error: `jq` needs to be installed for this example.'" |
35 |
| - local curl_cmd = "(curl https://raw.githubusercontent.com/wldeh/bible-api/refs/heads/main/bibles/en-" |
36 |
| - .. version:lower() |
37 |
| - .. "/books/" |
38 |
| - .. book:lower():gsub(" ", "") |
39 |
| - .. "/chapters/" |
40 |
| - .. chapter |
41 |
| - .. ".json 2>/dev/null)" |
42 |
| - local jq_parse_json = "(jq -M -r '.data[] | select((.verse | tonumber) >= " |
43 |
| - .. starting_verse |
44 |
| - .. " and (.verse | tonumber) <= " |
45 |
| - .. ending_verse |
46 |
| - .. ") | .text' 2>/dev/null) | head -" |
47 |
| - .. (ending_verse - starting_verse + 1) |
48 |
| - .. "" |
49 |
| - local curl_cmd_failed = "echo 'Error: Curl command failed.'" |
50 |
| - local jq_cmd_failed = "echo 'Error: `jq` command failed.'" |
51 |
| - local cmd = string.format( |
52 |
| - "(%s || (%s && false)) && ((%s || (%s >&2 && false)) | (%s && true || %s)) 2>&1", |
53 |
| - check_jq, |
54 |
| - jq_not_installed_msg, |
55 |
| - curl_cmd, |
56 |
| - curl_cmd_failed, |
57 |
| - jq_parse_json, |
58 |
| - jq_cmd_failed |
59 |
| - ) |
60 |
| - local handle = io.popen(cmd) |
61 |
| - local result = utils.read_from_handle(handle) or "" |
62 |
| - local output = "> **" .. line .. "**" .. "\n> " |
63 |
| - if utils.str.starts_with(result, "Error") or starting_verse == ending_verse then |
64 |
| - output = output .. result |
65 |
| - return output |
66 |
| - end |
67 |
| - local verse = starting_verse |
68 |
| - for verse_txt in utils.str.split_lines(result) do |
69 |
| - output = output .. "[" .. verse .. "] " .. verse_txt .. " " |
70 |
| - verse = verse + 1 |
71 |
| - if verse > math.tointeger(ending_verse) then |
72 |
| - break |
73 |
| - end |
74 |
| - end |
75 |
| - output = output:sub(1, #output - 1) |
| 19 | + resolve_reference = function(section) |
| 20 | + local line = section:get_lines()[1] |
| 21 | + local book, chapter, starting_verse, ending_verse, version = |
| 22 | + line:match("(%d*%s*%w*) (%d+):(%d+)-(%d+) ?(%w*)") |
| 23 | + if not book then |
| 24 | + book, chapter, starting_verse, version = |
| 25 | + line:match("(%d*%s*%w*) (%d+):(%d+) ?(%w*)") |
| 26 | + ending_verse = starting_verse |
| 27 | + end |
| 28 | + if not book then |
| 29 | + --- Restore the section if it was unable to be parsed. |
| 30 | + return section:open_tag() |
| 31 | + .. section:get_lines() |
| 32 | + .. section:close_tag() |
| 33 | + end |
| 34 | + version = #version > 0 and version or "ASV" |
| 35 | + local check_jq = "(jq --version >/dev/null 2>/dev/null)" |
| 36 | + local jq_not_installed_msg = |
| 37 | + "echo 'Error: `jq` needs to be installed for this example.'" |
| 38 | + local curl_cmd = "(curl https://raw.githubusercontent.com/wldeh/bible-api/refs/heads/main/bibles/en-" |
| 39 | + .. version:lower() |
| 40 | + .. "/books/" |
| 41 | + .. book:lower():gsub(" ", "") |
| 42 | + .. "/chapters/" |
| 43 | + .. chapter |
| 44 | + .. ".json 2>/dev/null)" |
| 45 | + local jq_parse_json = "(jq -M -r '.data[] | select((.verse | tonumber) >= " |
| 46 | + .. starting_verse |
| 47 | + .. " and (.verse | tonumber) <= " |
| 48 | + .. ending_verse |
| 49 | + .. ") | .text' 2>/dev/null) | head -" |
| 50 | + .. (ending_verse - starting_verse + 1) |
| 51 | + .. "" |
| 52 | + local curl_cmd_failed = "echo 'Error: Curl command failed.'" |
| 53 | + local jq_cmd_failed = "echo 'Error: `jq` command failed.'" |
| 54 | + local cmd = string.format( |
| 55 | + "(%s || (%s && false)) && ((%s || (%s >&2 && false)) | (%s && true || %s)) 2>&1", |
| 56 | + check_jq, |
| 57 | + jq_not_installed_msg, |
| 58 | + curl_cmd, |
| 59 | + curl_cmd_failed, |
| 60 | + jq_parse_json, |
| 61 | + jq_cmd_failed |
| 62 | + ) |
| 63 | + local handle = io.popen(cmd) |
| 64 | + local result = utils.read_from_handle(handle) or "" |
| 65 | + local output = "> **" .. line .. "**" .. "\n> " |
| 66 | + if |
| 67 | + utils.str.starts_with(result, "Error") |
| 68 | + or starting_verse == ending_verse |
| 69 | + then |
| 70 | + output = output .. result |
76 | 71 | return output
|
77 |
| - end, |
| 72 | + end |
| 73 | + local verse = starting_verse |
| 74 | + for verse_txt in utils.str.split_lines(result) do |
| 75 | + output = output .. "[" .. verse .. "] " .. verse_txt .. " " |
| 76 | + verse = verse + 1 |
| 77 | + if verse > tonumber(ending_verse) then |
| 78 | + break |
| 79 | + end |
| 80 | + end |
| 81 | + output = output:sub(1, #output - 1) |
| 82 | + return output |
| 83 | + end, |
78 | 84 |
|
79 |
| - allow_overwrite = true, |
80 |
| - }, |
| 85 | + allow_overwrite = true, |
81 | 86 | }
|
82 | 87 |
|
83 |
| -return configs |
| 88 | +crazywall.add_config("bible", config) |
0 commit comments