|
| 1 | +#!/usr/bin/env bash |
| 2 | + |
| 3 | +touch keys.txt body.md temp.md temp.txt |
| 4 | +keys=keys.txt |
| 5 | + |
| 6 | +if [[ ! -s $keys ]];then |
| 7 | + head -n 1 $keys | echo "dev.to:" >$keys |
| 8 | + sed -i "1a medium:" $keys |
| 9 | + sed -i "2a medium_id:" $keys |
| 10 | + sed -i "3a hashnode:" $keys |
| 11 | + sed -i "4a hashnode_id:" $keys |
| 12 | + sed -i "5a codenewbie:" $keys |
| 13 | +else |
| 14 | + dev_key=$(sed -n -e 's/dev.to://p' $keys) |
| 15 | + med_token=$(sed -n -e 's/medium://p' $keys) |
| 16 | + med_id=$(sed -n -e 's/medium_id://p' $keys) |
| 17 | + hashtoken=$(sed -n -e 's/hashnode://p' $keys) |
| 18 | + hash_id=$(sed -n -e 's/hashnode_id://p' $keys) |
| 19 | + codenbkeys=$(sed -n -e 's/codenewbie://p' $keys) |
| 20 | +fi |
| 21 | + |
| 22 | +read -p "Enter the name of the file : " file |
| 23 | + |
| 24 | +if [[ -z $(sed '/^---/p;q' $file) ]];then |
| 25 | + read -p "Enter the title of your post : " title |
| 26 | + read -p "Enter the subtitle of your post : " subtitle |
| 27 | + read -p "Enter the status of your post(true/false) : " statusp |
| 28 | + read -p "Enter the tags for your post : " tags |
| 29 | + read -p "Enter the canonical url of the post : " canonical_url |
| 30 | + read -p "Enter the cover_image url of the post : " cover_image |
| 31 | + read -p "Should this be a part of a series? (y/n) : " series_bool |
| 32 | + |
| 33 | + if [[ $series_bool = "y" || $series_bool = "Y" ]]; then |
| 34 | + read -p "Enter the name of the series : " series |
| 35 | + fi |
| 36 | + |
| 37 | + sed -i "1i ---" $file |
| 38 | + sed -i "1a title: $title" $file |
| 39 | + sed -i "2a subtitle: $subtitle" $file |
| 40 | + sed -i "3a published: $statusp" $file |
| 41 | + sed -i "4a tags: $tags" $file |
| 42 | + sed -i "5a canonical_url: $canonical_url" $file |
| 43 | + sed -i "6a cover_image: $cover_image" $file |
| 44 | + sed -i "7a series: $series" $file |
| 45 | + sed -i "8a ---" $file |
| 46 | +fi |
| 47 | + |
| 48 | +title=$(sed -n '2 s/^[^=]*title: *//p' $file) |
| 49 | +subtitle=$(sed -n '3 s/^[^=]*subtitle: *//p' $file) |
| 50 | +tags=$(sed -n '5 s/^[^=]*tags: *//p' $file) |
| 51 | +canonical_url=$(sed -n '6 s/^[^=]*url: *//p' $file) |
| 52 | +cover_image=$(sed -n '7 s/^[^=]*age: *//p' $file) |
| 53 | + |
| 54 | +sed -i "s/\"/'/g" $file |
| 55 | +awk '{print $0" "}' $file >temp.txt |
| 56 | +sed -i '1,+7 s/$/\\r\\n/g' temp.txt |
| 57 | +sed -i '/^- / s/$/\\r\\n/g' temp.txt |
| 58 | +sed -i '/^[0-9]. / s/$/\\r\\n/' temp.txt |
| 59 | +awk '!NF{$0="\\r\\n\\r\\n"}1' temp.txt >temp.md |
| 60 | +cat temp.md | tr -d '\r\n' >body.md |
| 61 | +body=$(cat body.md) |
| 62 | + |
| 63 | + |
| 64 | +echo -e "\n1. dev.to \n" |
| 65 | +echo -e "2. hashnode.com \n" |
| 66 | +echo -e "3. medium.com \n" |
| 67 | +echo -e "4. All of the above\n" |
| 68 | +echo -e "5. dev.to and medium\n" |
| 69 | +echo -e "6. codenewbie \n" |
| 70 | + |
| 71 | +source lib/codenewbie.sh lib/devto.sh lib/medium.sh lib/hashnode.sh |
| 72 | + |
| 73 | +read -p "Where you want to cross post to? " num |
| 74 | + |
| 75 | +if [[ $num -eq 1 ]];then |
| 76 | + |
| 77 | + dev |
| 78 | + |
| 79 | +elif [[ $num -eq 2 ]];then |
| 80 | + |
| 81 | + hashnode |
| 82 | + |
| 83 | +elif [[ $num -eq 3 ]];then |
| 84 | + |
| 85 | + medium |
| 86 | + |
| 87 | +elif [[ $num -eq 4 ]];then |
| 88 | + |
| 89 | + dev |
| 90 | + hashnode |
| 91 | + medium |
| 92 | + |
| 93 | +elif [[ $num -eq 5 ]];then |
| 94 | + |
| 95 | + dev |
| 96 | + medium |
| 97 | + |
| 98 | +elif [[ $num -eq 6 ]];then |
| 99 | + |
| 100 | + codenewbie |
| 101 | + |
| 102 | +else |
| 103 | + echo "Invalid Input" |
| 104 | +fi |
| 105 | + |
| 106 | +rm temp.md temp.txt body.md |
0 commit comments