Skip to content
Snippets Groups Projects

Add a script to import pads into a blogpost

Merged Georg Krause requested to merge import-script into main
1 file
+ 58
0
Compare changes
  • Side-by-side
  • Inline
pad2post.sh 0 → 100755
+ 58
0
 
#!/bin/sh
 
 
if [ -z ${1+x} ]; then
 
echo "Please provide a pad link!";
 
exit 1;
 
fi
 
 
url="$(echo $1 | cut -d? -f1)"
 
echo $url
 
 
# Check that file doesn't exist before progressing
 
while [[ !$meta_filename || $meta_filename == "" ]]
 
do
 
read -p "Filename: " meta_filename
 
meta_filename=$(echo "${meta_filename##*( )}") # Trim
 
meta_filename=$(echo "$meta_filename" | cut -d. -f1)
 
meta_filename=$(echo "$meta_filename" | tr " " _)
 
filename_ext="$meta_filename.md"
 
if [ -f "content/$filename_ext" ]; then
 
echo "File already exists. Please choose another filename."
 
meta_filename=""
 
else
 
break
 
fi
 
done
 
meta_date=$(date +%Y-%m-%d)
 
read -p "Author: " meta_author
 
PS3="Category: "
 
options=("Announcement" "Release" "Community")
 
select opt in "${options[@]}"
 
do
 
if [ $opt ]
 
then
 
meta_category=$opt
 
break
 
else
 
echo "Please select a valid category"
 
fi
 
done
 
read -p "Summary: " meta_summary
 
 
echo $meta_filename
 
echo $meta_date
 
echo $meta_author
 
echo $meta_category
 
echo $meta_summary
 
 
echo "Title: $(curl $url/download | head -n 1)" >> content/$filename_ext
 
echo "Date: $meta_date" >> content/$filename_ext
 
echo "Authors: $meta_author" >> content/$filename_ext
 
echo "Category: $meta_category" >> content/$filename_ext
 
echo "Slug: $meta_filename" >> content/$filename_ext
 
echo "Summary: $meta_summary" >> content/$filename_ext
 
 
# Populate the body with everything that comes after the header
 
curl "$url/download" | #Download the content
 
sed -n '/===/,$p' | #Find the header break "===" and take everything after this line. "," = range, "$p" = all lines
 
tail -n +2 >> content/$filename_ext #Print all lines starting at line 2 (after the ===) to the file
Loading