Skip to content

Commit

Permalink
Start of configuration and page regen - fixed UTF-8 output coding
Browse files Browse the repository at this point in the history
  • Loading branch information
synapticloop committed Jun 24, 2024
1 parent 3db6c2a commit 8c3dd3e
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
12 changes: 6 additions & 6 deletions book/the-panl-response-object.html
Original file line number Diff line number Diff line change
Expand Up @@ -969,9 +969,9 @@ <h1 class="c96 c66 c36" id="h.ptcvgc4pgkql"><span class="c6">The Panl Response O
<li class="c32 c108 li-bullet-0"><span class="c3">Clear all of the sorting options</span></li>
</ol><h4 class="c85 c66" id="h.y80wr7ry8dno"><span class="c119 c12 c104">Rendering the Initial Sorting Options</span></h4><ol class="c42 lst-kix_y1zqe712eim-0 start" start="1">
<li class="c4 li-bullet-0"><span>Iterate through the </span><span class="c1">available.sorting.fields</span><span class="c3">&nbsp;JSON array</span></li>
<li class="c4 li-bullet-0"><span>Render the value keyed on </span><span class="c1">name</span><span>&nbsp;? output </span><span class="c1">Name</span></li>
<li class="c66 c78 c224 li-bullet-0"><span>For the ascending link render the <br></span><span class="c1">&lt;CaFUPs&gt;&lt;set_uri_asc&gt;</span><span>&nbsp;? output </span><span class="c1">/mechanical-pencils/brandandname/11+grams/hexagonal/wsb+q/</span><span><br>
For the descending link render the<br></span><span class="c1">&lt;CaFUPs&gt;&lt;set_uri_desc&gt;</span><span>&nbsp;? output<br></span><span class="c1">/mechanical-pencils/brandandname/11+grams/hexagonal/wsb-q/</span></li>
<li class="c4 li-bullet-0"><span>Render the value keyed on </span><span class="c1">name</span><span>&nbsp; output </span><span class="c1">Name</span></li>
<li class="c66 c78 c224 li-bullet-0"><span>For the ascending link render the <br></span><span class="c1">&lt;CaFUPs&gt;&lt;set_uri_asc&gt;</span><span>&nbsp; output </span><span class="c1">/mechanical-pencils/brandandname/11+grams/hexagonal/wsb+q/</span><span><br>
For the descending link render the<br></span><span class="c1">&lt;CaFUPs&gt;&lt;set_uri_desc&gt;</span><span>&nbsp; output<br></span><span class="c1">/mechanical-pencils/brandandname/11+grams/hexagonal/wsb-q/</span></li>
</ol><a id="t.eba61ded04f04436fac691715917caf9fb7258b7"></a><a id="t.120"></a><table class="c21">
<tbody>
<tr class="c5">
Expand All @@ -985,9 +985,9 @@ <h1 class="c96 c66 c36" id="h.ptcvgc4pgkql"><span class="c6">The Panl Response O
<li class="c4 li-bullet-0"><span>Iterate through the </span><span class="c1">available.sorting.fields</span><span class="c3">&nbsp;JSON array</span></li>
<li class="c4 li-bullet-0"><span>If the </span><span class="c1">set_uri_asc</span><span>&nbsp;or </span><span class="c1">set_uri_desc</span><span class="c3">&nbsp;key exists then</span></li>
</ol><ol class="c42 lst-kix_2knqapsl7wrn-1 start" start="1">
<li class="c32 c108 li-bullet-0"><span>Render the value keyed on </span><span class="c1">name</span><span>&nbsp;? output </span><span class="c1">Name</span></li>
<li class="c224 c66 c108 li-bullet-0"><span>For the ascending link render the <br></span><span class="c1">&lt;CaFUPs&gt;&lt;add_uri_asc&gt;</span><span>&nbsp;? output </span><span class="c1">/mechanical-pencils/brandandname/11+grams/hexagonal/wsN+sb+q/</span><span><br>
For the descending link render the<br></span><span class="c1">&lt;CaFUPs&gt;&lt;add_uri_desc&gt;</span><span>&nbsp;? output<br></span><span class="c2 c41">/mechanical-pencils/brandandname/11+grams/hexagonal/wsN+sb+q/</span></li>
<li class="c32 c108 li-bullet-0"><span>Render the value keyed on </span><span class="c1">name</span><span>&nbsp; output </span><span class="c1">Name</span></li>
<li class="c224 c66 c108 li-bullet-0"><span>For the ascending link render the <br></span><span class="c1">&lt;CaFUPs&gt;&lt;add_uri_asc&gt;</span><span>&nbsp; output </span><span class="c1">/mechanical-pencils/brandandname/11+grams/hexagonal/wsN+sb+q/</span><span><br>
For the descending link render the<br></span><span class="c1">&lt;CaFUPs&gt;&lt;add_uri_desc&gt;</span><span>&nbsp; output<br></span><span class="c2 c41">/mechanical-pencils/brandandname/11+grams/hexagonal/wsN+sb+q/</span></li>
</ol><h4 class="c66 c204 c231" id="h.egpcgrnjrn1g"><span class="c119 c12 c104">Example of Multi Sorting Display</span></h4><a id="t.ed264438fdbf1e76b3db396dfeb5bda0fd26eb95"></a><a id="t.121"></a><table class="c21">
<tbody>
<tr class="c5">
Expand Down
3 changes: 3 additions & 0 deletions debookeriser.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
"&reg;" : "®"
},
"contents": {
"table_of_contents_link": "<h2 style=\"margin: 0px 0px 0px 4px; padding: 2px;\"><a href=\"/panl/book/\">&raquo;Table of Contents</a></h2>",



}
}
30 changes: 14 additions & 16 deletions src/main/java/com/synapticloop/debookeriser/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -45,15 +46,16 @@ public class Main {
private final Map<String, LinkElement> 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);
Expand All @@ -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("&rsquo;", "'");
googleDocsContent = googleDocsContent.replaceAll("&lsquo;", "'");
googleDocsContent = googleDocsContent.replaceAll("&trade;", "™");
googleDocsContent = googleDocsContent.replaceAll("&ndash;", "-");
googleDocsContent = googleDocsContent.replaceAll("&hellip;", "...");
googleDocsContent = googleDocsContent.replaceAll("&#8617;", "↩");
googleDocsContent = googleDocsContent.replaceAll("&reg;", "®");
for (String key : replacements.keySet()) {
googleDocsContent = googleDocsContent.replaceAll(key, replacements.get(key));
}

Document doc = Jsoup.parse(googleDocsContent);

Expand Down
3 changes: 2 additions & 1 deletion src/main/java/com/synapticloop/debookeriser/book/Page.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -35,7 +36,7 @@ public void writeContent(Map<String, LinkElement> 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) {
Expand Down

0 comments on commit 8c3dd3e

Please sign in to comment.