#!/bin/sh
#] 
#] *********************
#] $ bash "$d_bin"'webURL convert [text, html].sh'  - convert URL test <-> html
# www.BillHowell.ca  30Nov2024 initial 
# view in text editor, using constant-width font (eg courier), tabWidth = 3

# 30Nov2024 iincomplete set of conversions, expecially for redirection links

#24************************24




#24************************24
# List of operators, generated with :
# $ grep  "^#]"  "$d_bin"'webURL convert [text, html].sh' |  sed "s/^#\]/  /" 

#




#08********08
# Setup 

source  "$d_bin"'standard header.sh'



#08********08
# code 

#] url_convert()  -  

	url_convert()
{  
	urlType="$1"		# 'text'  or 'html'
	url="$2"
	
	# normal text -> html links
	if		[ "$urlType" == 'text' ]; then
		url=$( echo  "$url"  |  sed 's| |%20|g'  )
		echo  "html     =  $url"
	# html - generate redirection urls from text (in YouTube etc)
	elif	[ "$urlType" == 'textRedirect' ]; then
		url=$( echo  "$url"  |  sed 's| |%20|g;s|:|%3A|g;s|\/|%2F|g;s|?|%3F|g;s|=|%3D|g'  )
		echo  "htmlRedir=  $url"
	# html - useable to generate text urls from browser for emails etc
	elif	[ "$urlType" == 'html' ]; then
		url=$( echo  "$url"  |  sed 's|%20| |g'  )
		echo  "text     =  $url"
	# htmlRedirect - text links from html redirection links (in YouTube etc)
	elif	[ "$urlType" == 'htmlRedirect' ]; then
		url=$( echo  "$url"  |  sed 's|%20| |g;s|%3A|:|g;s|%2F|\/|g;s|%3F|?|g;s|%3D|=|g'  )
		echo  "textRedir=  $url"
	else
		echo  "urlType  =  $urlType  must be OR[text, html, htmlRedirect]"
	fi
}  

#08********08
# Examples :

#] examples()  -  

	examples()
{  
		echo  'text     :  http://www.BillHowell.ca/economics, markets/'
	url_convert 'text' 'http://www.BillHowell.ca/economics, markets/'
		echo  'answer   :  http://www.BillHowell.ca/economics,%20markets/'
		echo  ''

		echo  'text     :  https://www.BillHowell.ca/economics, markets/PE Schiller forward vs 10yr Tbills/?=some junk'
	url_convert 'textRedirect'		'https://www.billhowell.ca/economics, markets/PE Schiller forward vs 10yr Tbills/?=some junk'
		echo  'answer   :  https%3A%2F%2Fwww.billhowell.ca%2Feconomics,%20markets%2FPE%20Schiller%20forward%20vs%2010yr%20Tbills%2F%3F%3Dsome%20junk'
		echo  ''

		echo  'html     :  http://www.BillHowell.ca/economics,%20markets/'
	url_convert 'html'   'http://www.BillHowell.ca/economics,%20markets/'
		echo  'answer   :  http://www.BillHowell.ca/economics, markets/'
		echo  ''

		echo  'htmlRedir:  https%3A%2F%2Fwww.billhowell.ca%2Feconomics,%20markets%2FPE%20Schiller%20forward%20vs%2010yr%20Tbills%2F%3F%3Dsome%20junk'
	url_convert 'htmlRedirect' 'https%3A%2F%2Fwww.billhowell.ca%2Feconomics,%20markets%2FPE%20Schiller%20forward%20vs%2010yr%20Tbills%2F%3F%3Dsome%20junk'
		echo  'answer   :  https://www.BillHowell.ca/economics, markets/PE Schiller forward vs 10yr Tbills/?=some junk'

}  


#08********08
# run - select one of options

	examples

# $ bash  "$d_bin"'webURL convert [text, html].sh'  

# enddoc
