From 70e50c0f524202cfe36c29acd733d79bc11d9ebc Mon Sep 17 00:00:00 2001 From: "sigonasr2, Sig, Sigo" Date: Wed, 4 May 2022 20:21:52 +0000 Subject: [PATCH] Prepare article reference replacement. --- out/DIRECTORY_LISTING | 14 +-- out/articles/DIRECTORY_LISTING | 8 +- out/articles/test articles/DIRECTORY_LISTING | 8 +- out/otherpage.html | 10 +- sigPlace.java | 121 ++++++++++++------- sitefiles/otherpage.html | 10 +- 6 files changed, 100 insertions(+), 71 deletions(-) diff --git a/out/DIRECTORY_LISTING b/out/DIRECTORY_LISTING index fda7084..620f59e 100644 --- a/out/DIRECTORY_LISTING +++ b/out/DIRECTORY_LISTING @@ -1,4 +1,4 @@ - + @@ -18,12 +18,12 @@
-

Directory Listing for /

📁articles 2022-05-04T19:35:50.868925Z gitpod 116
-
🗎codeBackground 2022-05-04T19:35:50.828925Z gitpod 2635
-
🗎otherpage.html 2022-05-04T19:35:50.836925Z gitpod 901
-
🗎reset.css 2022-05-04T19:35:50.840925Z gitpod 1093
-
🗎sig.css 2022-05-04T19:35:50.852925Z gitpod 4314
-
🗎testfile.html 2022-05-04T19:35:50.856925Z gitpod 829
+

Directory Listing for /

📁articles 2022-05-04T20:08:17.510417Z gitpod 116
+
🗎codeBackground 2022-05-04T20:08:17.482417Z gitpod 2635
+
🗎otherpage.html 2022-05-04T20:08:17.490417Z gitpod 941
+
🗎reset.css 2022-05-04T20:08:17.494417Z gitpod 1093
+
🗎sig.css 2022-05-04T20:08:17.498417Z gitpod 4314
+
🗎testfile.html 2022-05-04T20:08:17.502417Z gitpod 829
diff --git a/out/articles/DIRECTORY_LISTING b/out/articles/DIRECTORY_LISTING index 50e251d..bb14ee0 100644 --- a/out/articles/DIRECTORY_LISTING +++ b/out/articles/DIRECTORY_LISTING @@ -1,4 +1,4 @@ - + @@ -18,9 +18,9 @@
-

Directory Listing for /articles/

🗎curabitur vel tempus ex.article 2022-05-04T19:35:50.808925Z gitpod 618
-
🗎sigplace1.article 2022-05-04T19:35:50.812925Z gitpod 1559
-
📁test articles 2022-05-04T19:35:50.716925Z gitpod 69
+

Directory Listing for /articles/

🗎curabitur vel tempus ex.article 2022-05-04T20:08:17.466417Z gitpod 618
+
🗎sigplace1.article 2022-05-04T20:08:17.474417Z gitpod 1559
+
📁test articles 2022-05-04T20:08:17.398417Z gitpod 69
diff --git a/out/articles/test articles/DIRECTORY_LISTING b/out/articles/test articles/DIRECTORY_LISTING index 92666e3..a8b4390 100644 --- a/out/articles/test articles/DIRECTORY_LISTING +++ b/out/articles/test articles/DIRECTORY_LISTING @@ -1,4 +1,4 @@ - + @@ -18,9 +18,9 @@
-

Directory Listing for /articles/test articles/

🗎test1.article 2022-05-04T19:35:50.816925Z gitpod 1111
-
🗎test2.article 2022-05-04T19:35:50.820925Z gitpod 807
-
🗎test3.article 2022-05-04T19:35:50.820925Z gitpod 1020
+

Directory Listing for /articles/test articles/

