squeeze

A static site generator that can put the toothpaste back in the tube.
git clone https://git.mulligrubs.me/squeeze
Log | Files | Refs | README | LICENSE

unsqueeze.sh (1406B)


      1 #!/usr/bin/env sh
      2 
      3 # Ungenerate a static website.
      4 
      5 # Usage: unsqueeze.sh site_path
      6 
      7 export site_path=$1
      8 
      9 export output_path="$site_path/output"
     10 export source_path="$site_path/source"
     11 
     12 # Copy everything that's not HTML.
     13 # Excludes the RSS folder, which we create ourselves upon generation.
     14 # This will also create the folder structure for the destination Markdown files.
     15 rsync --archive --delete --verbose \
     16        --exclude "*.html" --exclude "feeds" \
     17        "$output_path/" "$source_path/"
     18 
     19 # Parse and create all the Markdown files.
     20 html_files="$(find "$output_path" -type f -name "*.html")"
     21 line_count="$(echo "$html_files" | wc -l | tr -d -c '[:digit:]')"
     22 index=0
     23 
     24 echo "$html_files" |
     25 	sed "s|$output_path/||" |
     26 	while IFS= read -r file ; do
     27 		echo "$file"
     28 		index="$(expr "$index" + 1)"
     29 	
     30 		swipl --traditional --quiet -l parse_entry.pl -g "consult('$site_path/site.pl'), parse_entry('$output_path/$file')." |
     31 			# Unsmarten the punctuation.
     32 			sed 's/ / /g' |
     33 			# Replace single quotes.
     34 			sed "s/'/'/g" |
     35 			sed "s/‘/'/g" |
     36 			sed "s/’/'/g" |
     37 			sed "s/’/'/g" |
     38 			sed "s/‘/'/g" |
     39 			# Replace double quotes.
     40 			sed 's/“/"/g' |
     41 			sed 's/”/"/g' |
     42 			sed 's/”/"/g' |
     43 			sed 's/“/"/g' |
     44 			sed 's/"/"/g' \
     45 			> "$source_path/${file%.html}.md" &
     46 
     47 		# Wait until all jobs have completed.
     48 		[ "$index" -eq "$line_count" ] &&
     49 			wait
     50 	done