From: Daniel Liu Date: Wed, 25 Nov 2020 05:10:19 +0000 (-0500) Subject: adding a removing multiple lines working X-Git-Url: https://git.danieliu.xyz/?a=commitdiff_plain;h=2a037724047c4f54023651b5bf81b4171356409e;p=pb.git adding a removing multiple lines working --- diff --git a/pb b/pb index c3bee84..6497287 100755 --- a/pb +++ b/pb @@ -51,6 +51,8 @@ new() { sub() { cat - |\ + sed "1i " |\ + sed "\$a " |\ sed "s|{{TITLE}}|$1|g; s|{{DATE}}|`date +'%a, %b %d %H:%M'`|g; s|{{URL}}|$website_url/$1|g" |\ @@ -76,14 +78,17 @@ publish() { cat $blog_template | sub "$to_publish" \ > "$data_dir/html/$to_publish.html" - index_entry="$(cat "$data_dir/templates/$index_template" | sub "$to_publish")" - - #sed is breaking when trying to add multiple lines for some reason + temp_index="$(mktemp)" # probably bad idea + cat "$data_dir/templates/$index_template" | sub "$to_publish" >> $temp_index + temp_rolling="$(mktemp)" + cat "$data_dir/templates/$rolling_template" | sub "$to_publish" >> $temp_rolling + temp_rss="$(mktemp)" + cat "$data_dir/templates/$rss_template" | sub "$to_publish" >> $temp_rss # Add new entry to blog index (do something about indent??) - - # echo -e "//a \n\n$index_entry\n" - sed -i "//a \n${index_entry}\n" "$blog_index_file" + sed -i "//r $temp_index" "$blog_index_file" + sed -i "//r $temp_rolling" "$rolling_file" + sed -i "//r $temp_rss" "$rss_file" mv "$data_dir/drafts/$to_publish.draft.html" "$data_dir/published/"