diff --git a/noter.sh b/noter.sh index 7a4eb88..d4aa22d 100755 --- a/noter.sh +++ b/noter.sh @@ -1,51 +1,48 @@ #!/bin/bash -# noter 1.0.2 - @k@layer8.space - mit - -# ---- ---- ---- Useless Settings -favicon="favicon.png" - -# Show stuff at the bottom of the page: -showgenerator=true # Shows "generated with noter" -backtotop=true # Shows a back to top button for easier navigation -lastupdated=true # If we should show last update time at the bottom too +# noter 1.1.0 - "the lazy update" - @k@layer8.space - mit nlog() { - local ORANGE='\033[0;33m' - local NO_COLOR='\033[0m' - echo -e "${ORANGE}[noter] | ${1} ${NO_COLOR}" -} - -checksetting() { - # Use this function to check for a setting without repetition - # Eg: - # checksetting "yourmom" "$isyourmom" - if [ "$2" = true ]; then - echo "$1" >>"$output_file" - fi -} - -givefavicon() { - local file_path="$1" - - if [ -f "$file_path" ]; then - local base64_data="$(base64 -w 0 "$file_path")" - echo "data:image/png;base64,$base64_data" - fi -} - -generate_note_html() { - local note_date="$(date -d "$(basename "$1" .txt)" +"%B %d, %Y")" - echo "
" - echo "

$note_date

" - echo "
$(cat "$1")
" - echo "
" + local ORANGE='\033[0;33m' + local NO_COLOR='\033[0m' + echo -e "${ORANGE}[noter] | ${1} ${NO_COLOR}" } if [ ! -d "notes" ]; then - nlog "Error: 'notes' folder not found!" - exit 1 + nlog "Error: 'notes' folder not found!" + exit 1 fi +generate_note_html() { + local note_date="$(date -d "$(basename "$1" .txt)" +"%B %d, %Y")" + for img in $(grep -oP '(?<=" + echo "
" + if [ "$2" = true ]; then + echo "

$(date -d "$(basename "$1" .txt)" +"%Y")

" + fi + echo "

$note_date

" + echo "
$(cat "$1")
" + echo "
" +} + +generate_top_year_bar() { + local years=$(find notes -name "*.txt" ! -empty | cut -d'/' -f2 | cut -d'-' -f1 | sort -u | tac) + local top_bar="
" + local first_year=true + for year in $years; do + if [ "$first_year" = false ]; then + top_bar+=" | " + else + first_year=false + fi + top_bar+="$year" + done + top_bar+="

" + echo "$top_bar" +} + notecount=$(find notes -name "*.txt" ! -empty | wc -l) # Create HTML file @@ -53,13 +50,14 @@ output_file="notes.html" echo " - + $notecount notes | noter - - + + - + +

notes

" >"$output_file" - +generate_top_year_bar >>"$output_file" # loop for every note in notes nlog "generating page..." for file in $(ls -r notes/*.txt); do - nlog "processing: $file" - if [ -f "$file" ] && [ -s "$file" ]; then - generate_note_html "$file" >>"$output_file" - fi + nlog "processing: $file" + if [ -f "$file" ] && [ -s "$file" ]; then + generate_note_html "$file" >>"$output_file" + fi done -# Bottom navigation -checksetting "
generated with noter
" "$showgenerator" -checksetting "
Back to Top
" "$backtotop" -checksetting "
last Updated: $(date +"%Y-%m-%d %H:%M:%S")
" "$lastupdated" +# bottom navigation +echo "
generated with noter
" >>"$output_file" +echo "
Back to Top
" >>"$output_file" +echo "
last Updated: $(date +"%Y-%m-%d %H:%M:%S")
" >>"$output_file" echo "