#!/bin/sh
#] 
#] *********************
#] $ bash  "/media/bill/SWAPPER/bin/conference guides - remove emails.sh"  - remove contact emails after conference is over
# www.BillHowell.ca  15Aug2019  initial, based on "conference guides - format html.sh"

dater=$(date +"%y%m%d %kh%Mm")


if [[  "$HOWELL_computer" = "RaspPi"  ]]; then
   d_temp="/media/bill/RaspPi_ext4_32Gb/temp/"
else
   d_temp="/media/bill/ramdisk/"
fi


# 1. Clean out email addresses in kwrite 
# 	set as regular expression search
# 	Search :		<(.*)>		Replace :	<...>					= protect file insert codes!! eg.  <!--- :@file-insert@: Header  --->
# 
# 2. join sentences in paragraphs
# 	set mouse point at start of paragraph(s)
# 	Search :  \n		Replace :  space							- for now, cannot do 
# 
# 3. to add <BR>s to blog emails :  
# 	1st pass	:	Search  \n				Replace  <BR>\n		- just search/replace ALL, then fix - faster!
# 					Search  <BR><BR>\n	Replace  <BR>\n		- search/replace ALL
# 					Search  ---><BR>		Replace  --->
# 					Search  </h1><BR>		Replace  </h1>
# 					Search  </h2><BR>		Replace  </h2>
# 					Search  </h3><BR>		Replace  </h3>
# 					Search  <HR><BR>		Replace  <HR>
# 					Search  <UL><BR>		Replace  <UL>
# 					Search  </UL><BR>		Replace  </UL>
# 					Search  </A><BR>		Replace  </A>

# 	2nd pass	:	Search  <BR>\n\n			Replace  <BR>\n<BR>\n
# 	3rd pass	:	Search  <BR><BR>\n	Replace  <BR>\n
# 


# 03Aug2019 edited "s/<^[!].*\(@.*>\)/<\.\.\.\1/g;" :  check how it works next time...

#] remove_emails()  - 

	remove_emails()
{  
p_guide="$d_guide$1"
p_guide_temp="$d_temp""$1"
cat "$p_guide"  |  sed 's/<Bill@BillHowell.ca>/<@BillHowell.ca>/Ig;s/<CaptainHook@BillHowell.ca>/<@BillHowell.ca>/I;s/WCCI_World_Congress_on_Computational_Intelligence@BillHowell.ca/@BillHowell.ca/I;s/<daniel.c.sung@gmail.com>/<@gmail.com>/I;s/<rlegoo@association-resources.com>/<@association-resources.com>/I;s/<AAites@association-resources.com>/<@association-resources.com>/I;s/<kgonzalez@association-resources.com>/<@association-resources.com>/I;s/<ijcnn2019@gmail.com>/<@gmail.com>/I;s/<chrisina.jayne@gmail.com>/<@gmail.com>/I'  >"$p_guide_temp" 
}  

# good test lesson 
# cat "$p_guide"  |  sed 's/<(.*)>/<\.\.\.>/g;s/^$/<BR>/'  >"$p_guide_temp" 
# s/^$/<BR>/;


#] remove_emails_from_guide()  - 

	remove_emails_from_guide()
{  
d_guide="$1"
p_fileList="$d_temp""fileList.txt"

find  "$d_guide"  -maxdepth 1   -type f  -name "*.html"  |  sed  's#'"$d_guide"'##g'  >"$p_fileList"

#doesn't work :  |  tr  \\n  \\0  |  xargs -0  -IFILE  bash  "/media/bill/SWAPPER/bin/conference guides - remove emails.sh"  "FILE"  >"$d_temp""FILE"   

while  read -r  f_name; do
	echo "fileName = $f_name"
	remove_emails "$f_name" 
done  <"$p_fileList" 
}  


# don't run this on ordinary web-pages!!
# look in d_temp for updated blog!
# select
 remove_emails_from_guide  "/media/bill/SWAPPER/Website - raw/Conference guides/Author guide website/"


# $  bash  "/media/bill/SWAPPER/bin/conference guides - remove emails.sh"


# enddoc
