/* * [InsertBookMarkers.java] * * Summary: Insert markers between Insert macros to make them easy to sort. * * Copyright: (c) 2016-2017 Roedy Green, Canadian Mind Products, http://mindprod.com * * Licence: This software may be copied and used freely for any purpose but military. * http://mindprod.com/contact/nonmil.html * * Requires: JDK 1.8+ * * Created with: JetBrains IntelliJ IDEA IDE http://www.jetbrains.com/idea/ * * Version History: * 1.0 2016-06-26 initial version */ package com.mindprod.stores; import com.mindprod.common18.Misc; import com.mindprod.fastcat.FastCat; import com.mindprod.filter.ExtensionListFilter; import com.mindprod.htmlmacros.macro.Global; import com.mindprod.htmlmacros.support.ConfigurationForMindprod; import com.mindprod.hunkio.HunkIO; import java.io.File; import java.io.IOException; import java.util.List; import java.util.regex.Matcher; import java.util.regex.Pattern; /** * Insert markers between Insert macros to make them easy to sort. *

* one shot. * * @author Roedy Green, Canadian Mind Products * @version 1.0 2016-06-26 initial version * @since 2016-06-26 */ public class InsertBookMarkers { // TidyBookMacros: reflow Book macros. Update BookHead with recent title and published. Add missing published to BookHead. // RefreshInserts: refresh data on Insert macros from book page. Add missing published to book Insert. // InsertBookMarkers: put between books to make it easier to sort. One shot. // SortBooks: sort book Inserts on page so most recently published are first. // ProofreadInserts: check that sort worked. /** * true to get extra output */ private static final boolean DEBUGGING = false; /** * pieces used to compose regexes */ private static final Pattern BOOK_INSERT_FINDER = Pattern.compile( "" ); /** * webrootDir directory of website */ private static File webrootDir; /** * works with or without stripgenerated. * * @param args not used * * @throws IOException if trouble reading or writing files containing Book macros. */ public static void main( String[] args ) throws IOException { Global.installConfiguration( new ConfigurationForMindprod() ); // combine dirsWithMacros and dirsWithIncludes into dirsToProcess; final List a = Global.configuration.getDirsContainingHTMLMacros(); webrootDir = new File( Global.configuration.getLocalWebrootWithSlashes() ); for ( String dirname : a ) { final File dir = new File( webrootDir, dirname ); // out.println("Processing " + dir ); final String[] filenames = dir.list( new ExtensionListFilter( "html" ) ); for ( String filename : filenames ) { File file = new File( dir, filename ); final String big = HunkIO.readEntireFile( file, HunkIO.UTF8 ); if ( !big.contains( "" ) ) { /* already done */ continue; } final FastCat sb = new FastCat( 250 ); // look for first insert macro int start; int end; int count = 0; final Matcher m = BOOK_INSERT_FINDER.matcher( big ); if ( m.find() ) { // insert start marker before first Insert count++; start = m.start(); end = m.end(); sb.append( big.substring( 0, start ) ); sb.append( "\n\n" ); sb.append( big.substring( start, end ) ); } else { continue; // give up on this file. } while ( m.find() ) { count++; // insert separator marker before second Insert start = m.start(); sb.append( big.substring( end, start ) ); end = m.end(); sb.append( "\n\n" ); sb.append( big.substring( start, end ) ); } // finish off: if ( count >= 2 ) { // leave single book on page alone sb.append( "\n\n" ); sb.append( big.substring( end ) ); // replace original file contents. HunkIO.writeEntireFile( file, sb.toString(), HunkIO.UTF8 ); } } // end scan all files in dir } // end scan all dirs. Misc.trackLastThread(); System.exit( 0 ); } // end main }