diff --git a/book/the-panl-response-object.html b/book/the-panl-response-object.html index 99dba280..fccbc320 100644 --- a/book/the-panl-response-object.html +++ b/book/the-panl-response-object.html @@ -969,9 +969,9 @@

The Panl Response O
  • Clear all of the sorting options
  • Rendering the Initial Sorting Options

    1. Iterate through the available.sorting.fields JSON array
    2. -
    3. Render the value keyed on name ? output Name
    4. -
    5. For the ascending link render the
      <CaFUPs><set_uri_asc> ? output /mechanical-pencils/brandandname/11+grams/hexagonal/wsb+q/
      - For the descending link render the
      <CaFUPs><set_uri_desc> ? output
      /mechanical-pencils/brandandname/11+grams/hexagonal/wsb-q/
    6. +
    7. Render the value keyed on name ⇒ output Name
    8. +
    9. For the ascending link render the
      <CaFUPs><set_uri_asc> ⇒ output /mechanical-pencils/brandandname/11+grams/hexagonal/wsb+q/
      + For the descending link render the
      <CaFUPs><set_uri_desc> ⇒ output
      /mechanical-pencils/brandandname/11+grams/hexagonal/wsb-q/
    @@ -985,9 +985,9 @@

    The Panl Response O
  • Iterate through the available.sorting.fields JSON array
  • If the set_uri_asc or set_uri_desc key exists then
    1. -
    2. Render the value keyed on name ? output Name
    3. -
    4. For the ascending link render the
      <CaFUPs><add_uri_asc> ? output /mechanical-pencils/brandandname/11+grams/hexagonal/wsN+sb+q/
      - For the descending link render the
      <CaFUPs><add_uri_desc> ? output
      /mechanical-pencils/brandandname/11+grams/hexagonal/wsN+sb+q/
    5. +
    6. Render the value keyed on name ⇒ output Name
    7. +
    8. For the ascending link render the
      <CaFUPs><add_uri_asc> ⇒ output /mechanical-pencils/brandandname/11+grams/hexagonal/wsN+sb+q/
      + For the descending link render the
      <CaFUPs><add_uri_desc> ⇒ output
      /mechanical-pencils/brandandname/11+grams/hexagonal/wsN+sb+q/

    Example of Multi Sorting Display

    diff --git a/debookeriser.json b/debookeriser.json index 4ffeac1c..5e8e71da 100644 --- a/debookeriser.json +++ b/debookeriser.json @@ -11,6 +11,9 @@ "®" : "®" }, "contents": { + "table_of_contents_link": "

    »Table of Contents

    ", + + } } \ No newline at end of file diff --git a/src/main/java/com/synapticloop/debookeriser/Main.java b/src/main/java/com/synapticloop/debookeriser/Main.java index 57ac23a0..bd3bf486 100644 --- a/src/main/java/com/synapticloop/debookeriser/Main.java +++ b/src/main/java/com/synapticloop/debookeriser/Main.java @@ -27,6 +27,7 @@ import com.synapticloop.debookeriser.book.LinkElement; import com.synapticloop.debookeriser.book.Page; import org.apache.commons.io.FileUtils; +import org.json.JSONObject; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -45,15 +46,16 @@ public class Main { private final Map linkElements = new LinkedHashMap<>(); public Main(String fileName) { - try (BufferedReader br = new BufferedReader(new FileReader("replacements.csv", StandardCharsets.UTF_8))) { - String line; - while ((line = br.readLine()) != null) { - String[] split = line.split(","); - if(split.length == 2) { - replacements.put(split[0], split[1]); - } - } - } catch (IOException ignored) { + JSONObject jsonObject = new JSONObject(); + try { + jsonObject = new JSONObject(FileUtils.readFileToString(new File("debookeriser.json"), StandardCharsets.UTF_8)); + } catch (IOException e) { + throw new RuntimeException(e); + } + + JSONObject replacementsObject = jsonObject.optJSONObject("replacements"); + for (String key : replacementsObject.keySet()) { + replacements.put(key, replacementsObject.getString(key)); } this.googleDocsHTMLFile = new File(fileName); @@ -70,13 +72,9 @@ public void loadTemplate() throws IOException { public void parseGoogleHTMLFile() throws IOException { String googleDocsContent = FileUtils.readFileToString(googleDocsHTMLFile, StandardCharsets.UTF_8); - googleDocsContent = googleDocsContent.replaceAll("’", "'"); - googleDocsContent = googleDocsContent.replaceAll("‘", "'"); - googleDocsContent = googleDocsContent.replaceAll("™", "™"); - googleDocsContent = googleDocsContent.replaceAll("–", "-"); - googleDocsContent = googleDocsContent.replaceAll("…", "..."); - googleDocsContent = googleDocsContent.replaceAll("↩", "↩"); - googleDocsContent = googleDocsContent.replaceAll("®", "®"); + for (String key : replacements.keySet()) { + googleDocsContent = googleDocsContent.replaceAll(key, replacements.get(key)); + } Document doc = Jsoup.parse(googleDocsContent); diff --git a/src/main/java/com/synapticloop/debookeriser/book/Page.java b/src/main/java/com/synapticloop/debookeriser/book/Page.java index d8de40c6..0683bdc7 100644 --- a/src/main/java/com/synapticloop/debookeriser/book/Page.java +++ b/src/main/java/com/synapticloop/debookeriser/book/Page.java @@ -6,6 +6,7 @@ import java.io.File; import java.io.IOException; import java.nio.charset.Charset; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -35,7 +36,7 @@ public void writeContent(Map linkElements) throws IOExcepti .replace("##PREVIOUS_LINK##", previousPage) .replace("##NEXT_LINK##", nextPage); - FileUtils.writeStringToFile(new File(baseDirectory + getNicePageName(pageTitle) + ".html"), temp, Charset.defaultCharset()); + FileUtils.writeStringToFile(new File(baseDirectory + getNicePageName(pageTitle) + ".html"), temp, StandardCharsets.UTF_8); } private String getNicePageName(String pageName) {