Skip to content

Commit 5fab7cc

Browse files
author
synapticloop
committed
Added in documentation links and navigation sidebar
1 parent e55be56 commit 5fab7cc

25 files changed

+1911
-232
lines changed

book/.html

+77-4
Large diffs are not rendered by default.

book/a-brief-introduction-to-solr.html

+78-5
Large diffs are not rendered by default.

book/code-flow.html

+77-4
Large diffs are not rendered by default.

book/design-considerations.html

+78-5
Large diffs are not rendered by default.

book/epilogue.html

+77-4
Large diffs are not rendered by default.

book/getting-started.html

+85-12
Large diffs are not rendered by default.

book/how-it-all-fits-together.html

+77-4
Large diffs are not rendered by default.

book/index.html

+84-11
Large diffs are not rendered by default.

book/integrating-an-existing-solr-schema.html

+77-4
Large diffs are not rendered by default.

book/json-object-keys-quick-reference.html

+80-7
Large diffs are not rendered by default.

book/panl-configuration.html

+98-25
Large diffs are not rendered by default.

book/panl-cookbook.html

+77-4
Large diffs are not rendered by default.

book/panl-lpse-uri-paths-explained.html

+77-4
Large diffs are not rendered by default.

book/properties-quick-reference.html

+134-61
Large diffs are not rendered by default.

book/quick-start---the-5-steps.html

+81-8
Large diffs are not rendered by default.

book/readme-1st.html

+84-11
Large diffs are not rendered by default.

book/the-panl-response-object.html

+82-9
Large diffs are not rendered by default.

book/what-you-will-need.html

+79-6
Large diffs are not rendered by default.

book/why-synapticloop-panl-.html

+79-6
Large diffs are not rendered by default.

index.html

+16-14
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,20 @@ <h2>Welcome To Synapticloop Panl</h2>
3838
<h3>Why?</h3>
3939

4040
<p>Because <code>/Caran+d'Ache/true/Black/bDW/</code> looks nicer than
41-
<p><pre>
42-
q=*:*&facet.mincount=1&rows=10&facet.field=lead_size_indicator&
43-
facet.field=grip_material&facet.field=colours&facet.field=nib_shape&
44-
facet.field=diameter&facet.field=cap_shape&facet.field=brand&
45-
facet.field=mechanism_type&facet.field=length&facet.field=hardness_indicator
46-
&facet.field=grip_type&facet.field=cap_material&facet.field=lead_grade_indicator
47-
&facet.field=tubing_material&facet.field=in_built_sharpener&
48-
facet.field=disassemble&facet.field=category&facet.field=body_shape&
49-
facet.field=clip_material&facet.field=mechanism_material&facet.field=lead_length
50-
&facet.field=body_material&facet.field=in_built_eraser&facet.field=grip_shape
51-
&facet.field=relative_weight&facet.field=name&facet.field=nib_material
52-
&facet.field=weight&facet.field=variants&facet=true&fq=brand:"Caran+d'Ache"
53-
&fq=disassemble:"true"&fq=colours:"Black"&q.op=AND</pre></p>
41+
<p>
42+
<code>q=*:*&facet.mincount=1&rows=10&facet.field=lead_size_indicator&</code><br />
43+
<code>facet.field=grip_material&facet.field=colours&facet.field=nib_shape&</code><br />
44+
<code>facet.field=diameter&facet.field=cap_shape&facet.field=brand&</code><br />
45+
<code>facet.field=mechanism_type&facet.field=length&facet.field=hardness_indicator</code><br />
46+
<code>&facet.field=grip_type&facet.field=cap_material&facet.field=lead_grade_indicator</code><br />
47+
<code>&facet.field=tubing_material&facet.field=in_built_sharpener&</code><br />
48+
<code>facet.field=disassemble&facet.field=category&facet.field=body_shape&</code><br />
49+
<code>facet.field=clip_material&facet.field=mechanism_material&facet.field=lead_length</code><br />
50+
<code>&facet.field=body_material&facet.field=in_built_eraser&facet.field=grip_shape</code><br />
51+
<code>&facet.field=relative_weight&facet.field=name&facet.field=nib_material</code><br />
52+
<code>&facet.field=weight&facet.field=variants&facet=true&fq=brand:"Caran+d'Ache"</code><br />
53+
<code>&fq=disassemble:"true"&fq=colours:"Black"&q.op=AND</code>
54+
</p>
5455

