#] #] ********************* #] link d_Qndfs 'Website updates old converts.txt' # www.BillHowell.ca 28Oct2020 initial ? # old convert codes from link d_Qndfs 'Website updates.ndf' # may be very handy in the future - especially for "Conferece Guides' which I have not attempted to update # qnial> path_backupDated_retain (link d_Qndfs 'Website updates old converts.txt' ) #************************************ #] webPage_convertEncoding IS OP webPage - change [file-insert, www.BillHowell, .../, menuHeadFoots] # 22Oct2020 This converts Howell's old html "embedded encoding" to the new format # The new format allows far more [simple, flexible, powerful, consistent, reduced-error] web-page updating. # webPage_convertEncoding doesn't re-instate mailtos, as they are corrected in a second step # 23Oct2020 - # still need to have "dual temp files" to do the two-stage processing before over-writing original file # I should use modified file_backupDated_retain to save backups to a single directory # - it will be too much work to manually put them away, but this risks over-write of files with same name 25Oct2020 NUTS!!! I put quotes instead of apos around pnames of "embedded executables" IF flag_break THEN BREAK ; ENDIF ; webPage_convertEncoding IS OP webPage { LOCAL cmd grep_removeEnd sed_initiate sed_insertFile sed_insertFix sed_insertFix2 sed_pct20 sed_wwwHowell sed_backtracks sed_menuLevels sed_footLevels ; NONLOCAL chr_apo p_temp_webPage_convertEncoding ; % ; IF (NOT path_exists "r webPage) THEN EACH write '?webPage_convertEncoding file unknown error, webPage : ' webPage '' ; ELSE % first phase processing ; grep_removeEnd := link '| grep --invert-match ' chr_apo '' '|[#!: pinn_writeExecute_pout (link d_webWork \' chr_apo '\1\' chr_apo ') stdTmp d_webRaw d_webSite ; path_insertIn_fHand stdTmp fout ; |' ; sed_insertFix := link ';s|\[#!: path_insertIn_fHand (link d_webWork \"\(.*\)\") fout ' '|[#!: pinn_writeExecute_pout (link d_webWork \' chr_apo '\1\' chr_apo ') stdTmp d_webRaw d_webSite ; path_insertIn_fHand stdTmp fout ; |' ; sed_insertFix2 := link ';s|\[#!: path_insertIn_fHand (link d_webWork \(.*\)) fout ' '|[#!: pinn_writeExecute_pout (link d_webWork \1) stdTmp d_webRaw d_webSite ; path_insertIn_fHand stdTmp fout ; |' ; sed_pct20 := ';s|%20| |g' ; sed_wwwHowell := link ';s|"' p_temp_webPage_convertEncoding '" ' ; % write cmd ; host cmd ; ENDIF ; } #] webPage_mailtoFix IS OP webPage - put back %20 instead of space in mailtos # 23Oct2020 main issue is to put back %20 instead of space in mailtos, or they won't work # Note that wholesale replacement of %20 with spaces is DANGEROUS, as more than mailtos may be affected, # but I don't check this here. IF flag_break THEN BREAK ; ENDIF ; webPage_mailtoFix IS { LOCAL argList finn fout indices line lineList ; NONLOCAL chr_apo p_temp_webPage_convertEncoding p_temp_webPage_fixMailtos ; % ; IF (NOT AND (EACH path_exists ("r p_temp_webPage_convertEncoding) ("w p_temp_webPage_fixMailtos))) THEN EACH write '?webPage_mailtoFix file unknown error, OR [p_temp_webPage_convertEncoding, p_temp_webPage_fixMailtos]: ' p_temp_webPage_convertEncoding p_temp_webPage_fixMailtos '' ; ELSE finn := open p_temp_webPage_convertEncoding "r ; fout := open p_temp_webPage_fixMailtos "w ; WHILE (NOT isfault (line := readfile finn)) DO IF (subStr_in_str '"mailto:' line) THEN indices lineList := str_splitLftRgtTo_midlIndices_StrList 'mailto:' '">' line ; IF (not isfault indices) THEN argList := ' ' '%20' EACHRIGHT append lineList#indices ; lineList#indices := EACH str_replace_subStr argList ; line := link lineList ; writefile fout line ; ELSE write fault '?webPage_mailtoFix error : something wrong' ; ENDIF ; ELSE writefile fout line ; ENDIF ; ENDWHILE ; each close finn fout ; ENDIF ; } # loaddefs link d_Qndfs 'Website updates.ndf' IF flag_debug THEN write 'loading webPage_convert' ; ENDIF ; #] webPage_convert IS OP flag_overwrite webPage - converts Howell's "embedded encoding" and fixes mailtos # 23Oct2020 applies a two-stage process to convert embeddedEncoding, then fix resultant mailtos # COOL! unintended consequence! This means that mailtos can be composed with spaces, making them FAR more [read, work]-able!! IF flag_break THEN BREAK ; ENDIF ; webPage_convert IS OP flag_overwrite webPage { NONLOCAL d_htmlBackup p_temp_webPage_convertEncoding p_temp_webPage_fixMailtos ; IF (NOT AND (EACH path_exists ("w d_htmlBackup) ("w webPage))) THEN EACH write '?webPage_convert file unknown error, OR [d_htmlBackup, webPage] : ' d_htmlBackup webPage '' ; ELSE path_backupTo_dir webPage d_htmlBackup ; webPage_convertEncoding webPage ; IF (NOT path_exists "r p_temp_webPage_convertEncoding) THEN EACH write '?webPage_convert file unknown error, p_temp_webPage_convertEncoding : ' p_temp_webPage_convertEncoding '' ; ELSE webPage_mailtoFix ; IF flag_overwrite THEN host link 'mv "' p_temp_webPage_fixMailtos '" "' webPage '" ' ; ENDIF ; ENDIF ; ENDIF ; } #***************************** #] +-----+ #] Fix previous conversions of web-[pages, site] - don't use? # 25Oct2020 - It's much easier just to : 1. dirBackup_restoreTo_paths webpages from an earlier date 2. add corrections to webPage_convertEncoding 3. webSite_convert IF flag_debug THEN write '+-----+' ; ENDIF ; IF flag_debug THEN write 'Fix initial conversions of web-[pages, site]' ; ENDIF ; IF flag_debug THEN write 'loading webPage_fixInsertQuotes' ; ENDIF ; #] webPage_fixInsertQuotes IS OP flag_overwrite webPage - fix earlier screw-up: replace quotes with apos for file-inserts # 25Oct2020 This was inevitable # applied to files that have already been webPage_convertEncoding # depends on damage and what's in the over-written files # testing - write to test file, after - mv to original IF flag_break THEN BREAK ; ENDIF ; webPage_fixInsertQuotes IS OP flag_overwrite webPage { LOCAL cmd grep_removeEnd sed_initiate sed_insertFile sed_pct20 sed_wwwHowell sed_backtracks sed_menuLevels sed_footLevels ; NONLOCAL chr_apo d_htmlBackup p_temp_webPage_convertEncoding ; % ; IF flag_break THEN BREAK ; ENDIF ; IF (NOT path_exists "r webPage) THEN EACH write '?webPage_fixInsertQuotes file unknown error, webPage : ' webPage '' ; ELSE path_backupTo_dir webPage d_htmlBackup ; % first phase processing ; sed_initiate := '| sed -e "s' ; sed_insertFile := link '|\[#!: path_insertIn_fHand (link d_webWork \"\(.*\)\") fout ' '|[#!: path_insertIn_fHand (link d_webWork \' chr_apo '\1\' chr_apo ') fout |' ; IF flag_overwrite THEN output := link '" >"' webPage '" ' ; ELSE output := link '" >"' p_temp_webPage_convertEncoding '" ' ; ENDIF ; cmd := link 'cat "' webPage '" ' sed_initiate sed_insertFile output ; host cmd ; ENDIF ; } # qnial> webPage_fixInsertQuotes l (link d_webRaw 'Pandemics, health, and the Sun/influenza/Howell - influenza virus.html') >> Ok, works # qnial> webPage_fixInsertQuotes l (link d_webRaw 'economics, markets/SP500/multi-fractal/1872-2020 SP500 index, ratio of opening price to semi-log detrended price.html') >> MISSING file? # 25Oct2020 can't test esily as I've had to revert to old ""embedded encoding" backups # will run those IF flag_debug THEN write 'loading webSite_fixConversions' ; ENDIF ; #] webSite_fixConversions IS OP fixOptrPhrase - applies a fixPhrase to correct "embedded encodings" # 23Oct2020 applies a two-stage process to convert embeddedEncoding, then fix resultant mailtos # Note that this is specific to d_WebSite. Multiple webSites are a possibility, but this fix reduces error potential IF flag_break THEN BREAK ; ENDIF ; webSite_fixConversions IS OP fixOptrPhrase { LOCAL finn fout webPage webPageList ; NONLOCAL d_htmlBackup d_webRaw p_webPageList ; IF (NOT AND (EACH path_exists ("r p_webPageList) ("w d_webRaw))) THEN EACH write '?webSite_fixConversions file unknown error, one of : ' p_webPageList d_webRaw '' ; ELSE % create a new backup directory for every use of webSite_convert, as damage can be VERY time-costly ; d_htmlBackup := link d_webRaw 'z_Archive/' timestamp_YYMMDD_HMS 'backups/' ; host link 'mkdir "' d_htmlBackup '" ' ; % ; % refresh the list of webSite html files, excluding many directories (see 'Website header.ndf') ; % Most web-pages are in "Conference Guidelines", but I am NOT going to maintain those! ; webPageList := list_readFrm_path p_webPageList ; FOR webPage WITH webPageList DO IF flag_break THEN BREAK ; ENDIF ; % note that for the webSite, there is an automatic over-write of the original web-page ; % change this for initial test trials? ; write webPage ; apply fixOptrPhrase (l webPage) ; ENDFOR ; ENDIF ; } # enddoc