#! /bin/ksh # # Set this for your website: PARENTURL="http://sun.drydog.com/" MYNAME=generate_ebooks TMPOUT=/tmp/$MYNAME-out$$.tmp parentDir=$(basename $(dirname $PWD)) baseURL="$PARENTURL$shortDir" usage () { echo "Usage: $MYNAME [-h] htmlfile" echo "$MYNAME generate ebook files from HTML" echo "Where:" echo " -h Display this help" echo "Example: $MYNAME index.html" } # # Execution begins here # # Setup if [ "$1" = "-h" -o -z "$1" -o ! -f "$1" ] ; then usage; exit 1; fi inputHTML="$1" # # Create output filenames # shortDir=$(basename $PWD) shortTitle="$(echo "$shortDir" | sed 's/[-_]/ /g')" outputTXT="$shortDir.txt" outputPDF="$shortDir.pdf" # Note that Palm Pilot DOC PDB and Plucker PDB use the same extension: outputPDB="${shortDir}d.pdb" outputPlucker="${shortDir}p.pdb" # # Extract author from HTML element # # author=$(grep '"author"' $inputHTML | head -1 | sed 's/.*content="//' \ | sed 's/".*//') # # Convert to text and Palm Doc Pdb Format # http://homepage.mac.com/pauljlucas/software/txt2pdbdoc/ # # # Convert HTML to intermediate TEXT for use as Palm Pilot DOC PDB # (Note: title is scanned from the HTML tag and placed in line 1) # html2pdbtxt -u"$baseURL" $inputHTML $outputTXT >/dev/null # Get title from first line of $outputTXT longTitle="$(head -1 $outputTXT)" # # Convert intermediate TEXT file to Palm Pilot DOC PDB # txt2pdbdoc "$shortTitle" $outputTXT $outputPDB echo "Generated Palm Pilot DOC PDB file $outputPDB" # # Remove Palm Pilot weirdness from intermediate TEXT file for use as a # plain text file. # That is, # (1) Remove all "(*)" at the beginning of the line # and the preceeding newline, # (2) Remove the Palm Pilot end of file tag, "<(*)>". # (3) Convert to DOS format, with \r\n characters. # cp $outputTXT $TMPOUT cat $TMPOUT | grep -v '^<(\*)>$' | sed 's/$/@EOL@/g' | tr -d '\n' | \ sed 's/@EOL@(\*)//g' | sed 's/@EOL@/\r\n/g' >$outputTXT echo "Generated text output file $outputTXT" # # Create Plucker format # # NOTE: plucker-setup must be ran before plucker-build is ran the first time # to setup directory ~/.plucker/ and file ~/.pluckerrc and install PP apps. # NOTE: zip compression is available, but can only be used in PalmOS 3.0+. # Plucker supported with PalmOS 2.0+. # Zip not supported with this version of plucker-build, 1.8 # plucker-build --author="$author" \ --title="$longTitle" --doc-name="$shortTitle" --author="$author" \ --home-url="$baseURL/$inputHTML" --staybelow="$baseURL/" \ --maxdepth=1 --noimages \ --pluckerdir="$PWD" --doc-file="$(basename "$outputPlucker" .pdb)" echo "Generated Plucker PDB file $outputPlucker" # # Create PDF format with ebookconverter # Ref: http://www.kevinboone.com/ebookconverter.html # java -jar /usr/local/ebookconverter/ebookconverter.jar \ --format_options font-family=serif \ --source_options encoding=iso-8859-1 $inputHTML $outputPDF echo "Generated PDF file $outputPDF" # # Cleanup and terminate # rm -rf $TMPOUT