cfenollosa / bashblog

A single Bash script to create blogs. Download, run, write, done!
1.66k stars 228 forks source link

clean regeneration of entry files #179

Closed philomorphism closed 1 year ago

philomorphism commented 1 year ago

on all rebuild run the main() function calls rebuild_all_entries(), within which a call to get_html_file_content() is made, and then using the returned information along with timestamp found in the entry a call to create_html_page() is made.

but the definition of create_html_page() contains the line echo -e '\n<!-- text end -->'. the newline character causes all the mess in the rebuilt entries. this happens because newline character gets multiplied in the process of regeneration, and that happens because the function get_html_file_content() returns all the lines between '<!-- $1 begin -->' and '<!-- $2 end -->', where the variables are either "entry" or "text". but this "content" includes the newline character that was inserted (which was necessary) in the first call to create_html_page(), and then because rebuild_all_entries() calls it again, on each such call an another newline character is added.

instead of adding (on which i haven't given much thought though) conditional statement in create_html_page(), the solution i have given is to just truncate the newline character from the returned string of get_html_file_content() to keep the "content" invariant under all these callings.

(this is my first open source commit, i apologize for explaining in boring details. btw, BashBlog is beautiful, thank you!)

philomorphism commented 1 year ago

here are some of the web source examples this PR is solving. the empty newlines seen here get multiplied on every ./bb rebuild. (the number of empty lines generally suggests the number of time the rebuild command was issues on the site)

image image