diff --git a/README.md b/README.md index f37c167..03512b9 100644 --- a/README.md +++ b/README.md @@ -22,9 +22,11 @@ reduced. This is especially interesting for mobile devices. * (optional) Yahoo [`YUIcompressor`](https://github.com/yui/yuicompressor/releases) -This script was tested on `Gentoo Linux` with `Python 3.2.5` and +This script was tested on: +- Unknown Date: `Gentoo Linux` with `Python 3.2.5` and `BeautifulSoup4`. - +- 03.03.2020: `Windows 10 (Version 1809, OS Build: 17763.1039)` with `python3 (3.8.2)` and +`BeautifulSoup4 (4.8.2)`. ### Install ### Save `htmlmerge` to your bin path and make it executable. @@ -88,6 +90,9 @@ Make sure `~/bin/` is in your `$PATH` variable. htmlmerge index.html htmlmerge index.html -H -C -J -o build/out.html -u htmlmerge index.html -H --loglevel quiet -c -i -j + + Examples (Windows): + py htmlmerge index.dev.html -o index.html For CSS or JavaScript compression, additional YUIcompressor jar file must be present in the same directory as this script. @@ -115,6 +120,9 @@ output file. If there is no output file given the script will save to * possibility to pass arguments to htmlcompressor * add a preset system +### Development ### +* Use unix-style end-of-line LF. + ### Author ### Fin Christensen diff --git a/htmlmerge b/htmlmerge index d19022a..43a6382 100755 --- a/htmlmerge +++ b/htmlmerge @@ -380,8 +380,9 @@ else: try: with open (infile,'r') as f: indexHTML = f.read() - except: + except Exception as e: error ("Could not open \"" + infile + "\" !") + print(e) sys.exit(1) # end try # end if @@ -403,7 +404,7 @@ if merge_js: # iterate over script tags for tag in scripts: # get src url of script tag - if tag.has_key ("src"): + if tag.has_attr ("src"): # save source url to variable src_url = tag['src'] else: @@ -418,8 +419,9 @@ if merge_js: try: with open (src_url,'r') as f: all_scripts += f.read() - except: + except Exception as e: error ("Could not open \"" + src_url + "\" !") + print(e) sys.exit(1) # end try @@ -483,10 +485,10 @@ if merge_css: # iterate over link tags for tag in links: # get content of rel attribute - if tag.has_key ("rel"): + if tag.has_attr ("rel"): rel = " ".join (tag['rel']) - if rel == "stylesheet" and tag.has_key ("href"): + if rel == "stylesheet" and tag.has_attr ("href"): # get href url of link tag src_url = tag['href'] @@ -496,8 +498,9 @@ if merge_css: try: with open (src_url,'r') as f: all_css += f.read() - except: + except Exception as e: error ("Could not open \"" + src_url + "\" !") + print(e) sys.exit(1) # end try @@ -541,8 +544,9 @@ if merge_css: with open (src_url,'r') as f: # insert loaded css at old @import index all_css.insert (idx, f.read()) - except: + except Exception as e: error ("Could not open \"" + src_url + "\" !") + print(e) sys.exit(1) # end try # end if @@ -635,9 +639,10 @@ else: try: with open (outfile,'w') as f: - f.write ( all_html ) - except: - error ("Failed to save \"" + outfile + "\" ! Do we have permission?") + f.write ( all_html.decode('utf-8') ) + except Exception as e: + error ("Failed to save \"" + outfile + "\" ! Do we have permission? (Original error below)") + error (e) sys.exit(1) # end try # end if