From a4fed5715cc9e47def717ef6f21a5aed34455b32 Mon Sep 17 00:00:00 2001 From: kaotisk Date: Wed, 27 Mar 2024 09:37:57 +0200 Subject: News module aware renderer --- bin/ak-news | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ bin/ak-zblock-gen-html | 5 +++++ 2 files changed, 65 insertions(+) diff --git a/bin/ak-news b/bin/ak-news index 4c42a5d..3f8b94a 100755 --- a/bin/ak-news +++ b/bin/ak-news @@ -176,6 +176,7 @@ _ak_modules_news_usage(){ echo " -c, --create Vim is going to pop up, you will write and save your" echo " newsletter and it's going to be saved" echo " -s, --specs Print specs of data block" + echo " -x, --html Returns an appropriate html element from a NEWS zblock" exit 0 } @@ -203,6 +204,64 @@ _ak_modules_news_read(){ rm temp } +_ak_modules_news_html(){ + ak-enter -l 1 $1 > temp + if [ $? -ne 0 ] + then + logit "ERROR" "Failed to retrieve zblock $1" + exit 22 + fi + module="`cat temp | jq -r '.[].module'`" + action="`cat temp | jq -r '.[].action'`" + data="`cat temp | jq -r '.[].data'`" + linkToText="`cat temp | jq -r ".[].$data.ipfs"`" + zfilename="`cat temp | jq -r ".[].$data.filename"`" + ztitle="`cat temp | jq -r ".[].$data.title"`" + zdatetime="`cat temp | jq -r ".[].$data.datetime"`" + + if [ "$module" == "news" ] && [ "$action" == "add" ] + then + echo "" + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo " " + echo '
" + echo "
⌚ Date/Time
" + echo "
" + echo "
$zdatetime
" + echo "
" + echo "
 ✍ī¸  Title
" + echo "
" + echo "
$ztitle
" + echo "
" + echo "
📄 Filename
" + echo "
" + echo "
$zfilename
" + echo "
" + echo "
📄 Content
" + echo "
" + echo "
$(_ak_ipfs_cat $linkToText)
" + echo "
' + else + logit "ERROR" "Not a news block." + exit 1 + fi + rm temp +} + _ak_modules_news_specs(){ datetime_mask=$(printf '^[0-9]\{8\}_[0-9]\{6\}$' | xxd -p) ipfs_mask=$(printf '^Qm[a-zA-Z0-9]\{44\}$' | xxd -p) @@ -226,6 +285,7 @@ if [ ! -z $1 ]; then -c | --create) _ak_modules_news_create; exit;; -r | --read) _ak_modules_news_read $2; exit;; -s | --specs) _ak_modules_news_specs $2; exit;; + -x | --html) _ak_modules_news_html $2; exit;; * ) _ak_modules_news_usage;; esac else _ak_modules_news_usage diff --git a/bin/ak-zblock-gen-html b/bin/ak-zblock-gen-html index 289823b..d125d82 100755 --- a/bin/ak-zblock-gen-html +++ b/bin/ak-zblock-gen-html @@ -94,6 +94,11 @@ then # Output data in HTML format echo "

$PROGRAM

" echo "

🔎 $zblock

" + if [ "$module" == "news" ] && [ "$action" == "add" ] + then + ak-news -x $zblock + fi + echo "

ℹī¸ $zblock

" echo " " echo " " echo "
" -- cgit v1.2.3