5556
<h3>Additional Panl Niceties</h3>
5657
<ol>
@@ -70,6 +71,7 @@ <h3>Additional Panl Niceties</h3>
7071

7172
<ul class="actions">
7273
<li><a href="https://github.com/synapticloop/panl/" class="button alt">Browse the code</a></li>
74+
<li><a href="https://synapticloop.github.io/panl/" class="button alt">Read the book online</a></li>
7375
</ul>
7476
</div>
7577
<div class="4u$ 12u$(medium) important(medium)"><span class="image fit rounded"><img
@@ -88,7 +90,7 @@ <h3>Additional Panl Niceties</h3>
8890
<div class="icon-grid">
8991
<div class="row uniform 150%">
9092
<section class="4u 6u(large) 12u$(small)"><i class="icon fa-book"></i>
91-
<h3>Read the book</h3>
93+
<h3>Read Offline</h3>
9294
<p>Prefer a PDF all on one to print or take with you?</p>
9395
<p><a href="#">Download the book...</a></p>
9496
</section>

src/main/java/com/synapticloop/debookeriser/Main.java

+44-21
Original file line numberDiff line numberDiff line change
@@ -24,21 +24,25 @@
2424
* IN THE SOFTWARE.
2525
*/
2626

27+
import com.synapticloop.debookeriser.book.LinkElement;
28+
import com.synapticloop.debookeriser.book.Page;
2729
import org.apache.commons.io.FileUtils;
2830
import org.jsoup.nodes.Document;
2931
import org.jsoup.nodes.Element;
30-
import org.jsoup.select.Elements;
3132

3233
import java.io.*;
3334
import java.nio.charset.Charset;
34-
import java.util.LinkedHashMap;
35-
import java.util.Map;
35+
import java.util.*;
3636

3737
import org.jsoup.*;
3838

