From 12b3accd30ad27d2f635971e40b33c536d228a21 Mon Sep 17 00:00:00 2001 From: iceyrazor Date: Sun, 25 Aug 2024 04:08:32 -0500 Subject: [PATCH] init --- .gitignore | 11 ++++++ LICENSE | 21 +++++++++++ README.md | 42 ++++++++++++++++++++++ config.def.txt | 7 ++++ gen_html.sh | 21 +++++++++++ gen_index_list.sh | 20 +++++++++++ gen_xml.sh | 29 +++++++++++++++ push_discord_webhook.sh | 18 ++++++++++ replace_all.sh | 1 + rss_pull.sh | 18 ++++++++++ rss_push.sh | 79 +++++++++++++++++++++++++++++++++++++++++ template/index.html | 11 ++++++ template/index.xml | 8 +++++ template/page.html | 15 ++++++++ template/webhook.json | 4 +++ test.md | 7 ++++ 16 files changed, 312 insertions(+) create mode 100644 .gitignore create mode 100644 LICENSE create mode 100644 README.md create mode 100644 config.def.txt create mode 100644 gen_html.sh create mode 100644 gen_index_list.sh create mode 100644 gen_xml.sh create mode 100644 push_discord_webhook.sh create mode 100644 replace_all.sh create mode 100644 rss_pull.sh create mode 100644 rss_push.sh create mode 100644 template/index.html create mode 100644 template/index.xml create mode 100644 template/page.html create mode 100644 template/webhook.json create mode 100644 test.md diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b23deca --- /dev/null +++ b/.gitignore @@ -0,0 +1,11 @@ +src/** +src +static/** +*.md +hoedown +config.txt +discord_api.txt +!test.md +!README.md +.clangd +post/** diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..115d8fa --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2024 iceyrazor + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.md b/README.md new file mode 100644 index 0000000..48e8f09 --- /dev/null +++ b/README.md @@ -0,0 +1,42 @@ +# hi +this is just a personal project i made to generate and push to my static pages and rss feed at http://iceyfox.xyz and post to discord webhook + +this isnt perfect and does require manual intervention. for instance. if you need to edit a post. you have to delete it from the rss feed aka the xml file. else you will have duplicates. + +### this was built in mind with linux, not intended for windows + +# how to download and use. +well its all shell. except for converting from md to html. witch you need hoedown. https://github.com/hoedown/hoedown + +- download hoedown +- extract and compile it. should just be make. +- download this repo +- put hoedown in this repo ./ +- make a directoy in this repo. static +- make a folder inside static for your 'posting' page. +- copy config.def.txt as config.txt and config it. +- prime folder is if on your webserver you want everything in a sub-directory. leave as is if you dont want it. must have trailing /! +- make post the same name as your 'posting' page +- copy index.xml and index.html to static/'posting' or static/primefolder/posting. +- in gen\_index\_list.sh edit the head -n 6 to get the top half of your index.html page. and make the one below your number +1 +- optional + - make a file discord\_api.txt and put a webhook api in there if you want to + +and that shoooould be everything + +# running +for this ill use test.md as a example + +- only run this while in the same directory as this repo. i havent edited this to run outside it, for now. +- to run you can run rss\_pull.sh if you have files from a website that allready has a simmular setup //will use the config for url to pull from +- run ``gen_index_list.sh ./test.md`` and check static/post/index.html +- run ``gen_xml.sh ./test.md`` and check static/post/index.xml +- run ``gen_html.sh ./test.md`` and check static/post/list/filename/index.html +- if you have a discord webhook and thats config'd run ``push_discord_webhook.sh ./test.md`` and check your webhook channel +- run rss\_push.sh ./test.md or upload files to your webserver +- in rss\_push.sh if ./test.md or file isnt defined it wont add the posting file, instead it will just update the existing files. + +# todo +- instead of defining posting page in config. make directory for each posting page then use directory name for post +- somthing i dont remember +- error checking. mainly input file checking. diff --git a/config.def.txt b/config.def.txt new file mode 100644 index 0000000..8c64081 --- /dev/null +++ b/config.def.txt @@ -0,0 +1,7 @@ +url: +prime_folder: +css_file:static/static-style.css +css_upload:assets +post:updates +ftp: +user: diff --git a/gen_html.sh b/gen_html.sh new file mode 100644 index 0000000..f3a5cc3 --- /dev/null +++ b/gen_html.sh @@ -0,0 +1,21 @@ +content="$(./hoedown --hard-wrap "$1" | sed -e 's/&/\\\\&/g')" +#content=$(printf "%q" $content) +title=$(cat "$1" | head -n 1 | sed 's/# //' | sed -e 's/\r//g') +file=$(printf "$1" | sed 's/\.md$//' | sed 's/^\.\///') + +config=$(cat ./config.txt) +url=$(printf "$config" | awk 'gsub(/^url:/,"")'); +prime_folder=$(printf "$config" | awk 'gsub(/^prime_folder:/,"")'); +post=$(printf "$config" | awk 'gsub(/^post:/,"")'); +ftp=$(printf "$config" | awk 'gsub(/^ftp:/,"")'); +user=$(printf "$config" | awk 'gsub(/^user:/,"")'); + +#f_out=$(printf "\n\n\n\n
\n$content\n

$url/$prime_folder/$post \n
\n") + +#f_out=$(cat ./template/page.html | awk -v chunk="$content" '{gsub("",chunk)}1' | awk -v chunk="$url/$prime_folder/$post" '{gsub("",chunk)}1' | awk -v chunk="$(date '+%B %m/%d/%Y %I:%M%p')" '{gsub("",chunk)}1') + +f_out=$(awk -v content="$content" -v post="$url/$prime_folder$post" -v date="$(date '+%B %m/%d/%Y %I:%M%p')" '{gsub("",content); gsub("",post); gsub("",date); print}' ./template/page.html) + +printf "$f_out" +mkdir "static/$prime_folder$post/$file" +printf "$f_out" > "static/$prime_folder$post/$file/index.html" diff --git a/gen_index_list.sh b/gen_index_list.sh new file mode 100644 index 0000000..95941a4 --- /dev/null +++ b/gen_index_list.sh @@ -0,0 +1,20 @@ +file=$(printf "$1" | sed 's/\.md$//' | sed 's/^\.\///') +title=$(cat "$1" | head -n 1 | sed 's/# //' | sed -e 's/\r//g') + +config=$(cat ./config.txt) +url=$(printf "$config" | awk 'gsub(/^url:/,"")'); +prime_folder=$(printf "$config" | awk 'gsub(/^prime_folder:/,"")'); +post=$(printf "$config" | awk 'gsub(/^post:/,"")'); +ftp=$(printf "$config" | awk 'gsub(/^ftp:/,"")'); +user=$(printf "$config" | awk 'gsub(/^user:/,"")'); + + +#f_end="$(cat ./$prime_folder/$post/index.html | tail -n 5)" +#f_start=$(cat ./$prime_folder/$post/index.html | awk -v RS="$f_end" 'NR==1{printf $0} NR!=1{printf "%s", $0}') +f_start=$(head -n 6 "./static/$prime_folder$post/index.html") +f_end=$(tail -n +7 "./static/$prime_folder$post/index.html") + +f_out=$(printf "$f_start\n\n$f_end") + +printf "$f_out" +printf "$f_out" > "static/$prime_folder$post/index.html" diff --git a/gen_xml.sh b/gen_xml.sh new file mode 100644 index 0000000..ebdf2a8 --- /dev/null +++ b/gen_xml.sh @@ -0,0 +1,29 @@ +# " --> " +# & --> & +# ' --> ' +# < --> < +# > --> > +content="$(./hoedown "$1" | tail -n +2 | sed 's//\>\;/g')" +title=$(cat "$1" | head -n 1 | sed 's/# //' | sed -e 's/\r//g') +file=$(printf "$1" | sed 's/\.md$//' | sed 's/^\.\///') + +config=$(cat ./config.txt) +url=$(printf "$config" | awk 'gsub(/^url:/,"")'); +prime_folder=$(printf "$config" | awk 'gsub(/^prime_folder:/,"")'); +post=$(printf "$config" | awk 'gsub(/^post:/,"")'); +ftp=$(printf "$config" | awk 'gsub(/^ftp:/,"")'); +user=$(printf "$config" | awk 'gsub(/^user:/,"")'); + +#f_end="$(cat ./$prime_folder/$post/index.xml | tail -n 2)" +#f_start=$(cat ./$prime_folder/$post/index.xml | awk -v RS="$f_end" 'NR==1{printf $0} NR!=1{printf "%s", $0}') +f_start=$(head -n 6 "./static/$prime_folder$post/index.xml") +f_end=$(tail -n +7 "./static/$prime_folder$post/index.xml") + + +pub_date=$(date '+%a, %d %b %Y %H:%M:%S %z') + +f_out=$(printf "$f_start\n\n\t$title\n\t$pub_date\n\t$url/$prime_folder$post/$file/\n\t$url/$prime_folder$post/$file/\n\t$content\n\n$f_end" | awk -v chunk="$(date '+%B %d/%d/%Y %I:%M%p')" '{gsub("<DATE_POST>",chunk)}1') + + +printf "$f_out" +printf "$f_out" > "static/$prime_folder$post/index.xml" diff --git a/push_discord_webhook.sh b/push_discord_webhook.sh new file mode 100644 index 0000000..70d6cd5 --- /dev/null +++ b/push_discord_webhook.sh @@ -0,0 +1,18 @@ +content="$(cat "$1" | head -n 20 | sed -z 's/\n/\\\\n/g' | sed 's/\"/\\\\"/g' | sed -e 's/\r//g')" +#content=$(printf "%q" $content) +title=$(cat "$1" | head -n 1 | sed 's/# //' | sed -e 's/\r//g') +file=$(printf "$1" | sed 's/\.md$//' | sed 's/^\.\///') + +config=$(cat ./config.txt) +url=$(printf "$config" | awk 'gsub(/^url:/,"")'); +local_folder=$(printf "$config" | awk 'gsub(/^local_folder:/,"")'); +prime_folder=$(printf "$config" | awk 'gsub(/^prime_folder:/,"")'); +post=$(printf "$config" | awk 'gsub(/^post:/,"")'); +ftp=$(printf "$config" | awk 'gsub(/^ftp:/,"")'); +user=$(printf "$config" | awk 'gsub(/^user:/,"")'); +discord_webhook=$(cat discord_api.txt); + +f_out=$(cat ./template/webhook.json | awk -v chunk="$content" '{gsub("",chunk)}1' | awk -v chunk="$url/$prime_folder$post/$file" '{gsub("",chunk)}1' | awk -v chunk="$post" '{gsub("",chunk)}1' | awk -v chunk="$url/$prime_folder$post" '{gsub("",chunk)}1' | awk -v chunk="$(date '+%B %m/%d/%Y %I:%M%p')" '{gsub("",chunk)}1') + +printf "$f_out\n\n" +curl -X POST -H "Content-Type: application/json" -d "$f_out" "$discord_webhook" diff --git a/replace_all.sh b/replace_all.sh new file mode 100644 index 0000000..b0ad0c4 --- /dev/null +++ b/replace_all.sh @@ -0,0 +1 @@ +find . -type f -exec sed -i 's/old_string/new_string/g' {} \; diff --git a/rss_pull.sh b/rss_pull.sh new file mode 100644 index 0000000..3f0cb90 --- /dev/null +++ b/rss_pull.sh @@ -0,0 +1,18 @@ +config=$(cat ./config.txt) +url=$(printf "$config" | awk 'gsub(/^url:/,"")'); +prime_folder=$(printf "$config" | awk 'gsub(/^prime_folder:/,"")'); +post=$(printf "$config" | awk 'gsub(/^post:/,"")'); +ftp=$(printf "$config" | awk 'gsub(/^ftp:/,"")'); +user=$(printf "$config" | awk 'gsub(/^user:/,"")'); + +cd static/ +cd $prime_folder +rm static-style.css +wget $url/static/{$prime_folder}static-style.css + +cd $post +rm index.html +wget $url/static/$prime_folder$post/index.html + +rm index.xml +wget $url/static/$prime_folder$post/index.xml diff --git a/rss_push.sh b/rss_push.sh new file mode 100644 index 0000000..e906235 --- /dev/null +++ b/rss_push.sh @@ -0,0 +1,79 @@ +config=$(cat ./config.txt) +file=$(printf "$1" | sed 's/\.md$//' | sed 's/^\.\///') +url=$(printf "$config" | awk 'gsub(/^url:/,"")'); +prime_folder=$(printf "$config" | awk 'gsub(/^prime_folder:/,"")'); +css_file=$(printf "$config" | awk 'gsub(/^css_file:/,"")'); +css_upload_folder=$(printf "$config" | awk 'gsub(/^css_upload_folder:/,"")'); +post=$(printf "$config" | awk 'gsub(/^post:/,"")'); +ftp=$(printf "$config" | awk 'gsub(/^ftp:/,"")'); +user=$(printf "$config" | awk 'gsub(/^user:/,"")'); + +prime_folder_cmd="" +prime_cd_cmd="" +prime_mkdir="" +if [ "$prime_folder" != "" ]; then + prime_folder_cmd="lcd $prime_folder" + prime_cd_cmd="cd $prime_folder" + prime_mkdir="mkdir $prime_folder" +fi + +read -s -p "ftp_password: " pass +printf "\n\n" + +if [ "$1" == "" ]; then + +#upload only index.xml/html listing and other assets +ftp -n < + + + + +
+

+rss: +
+ + diff --git a/template/index.xml b/template/index.xml new file mode 100644 index 0000000..cea8f3c --- /dev/null +++ b/template/index.xml @@ -0,0 +1,8 @@ + + + +iceys updates +http://iceyfox.xyz/static/test +this is a rss test + + diff --git a/template/page.html b/template/page.html new file mode 100644 index 0000000..c481dfe --- /dev/null +++ b/template/page.html @@ -0,0 +1,15 @@ + + + + + +
+ +

+ + + + +
+ + diff --git a/template/webhook.json b/template/webhook.json new file mode 100644 index 0000000..893ecfa --- /dev/null +++ b/template/webhook.json @@ -0,0 +1,4 @@ +{ + "username":"iceyfox:", + "content":" \nread more here: \n\n---" +} diff --git a/test.md b/test.md new file mode 100644 index 0000000..7467b78 --- /dev/null +++ b/test.md @@ -0,0 +1,7 @@ +# test +> + +### djsakladsjdsakl +- a +- b +- c