diff options
author | kaotisk <kaotisk@arching-kaos.org> | 2024-06-10 16:35:33 +0300 |
---|---|---|
committer | kaotisk <kaotisk@arching-kaos.org> | 2024-06-10 16:35:33 +0300 |
commit | 1c0efac2b6be7d9e5e7bbddd237fef72eef49bd5 (patch) | |
tree | f21a99f6817de34d86eb1c2ff163e2d55463267b /lib/_ak_zblock | |
parent | 943f034f2bb2df772853a1de2e07d84a6c510c2a (diff) | |
download | arching-kaos-tools-1c0efac2b6be7d9e5e7bbddd237fef72eef49bd5.tar.gz arching-kaos-tools-1c0efac2b6be7d9e5e7bbddd237fef72eef49bd5.tar.bz2 arching-kaos-tools-1c0efac2b6be7d9e5e7bbddd237fef72eef49bd5.zip |
Refactoring
Diffstat (limited to 'lib/_ak_zblock')
-rwxr-xr-x | lib/_ak_zblock | 238 |
1 files changed, 9 insertions, 229 deletions
diff --git a/lib/_ak_zblock b/lib/_ak_zblock index 8a83479..ae95159 100755 --- a/lib/_ak_zblock +++ b/lib/_ak_zblock @@ -386,242 +386,22 @@ _ak_zblock_gen_html(){ arg="$(mktemp)" _ak_zblock_show "$1" | jq > $arg - ( \ - # Create HTML document - echo "<!DOCTYPE html>" - echo "<html>" - echo "<head>" - echo " <title>Arching Kaos Chain Data</title>" - echo ' <meta charset="UTF-8">' - echo ' <meta name="viewport" content="width=device-width, initial-scale=1">' - echo ' <style> - body { - background-color: #000; - color: lightgreen; - padding: 2%; - width: auto; - font-family: monospace; - font-size: 1rem; - } - h1, h2, h3, h4 { - text-align: left; - } - td { - text-align: initial; - background-color: #090909; - border: 1px dashed #444; - font-size: 1rem; - padding: 1vh 1vw; - margin: 0; - } - p, summary { - background: #061624; - border: 1px solid #827c7c; - padding: 1vh 1vw; - margin: 0; - color: lightgreen; - font-style: normal; - text-decoration: none; - } - summary:hover { - background: lightgreen; - color: #061624; - } - a { - color: #042746; - background-color: lightyellow; - border: 1px solid #827c7c; - padding: 1vh 1vw; - margin: 0; - font-style: normal; - text-decoration: none; - } - a:hover { - background-color: lightgreen; - color: #042746; - } - details { - /*! padding: 1vh 1vw; */ - border: 1px dotted; - background-color: #1d4055; - } - footer { - text-align: center; - } - </style>' - echo "</head>" - echo "<body>" - - # Iterate through each argument and parse data - if [ -f "$arg" ] - then - # Extract data from argument - zblock=$(cat $arg | jq -r '.zblock') - block=$(cat $arg | jq -r '.block') - timestamp=$(cat $arg | jq -r '.timestamp') - block_signature=$(cat $arg | jq -r '.block_signature') - detach=$(cat $arg | jq -r '.detach') - data=$(cat $arg | jq -r '.data') - module=$(cat $arg | jq -r '.module') - action=$(cat $arg | jq -r '.action') - gpg=$(cat $arg | jq -r '.gpg') - previous=$(cat $arg | jq -r '.previous') - datablock=$(cat $arg | jq -r ".$data") - - # Output data in HTML format - echo " <h1>$PROGRAM</h1>" - echo " <h2>đ $zblock</h2>" - if [ "$module" == "news" ] && [ "$action" == "add" ] - then - ak-news -x $zblock - fi - echo " <h2>âšī¸ $zblock</h2>" - echo " <table>" - echo " <tr>" - echo " <td>" - echo " <pre>đĻ ZBLOCK</pre>" - echo " </td>" - echo " <td>" - echo " <details>" - echo " <summary>$zblock</summary>" - echo " <pre>$(_ak_ipfs_cat $zblock | jq)</pre>" - echo " </details>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đĻ BLOCK</pre>" - echo " </td>" - echo " <td>" - echo " <details>" - echo " <summary>$block</summary>" - echo " <pre>$(_ak_ipfs_cat $block | jq)</pre>" - echo " </details>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đ BLOCK SIGNATURE</pre>" - echo " </td>" - echo " <td>" - echo " <details>" - echo " <summary>$block_signature</summary>" - echo " <pre>$(_ak_ipfs_cat $block_signature)</pre>" - echo " </details>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>â TIMESTAMP</pre>" - echo " </td>" - echo " <td>" - echo " <p>$timestamp</p>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đ MODULE</pre>" - echo " </td>" - echo " <td>" - echo " <p>$module</p>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đĒ§ ACTION</pre>" - echo " </td>" - echo " <td>" - echo " <p>$action</p>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đ GPG</pre>" - echo " </td>" - echo " <td>" - echo " <details>" - echo " <summary>$gpg</summary>" - echo " <pre>$(_ak_ipfs_cat $gpg)</pre>" - echo " </details>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đĻ PREVIOUS</pre>" - echo " </td>" - echo " <td>" - echo ' <a target="_blank" href="http://z.kaotisk-hund.com/files/zblocks-as-html/zblock-'$previous'.html">đ '$previous'</a>' - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đĻ DATA</pre>" - echo " </td>" - echo " <td>" - echo " <details>" - echo " <summary>$data</summary>" - echo " <pre>$datablock</pre>" - echo " </details>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đ DATA_SIGNATURE</pre>" - echo " </td>" - echo " <td>" - echo " <details>" - echo " <summary>$detach</summary>" - echo " <pre>$(_ak_ipfs_cat $detach)</pre>" - echo " </details>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đ ipfs</pre>" - echo " </td>" - echo " <td>" - echo ' <a target="_blank" href="http://gw.ipfs.z.kaotisk-hund.com/ipfs/'$(echo $datablock | jq -r '.ipfs')'">'đ $(echo $datablock | jq -r '.ipfs')'</a>' - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>đ detach</pre>" - echo " </td>" - echo " <td>" - echo " <details>" - echo " <summary>$(echo $datablock | jq -r '.detach')</summary>" - echo " <pre>$(_ak_ipfs_cat $(echo $datablock | jq -r '.detach'))</pre>" - echo " </details>" - echo " </td>" - echo " </tr>" - echo " </table>" - echo " <table>" - echo " <tr>" - echo " <td>" - echo " <pre>đ Rendered ZBLOCK</pre>" - echo " </td>" - echo " </tr>" - echo " <tr>" - echo " <td>" - echo " <pre>$(cat $arg | jq)</pre>" - echo " </td>" - echo " </tr>" - echo " </table>" - fi + _ak_generate_html_header > zblock-$1.html + _ak_generate_html_zblock $arg >> zblock-$1.html + time_ended=$(date -u +%s.%N) se=$(echo $time_ended | cut -d '.' -f 1) nse=$(echo $time_ended | cut -d '.' -f 2) - echo " <hr>" - echo -n " <footer>Generated by $PROGRAM on $(datehuman) in $(( $se - $ss ))." + printf ' <hr>\n' >> zblock-$1.html + printf ' <footer>Generated by $PROGRAM on $(datehuman) in $(( $se - $ss )).' >> zblock-$1.html if [ $nse -lt $nss ] then - echo "$(( 1$nse - $nss )) seconds</footer>" + printf '%s seconds</footer>\n' "$(( 1$nse - $nss ))" >> zblock-$1.html else - echo "$(( $nse - $(echo -n $nss|sed 's/^0*//') )) seconds</footer>" + printf '%s seconds</footer>' "$(( $nse - $(echo -n $nss|sed 's/^0*//') ))" >> zblock-$1.html fi - - echo "</body>" - echo "</html>" ) > zblock-$1.html + printf '</body>' >> zblock-$1.html + printf '</html>' >> zblock-$1.html rm $arg } |