aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoriceyrazor <iceyfoxservers@gmail.com>2024-08-25 04:08:32 -0500
committericeyrazor <iceyfoxservers@gmail.com>2024-08-25 04:08:32 -0500
commit12b3accd30ad27d2f635971e40b33c536d228a21 (patch)
tree2ad9f589d05a279eab01ed1a1565a04cb61c6239
init
-rw-r--r--.gitignore11
-rw-r--r--LICENSE21
-rw-r--r--README.md42
-rw-r--r--config.def.txt7
-rw-r--r--gen_html.sh21
-rw-r--r--gen_index_list.sh20
-rw-r--r--gen_xml.sh29
-rw-r--r--push_discord_webhook.sh18
-rw-r--r--replace_all.sh1
-rw-r--r--rss_pull.sh18
-rw-r--r--rss_push.sh79
-rw-r--r--template/index.html11
-rw-r--r--template/index.xml8
-rw-r--r--template/page.html15
-rw-r--r--template/webhook.json4
-rw-r--r--test.md7
16 files changed, 312 insertions, 0 deletions
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 "<html>\n<head>\n<link rel=\"stylesheet\" href=\"/static/static-style.css?v=76\" />\n</body>\n<div align=\"center\" class=\"static-main\">\n$content\n<br><br><a href=\"$url/$prime_folder/$post\">$url/$prime_folder/$post</a> <a href=\"../index.xml\" target=\"_blank\"><img src=\"/assets/img/RSS.png\" class=\"rss_img\"></a>\n</div></body>\n</html>")
+
+#f_out=$(cat ./template/page.html | awk -v chunk="$content" '{gsub("<PAGE_CONTENT>",chunk)}1' | awk -v chunk="$url/$prime_folder/$post" '{gsub("<PAGE_URL>",chunk)}1' | awk -v chunk="$(date '+%B %m/%d/%Y %I:%M%p')" '{gsub("<DATE_POST>",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("<PAGE_CONTENT>",content); gsub("<PAGE_URL>",post); gsub("<DATE_POST>",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<div><a href=\"$url/$prime_folder$post/$file/index.html\">$title</a></div>\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 @@
+# " --> &quot;
+# & --> &amp;
+# ' --> &#39;
+# < --> &lt;
+# > --> &gt;
+content="$(./hoedown "$1" | tail -n +2 | sed 's/</\&lt\;/g' | sed 's/>/\&gt\;/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<item>\n\t<title>$title</title>\n\t<pubDate>$pub_date</pubDate>\n\t<link>$url/$prime_folder$post/$file/</link>\n\t<guid>$url/$prime_folder$post/$file/</guid>\n\t<description>$content</description>\n</item>\n$f_end" | awk -v chunk="$(date '+%B %d/%d/%Y %I:%M%p')" '{gsub("&lt;DATE_POST&gt;",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("<PAGE_CONTENT>",chunk)}1' | awk -v chunk="$url/$prime_folder$post/$file" '{gsub("<PAGE_URL>",chunk)}1' | awk -v chunk="$post" '{gsub("<POST_NAME>",chunk)}1' | awk -v chunk="$url/$prime_folder$post" '{gsub("<PAGE_PAGE>",chunk)}1' | awk -v chunk="$(date '+%B %m/%d/%Y %I:%M%p')" '{gsub("<DATE_POST>",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 <<EOF
+open $ftp
+user $user $pass
+
+cd public_html
+cd $css_upload_folder
+lcd static
+put $css_file
+cd /public_html
+
+$prime_mkdir
+$prim_cd_cmd
+
+$prime_folder_cmd
+
+mkdir "$post"
+cd "$post"
+lcd "$post"
+put index.xml
+put index.html
+EOF
+
+else
+
+ftp -n -vvv <<EOF
+open $ftp
+user $user $pass
+
+cd public_html
+cd $css_upload_folder
+lcd static
+put $css_file
+
+cd /public_html
+
+$prime_mkdir
+$prim_cd_cmd
+
+$prime_folder_cmd
+
+
+mkdir "$post"
+cd "$post"
+lcd "$post"
+put index.xml
+put index.html
+
+mkdir "$file"
+cd "$file"
+lcd "$file"
+put index.html
+EOF
+
+fi
diff --git a/template/index.html b/template/index.html
new file mode 100644
index 0000000..f88511d
--- /dev/null
+++ b/template/index.html
@@ -0,0 +1,11 @@
+<html>
+<head>
+<link rel="stylesheet" href="/assets/static-style.css?v=1" />
+</head>
+<body>
+<div class="static-main" >
+<br><br>
+rss: <a href="./index.xml" target="_blank"><img src="/assets/img/RSS.png" class="rss_img"></img></a>
+</div>
+</body>
+</html>
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 @@
+<?xml version="1.0" encoding="utf-8"?>
+<rss version="2.0">
+<channel>
+<title>iceys updates</title>
+<link>http://iceyfox.xyz/static/test</link>
+<description>this is a rss test</description>
+</channel>
+</rss>
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 @@
+<html>
+ <head>
+ <link rel="stylesheet" href="/assets/static-style.css?v=80" />
+ </head>
+ <body>
+ <div class="static-main">
+ <PAGE_CONTENT>
+ <br><br>
+ <a href="<PAGE_URL>"><PAGE_URL></a>
+ <a href="../index.xml" target="_blank">
+ <img src="/assets/img/RSS.png" class="rss_img">
+ </a>
+ </div>
+ </body>
+</html>
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:<POST_NAME>",
+ "content":"<DATE_POST> <PAGE_PAGE>\nread more here: <PAGE_URL>\n<PAGE_CONTENT>\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
+> <DATE_POST>
+
+### djsakladsjdsakl
+- a
+- b
+- c