You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.6 KiB
36 lines
1.6 KiB
#!/bin/bash
|
|
|
|
getChanged() {
|
|
local file="$1"
|
|
date -r "${file}" "+%s"
|
|
}
|
|
|
|
getCreated() {
|
|
local d=$(basename $1 | grep -oe "^[0-9]\{12\}")
|
|
date -d "${d:0:4}-${d:4:2}-${d:6:2} ${d:8:2}:${d:10:2}" '+%s'
|
|
# date -j -f "%Y-%m-%d %H:%M" "${d:0:4}-${d:4:2}-${d:6:2} ${d:8:2}:${d:10:2}" '+%s'
|
|
#date -j -f "%Y-%m-%d" "$(getDocumentMetadataValue "$1" 'created')" "+%s"
|
|
}
|
|
|
|
m2j --content $1 > /tmp/md.json
|
|
cat /tmp/md.json | jq '.[] + {"body": .content} | .body = .content | del(.content, .basename, .preview)' > /tmp/md2.json
|
|
mv /tmp/md2.json /tmp/md.json
|
|
jq --arg changed "$(getChanged $1)" '. += {"changed": $changed}' < /tmp/md.json > /tmp/md2.json
|
|
mv /tmp/md2.json /tmp/md.json
|
|
jq --arg image "https://www.maketecheasier.com/assets/uploads/2020/09/markdown-cheatsheet-800x400.jpg.webp" '. += {"image": $image}' < /tmp/md.json > /tmp/md2.json
|
|
mv /tmp/md2.json /tmp/md.json
|
|
jq --arg type "md" '. += {"type": $type}' < /tmp/md.json > /tmp/md2.json
|
|
mv /tmp/md2.json /tmp/md.json
|
|
jq --arg created "$(getCreated $1)" '. | .created = $created' < /tmp/md.json > /tmp/md2.json
|
|
mv /tmp/md2.json /tmp/md.json
|
|
# jq --arg id "$(echo -n "$(basename $1|xxd -p -u)"| sed "s/[.]/_/g")" '. += {"id": $id}' < /tmp/md.json > /tmp/md2.json
|
|
jq --arg id "$(echo -n "$(basename $1)"| sed "s/[.]/_/g")" '. += {"id": $id}' < /tmp/md.json > /tmp/md2.json
|
|
mv /tmp/md2.json /tmp/md.json
|
|
jq --arg title "$(basename $1)" '. += {"title": $title}' < /tmp/md.json > /tmp/md2.json
|
|
mv /tmp/md2.json /tmp/md.json
|
|
jq --arg refcount "$2" '. += {"refcount": $refcount}' < /tmp/md.json > /tmp/md2.json
|
|
mv /tmp/md2.json /tmp/md.json
|
|
|
|
jq '. | [.]' < /tmp/md.json
|
|
|