3939
public class Main {
4040
private final File googleDocsHTMLFile;
4141
private String template;
42+
43+
private final List<Page> pages = new ArrayList<>();
44+
private final Map<String, LinkElement> linkElements = new LinkedHashMap<>();
45+
4246
public Main(String fileName) {
4347
this.googleDocsHTMLFile = new File(fileName);
4448
}
@@ -52,45 +56,64 @@ public void loadTemplate() throws IOException {
5256
template = FileUtils.readFileToString(new File("src/main/resources/template.html"), Charset.defaultCharset());
5357
}
5458

55-
private Map<String, String> pages = new LinkedHashMap<>();
5659
public void parseGoogleHTMLFile() throws IOException {
5760
Document doc = Jsoup.parse(googleDocsHTMLFile);
58-
boolean hasFirstPage = false;
59-
String outputPage = "book/index.html";
6061

6162
StringBuilder styles = new StringBuilder();
6263
for (Element style : doc.getElementsByTag("style")) {
6364
styles.append(style.outerHtml());
6465
}
66+
6567
template = template.replace("##STYLE##", styles.toString());
6668

69+
Page page = new Page("index", "book/", template);
70+
6771
boolean hasRemovedFirstDiv = false;
68-
StringBuilder contents = new StringBuilder();
72+
6973
for (Element body : doc.getElementsByTag("body")) {
70-
for (Element allElement : body.children()) {
71-
String tagName = allElement.tag().getName();
74+
for (Element childElement : body.children()) {
75+
String tagName = childElement.tag().getName();
76+
77+
getAllIds(page.getPageTitle(), childElement);
78+
7279
if(tagName.equals("h1")) {
73-
String temp = template.replace("##CONTENT##", contents.toString());
74-
System.out.println(temp.length());
75-
FileUtils.writeStringToFile(new File(outputPage), temp, Charset.defaultCharset());
76-
outputPage = "book/" + getNicePageName(allElement.text()) +".html";
77-
System.out.println(outputPage);
78-
contents.setLength(0);
79-
contents.append(allElement.outerHtml());
80-
} else {
80+
// now start a new page
81+
pages.add(page);
8182

83+
page = new Page(childElement.text(), "book/", template);
84+
linkElements.put("#" + childElement.attr("id"), new LinkElement(page.getPageTitle(), childElement));
85+
page.addPageElement(childElement);
86+
} else {
8287
if(!hasRemovedFirstDiv && tagName.equals("div")) {
8388
// skip this one
8489
} else {
85-
contents.append(allElement.outerHtml());
90+
page.addPageElement(childElement);
8691
}
87-
8892
}
8993
}
94+
95+
pages.add(page);
96+
}
97+
98+
for(Page outputPage : pages) {
99+
outputPage.writeContent(linkElements);
90100
}
91101
}
92-
private String getNicePageName(String pageName) {
93-
return(pageName.toLowerCase().replaceAll("[^a-z0-9]", "-"));
102+
103+
private void getAllIds(String pageTitle, Element element) {
104+
String id = element.attr("id");
105+
// we only want to put in heading, which will be in order, not links to headings
106+
// if(element.tagName().startsWith("h") && !id.isBlank()) {
107+
// linkElements.put("#" + id, new LinkElement(pageTitle, element));
108+
// }
109+
110+
if(!id.isBlank()) {
111+
linkElements.put("#" + id, new LinkElement(pageTitle, element));
112+
}
113+
114+
for(Element childElement : element.children()) {
115+
getAllIds(pageTitle, childElement);
116+
}
94117
}
95118

96119
public static void main(String[] args) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package com.synapticloop.debookeriser.book;
2+
3+
import org.jsoup.nodes.Attribute;
4+
import org.jsoup.nodes.Element;
5+
6+
public class LinkElement {
7+
private final String pageTitle;
8+
private final String id;
9+
private final String tagName;
10+
private final Element element;
11+
12+
public LinkElement(String pageTitle, Element element) {
13+
this.pageTitle = pageTitle;
14+
this.element = element;
15+
this.tagName = element.tagName();
16+
17+
this.id = element.attr("id");
18+
}
19+
20+
public String getLink() {
21+
return(getNicePageName(pageTitle) + ".html#" + id);
22+
}
23+
24+
private String getNicePageName(String pageTitle) {
25+
return pageTitle.toLowerCase().replaceAll("[^a-z0-9]", "-");
26+
}
27+
28+
public String getPageTitle() {
29+
return (pageTitle);
30+
}
31+
32+
public String getId() {
33+
return (id);
34+
}
35+
36+
public String getContent() {
37+
return(element.text());
38+
}
39+
40+
public String getTagName() {
41+
return (tagName);
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
package com.synapticloop.debookeriser.book;
2+
3+
import org.apache.commons.io.FileUtils;
4+
import org.jsoup.nodes.Element;
5+
6+
import java.io.File;
7+
import java.io.IOException;
8+
import java.nio.charset.Charset;
9+
import java.util.ArrayList;
10+
import java.util.List;
11+
import java.util.Map;
12+
13+
public class Page {
14+
private final String pageTitle;
15+
private final String baseDirectory;
16+
private final String template;
17+
private List<String> styles;
18+
private List<PageElement> pageElements = new ArrayList<>();
19+
20+
public Page(String pageTitle, String baseDirectory, String template) {
21+
this.pageTitle = pageTitle;
22+
this.baseDirectory = baseDirectory;
23+
this.template = template;
24+
}
25+
26+
public void addPageElement(Element element) {
27+
pageElements.add(new PageElement(element));
28+
}
29+
30+
public void setStyles(List<String> styles) {
31+
this.styles = styles;
32+
}
33+
34+
public void writeContent(Map<String, LinkElement> linkElements) throws IOException {
35+
String temp = template.replace("##CONTENT##", getPageContent(linkElements))
36+
.replace("##NAVIGATION##", getPageNavigation(linkElements));
37+
FileUtils.writeStringToFile(new File(baseDirectory + getNicePageName(pageTitle) + ".html"), temp, Charset.defaultCharset());
38+
}
39+
40+
private String getNicePageName(String pageName) {
41+
return(pageName.toLowerCase().replaceAll("[^a-z0-9]", "-"));
42+
}
43+
44+
private String getPageContent(Map<String, LinkElement> linkElements) {
45+
StringBuilder sb = new StringBuilder();
46+
47+
for(PageElement pageElement : pageElements) {
48+
sb.append(pageElement.getContent(linkElements));
49+
}
50+
51+
return(sb.toString());
52+
}
53+
54+
private String getPageNavigation(Map<String, LinkElement> linkElements) {
55+
boolean foundUs = false;
56+
boolean hasFinished = false;
57+
StringBuilder sb = new StringBuilder();
58+
sb.append("<h2 style=\"margin: 0px 0px 0px 4px; padding: 2px;\"><a href=\"/panl/book/\">&raquo;Table of Contents</a></h2>");
59+
60+
for (String key : linkElements.keySet()) {
61+
LinkElement linkElement = linkElements.get(key);
62+
if(linkElement.getTagName().equals("h1")) {
63+
if (linkElement.getPageTitle().equals(pageTitle)) {
64+
sb.append("<section class=\"current-page\">");
65+
foundUs = true;
66+
} else {
67+
if(foundUs) {
68+
hasFinished = true;
69+
}
70+
foundUs = false;
71+
}
72+
}
73+
74+
String content = linkElement.getContent();
75+
if(foundUs) {
76+
if(!content.isBlank()) {
77+
switch(linkElement.getTagName()) {
78+
case "h1":
79+
sb.append(String.format("<h1 style=\"margin: 0px; padding: 2px;\">%s</h4>", content));
80+
break;
81+
case "h2":
82+
sb.append(String.format("<h2 style=\"margin: 0px 0px 0px 4px; padding: 2px;\"><a href=\"%s\">%s</a></h5>", linkElement.getLink(), content));
83+
break;
84+
case "h3":
85+
sb.append(String.format("<h3 style=\"margin: 0px 0px 0px 8px; padding: 2px;\"><a href=\"%s\">%s</a></h6>", linkElement.getLink(), content));
86+
break;
87+
}
88+
}
89+
} else {
90+
if(!content.isBlank()) {
91+
switch (linkElement.getTagName()) {
92+
case "h1":
93+
if(hasFinished) {
94+
sb.append("</section>");
95+
hasFinished = false;
96+
}
97+
sb.append(String.format("<h2 style=\"margin: 0px 0px 0px 4px; padding: 2px;\"><a href=\"%s\">&raquo;%s</a></h5>", linkElement.getLink(), content));
98+
break;
99+
}
100+
}
101+
}
102+
}
103+
104+
return(sb.toString());
105+
}
106+
107+
public String getPageTitle() {
108+
return (pageTitle);
109+
}
110+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package com.synapticloop.debookeriser.book;
2+
3+
import org.jsoup.nodes.Element;
4+
5+
import java.util.Map;
6+
7+
public class PageElement {
8+
public static final String GOOGLE_TRACKING_URL = "https://www.google.com/url?q=";
9+
private final Element element;
10+
11+
public PageElement(Element element) {
12+
this.element = element;
13+
}
14+
15+
public String getContent(Map<String, LinkElement> linkElements) {
16+
convertAnchors(element, linkElements);
17+
return (element.outerHtml());
18+
}
19+
20+
private void convertAnchors(Element element, Map<String, LinkElement> linkElements) {
21+
for (Element childElement : element.children()) {
22+
if (childElement.tagName().equals("a")) {
23+
String href = childElement.attr("href");
24+
if (!href.startsWith("http")) {
25+
if (linkElements.containsKey(href)) {
26+
childElement.attr("href", linkElements.get(href).getLink());
27+
}
28+
} else {
29+
if(href.startsWith(GOOGLE_TRACKING_URL)) {
30+
href = href.substring(GOOGLE_TRACKING_URL.length(), href.indexOf("&"));
31+
}
32+
if(href.startsWith("https://docs.google.com")) {
33+
href = "#";
34+
}
35+
childElement.attr("href", href);
36+
}
37+
}
38+
convertAnchors(childElement, linkElements);
39+
}
40+
}
41+
}

0 commit comments

Comments
 (0)