Skip to content

Commit

Permalink
[scripts] ,frontmatter: script to generate frontmatter for sb
Browse files Browse the repository at this point in the history
Currently supports youtube and generic articles.
  • Loading branch information
meain committed May 29, 2024
1 parent 48bd1cf commit 20a7c6a
Showing 1 changed file with 49 additions and 0 deletions.
49 changes: 49 additions & 0 deletions scripts/.local/bin/random/,frontmatter
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
#!/bin/sh

set -e

# generate frontmatter (primarily for silverbullet)

set -e

[ -z "$1" ] && url="$(pbpaste)" || url="$1"

# TODO(meain): print out length of video
if echo "$url" | grep -q '^https://www.youtube.com'; then
title_and_creator="$(yt-dlp --print title --print uploader "$url")"
title="$(echo "$title_and_creator" | head -n 1)"
creator="$(echo "$title_and_creator" | tail -n 1)"
tags="youtube,video"
folder="YouTube"
else
page="$(curl -s "$url")"
title="$(echo "$page" | pup 'title text{}')"
creator="$(echo "$page" | pup 'meta[name="author"] attr{content}')"
if [ -z "$creator" ]; then
creator="$(echo "$url" | awk -F/ '{print $3}')"
fi
tags="article"
folder="Article"
fi

if [ -z "$2" ]; then
echo "---"
printf 'title: "%s"\nproducer: "%s"\nurl: "%s"\ntags: %s\nrating:0\nconsumed:"%s"\n---\n' "$title" "$creator" "$url" "$tags" "$(date +'%Y-%m-%d')"
else
filename="$2/$folder/$title.md"
if [ -e "$filename" ]; then
echo "File already exists: $filename"
exit 1
fi

echo "---" >"$filename"
printf 'title: "%s"\nproducer: "%s"\nurl: "%s"\ntags: %s\nrating:0\nconsumed:"%s"\n---\n' "$title" "$creator" "$url" "$tags" "$(date +'%Y-%m-%d')" >>"$filename"

if [ "$folder" = "YouTube" ]; then
echo "# Chapters" >> "$filename"
,yt-chapters "$url" >> "$filename"
echo "" >> "$filename"
echo "# Notes" >> "$filename"
fi
echo "Wrote $filename"
fi

0 comments on commit 20a7c6a

Please sign in to comment.