🗎test1.article 2022-05-04T20:08:17.474417Z gitpod 1111
+
🗎test2.article 2022-05-04T20:08:17.474417Z gitpod 807
+
🗎test3.article 2022-05-04T20:08:17.478417Z gitpod 1020
diff --git a/out/otherpage.html b/out/otherpage.html index 18128a0..aef7a91 100644 --- a/out/otherpage.html +++ b/out/otherpage.html @@ -19,11 +19,11 @@
This is a different webpage.
-$ARTICLE sigplace1 -$ARTICLE test articles/test1 -$ARTICLE test articles/test2 -$ARTICLE test articles/test3 -$ARTICLE curabitur vel tempus ex +$ARTICLE_PREVIEW sigplace1 +$ARTICLE_PREVIEW test articles/test1 +$ARTICLE_PREVIEW test articles/test2 +$ARTICLE_PREVIEW test articles/test3 +$ARTICLE_PREVIEW curabitur vel tempus ex
diff --git a/sigPlace.java b/sigPlace.java index f1c4e8d..cddea91 100644 --- a/sigPlace.java +++ b/sigPlace.java @@ -58,52 +58,10 @@ public class sigPlace { try { copyDirectory("sitefiles","out"); Iterator items = Files.walk(Paths.get("out")).iterator(); - while (items.hasNext()) { - Path f = items.next(); - System.out.println(" Found "+f.getFileName()); - if (Files.isRegularFile(f)) { - try { - - System.out.println(" Preparing "+f.getFileName()); - - List content = Files.readAllLines(f); - if (isHTMLFile(f)) { - content.addAll(0,Files.readAllLines(ops.get("%DEFAULT"))); - content.addAll(Files.readAllLines(ops.get("%FOOTER"))); - } - - System.out.println(" Parsing "+f.getFileName()); - for (int i=0;i0&&isArticleFile(f)) { - //Check for markdown pieces. - if (s.charAt(0)=='-') { - //Start of a title piece. - s=s.replace("-",map.get("$TITLE_CONTENT_START")); - s=s+map.get("$TITLE_CONTENT_END").replace("%ID%","id=\"content_"+i+"\""); - //Use ⤈ if there's more text to be shown than can fit. - } else - if (s.contains("===")) { - s=map.get("$CONTENT_END")+map.get("$DATE_CONTENT_START")+s.replace("===","")+map.get("$CONTENT_END")+"




⤈ Click to expand.
"+map.get("$CONTENT_END"); - } - } - for (String key : map.keySet()) { - s=s.replaceAll(Pattern.quote(key),map.get(key)); - } - content.set(i,s); - } - - System.out.println(" Writing to "+f.toAbsolutePath()); + ParseArticleFiles(items); - Files.write(f, content, Charset.defaultCharset(),StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING,StandardOpenOption.WRITE); - - System.out.println(" "+f.getFileName() + " conversion complete!"); - - } catch (IOException e) { - e.printStackTrace(); - } - } - } + items = Files.walk(Paths.get("out")).iterator(); + ConvertArticleReferences(items); }catch (IOException e) { e.printStackTrace(); System.err.println("Copying files over failed!"); @@ -126,6 +84,77 @@ public class sigPlace { System.out.println("\nStarting web server..."); new sigServer(); } + private static void ParseArticleFiles(Iterator items) { + while (items.hasNext()) { + Path f = items.next(); + System.out.println(" Found "+f.getFileName()); + if (Files.isRegularFile(f)) { + try { + + System.out.println(" Preparing "+f.getFileName()); + + List content = Files.readAllLines(f); + if (isHTMLFile(f)) { + content.addAll(0,Files.readAllLines(ops.get("%DEFAULT"))); + content.addAll(Files.readAllLines(ops.get("%FOOTER"))); + } + + System.out.println(" Parsing "+f.getFileName()); + for (int i=0;i0&&isArticleFile(f)) { + //Check for markdown pieces. + if (s.charAt(0)=='-') { + //Start of a title piece. + s=s.replace("-",map.get("$TITLE_CONTENT_START")); + s=s+map.get("$TITLE_CONTENT_END").replace("%ID%","id=\"content_"+i+"\""); + //Use ⤈ if there's more text to be shown than can fit. + } else + if (s.contains("===")) { + s=map.get("$CONTENT_END")+map.get("$DATE_CONTENT_START")+s.replace("===","")+map.get("$CONTENT_END")+"




⤈ Click to expand.
"+map.get("$CONTENT_END"); + } + } + for (String key : map.keySet()) { + s=s.replaceAll(Pattern.quote(key),map.get(key)); + } + content.set(i,s); + } + + System.out.println(" Writing to "+f.toAbsolutePath()); + + Files.write(f, content, Charset.defaultCharset(),StandardOpenOption.CREATE,StandardOpenOption.TRUNCATE_EXISTING,StandardOpenOption.WRITE); + + System.out.println(" "+f.getFileName() + " conversion complete!"); + + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + private static void ConvertArticleReferences(Iterator items) { + while (items.hasNext()) { + Path f = items.next(); + System.out.println(" Looking for Article References..."+f.getFileName()); + if (Files.isRegularFile(f)&&isHTMLFile(f)) { + System.out.println(" Searching "+f.getFileName()); + try { + List content = Files.readAllLines(f); + for (int i=0;i0&&s.contains("$ARTICLE_PREVIEW")) { + String article = s.replace("$ARTICLE_PREVIEW ",""); + System.out.println(" Found article preview request in "+f.getFileName()+" for article "+article+"."); + Path file = Paths.get(OUTDIR,article); + content.remove(i--); + } + } + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } static void copyDirectory(String sourceDirectoryLocation, String destinationDirectoryLocation) throws IOException { Files.walk(Paths.get(sourceDirectoryLocation)) @@ -162,7 +191,7 @@ public class sigPlace { System.out.println(" "+map); for (String key : map.keySet()) { System.out.println("Creating directory listing for "+key+"..."); - StringBuilder sb = new StringBuilder(""); + StringBuilder sb = new StringBuilder(""); List data = Files.readAllLines(ops.get("%DEFAULT")); List data2 = Files.readAllLines(ops.get("%FOOTER")); for (String d : data) { diff --git a/sitefiles/otherpage.html b/sitefiles/otherpage.html index b371084..51c461d 100644 --- a/sitefiles/otherpage.html +++ b/sitefiles/otherpage.html @@ -1,6 +1,6 @@ This is a different webpage.
-$ARTICLE sigplace1 -$ARTICLE test articles/test1 -$ARTICLE test articles/test2 -$ARTICLE test articles/test3 -$ARTICLE curabitur vel tempus ex \ No newline at end of file +$ARTICLE_PREVIEW sigplace1 +$ARTICLE_PREVIEW test articles/test1 +$ARTICLE_PREVIEW test articles/test2 +$ARTICLE_PREVIEW test articles/test3 +$ARTICLE_PREVIEW curabitur vel tempus ex \ No newline at end of file