From 11170ec187cf82fe8b983390ff20b1ed9957157a Mon Sep 17 00:00:00 2001 From: firefly <531109985@qq.com> Date: Thu, 13 Feb 2020 14:37:47 +0800 Subject: [PATCH] update --- blog/BlogLogger.java | 2 +- blog/DealFile.java | 66 ++++++++++++++++++++++++++++++++++++++------ blog/GenHtml.java | 23 +++++++++------ 3 files changed, 72 insertions(+), 19 deletions(-) diff --git a/blog/BlogLogger.java b/blog/BlogLogger.java index d676a1a..fe730a6 100644 --- a/blog/BlogLogger.java +++ b/blog/BlogLogger.java @@ -11,7 +11,7 @@ public class BlogLogger { private String info = ""; public void log(String info) { - this.info += (info + "\n"); + this.info += (info + "\r\n"); } public String getInfo() { diff --git a/blog/DealFile.java b/blog/DealFile.java index bf6f69a..3a0ee57 100644 --- a/blog/DealFile.java +++ b/blog/DealFile.java @@ -41,8 +41,8 @@ public void search() throws IOException { File[] types = file.listFiles(); List temp = new ArrayList<>(); // 每一分类 - for (File type : types) { - if (type.isDirectory()) { + for (File type : types ) { + if (type.isDirectory() && !type.getName().contentEquals(".git")) { PostFile temp_type = new PostFile(type.getName(), true); File[] contents = new File(type.getPath()).listFiles(); // 每一篇文章 @@ -82,6 +82,8 @@ public static void main(String[] args) { file.deaLFiles(); System.out.println("*********************make the index.html*********************"); file.makeIndexHtml(); + System.out.println("*********************make the allblogs.html*********************"); + file.makeAllBlogs(); System.out.println("*********************deal over!*********************"); } @@ -178,11 +180,11 @@ private void add2Database(int fileIndex, String fname, String info) { // dealInfo = dealInfo.replace(dealInfo.substring(matcher.start(), matcher.end()), " "); // } - while(true){ + while (true) { matcher = Pattern.compile("<.{0,200}?>").matcher(dealInfo); - if(matcher.find() && matcher.end() < dealInfo.length()){ - dealInfo = dealInfo.replace(dealInfo.substring(matcher.start(), matcher.end()), ""); - }else { + if (matcher.find() && matcher.end() < dealInfo.length()) { + dealInfo = dealInfo.replace(dealInfo.substring(matcher.start(), matcher.end()), ""); + } else { break; } } @@ -218,7 +220,8 @@ public String devBlog() { logger.log("\n\n\n*********************make the index.html*********************"); makeIndexHtml(); logger.log("\n\n\n*********************deal over!*********************"); - + makeAllBlogs(); + logger.log("*********************make the allblogs.html*********************"); return logger.getInfo(); } @@ -271,7 +274,6 @@ private void dealFile(String path, String html) { } public void makeIndexHtml() { - makeDir(classPath + "WebContent/post"); String indexHtml = ""; indexHtml += "\n" + "" + GenHtml.getHead(); // 开始 body @@ -306,8 +308,15 @@ public void makeIndexHtml() { cntp++; } - indexHtml += " }" + "" + GenHtml.getIndexBody(); + indexHtml += " }" + "" ; + String indexBody = GenHtml.getIndexBody(); + Matcher matcher = Pattern.compile("").matcher(indexBody); + if (matcher.find()){ + indexHtml += indexBody.substring(0,matcher.start()); + } + indexHtml += "

文章列表

"; + indexHtml += indexBody.substring(matcher.start(),matcher.end()); indexHtml = indexHtml.trim(); try { BufferedWriter br = new BufferedWriter(new FileWriter(classPath + "WebContent/index.html")); @@ -321,4 +330,43 @@ public void makeIndexHtml() { } + private void makeAllBlogs() { + String indexHtml = ""; + indexHtml += "\n" + "" + GenHtml.getHead(); + // 开始 body + indexHtml += ""; + indexHtml += "
"; + + int cntp = 1; + int cnt = 0; + for (String i : this.getTypes()) { + if (dataBasa.get(cntp) != null) { + int cntpp = 1; + for (Pair d : dataBasa.get(cntp)) { + indexHtml += "

" + cnt++ +" - "+ d.getKey().split("-")[1] + "

" + "
" + "

"; + indexHtml += d.getValue().length() > 200 ? d.getValue().substring(0, 200) : d.getValue(); + indexHtml += "+ " + "

" + "

 

\n "; + } + } + cntp++; + + } + //生成页尾 + indexHtml += "

@Author: Firefly

" + "
;"; + indexHtml += ""; + indexHtml = indexHtml.trim(); + indexHtml = indexHtml.replace("\n",""); + try { + BufferedWriter br = new BufferedWriter(new FileWriter(classPath + "WebContent/allblogs.html")); + br.write(indexHtml); + br.flush(); + logger.log("Gen allblogs.html success!!"); + br.close(); + } catch (Exception e) { + logger.log(e.toString()); + } + + } + + } diff --git a/blog/GenHtml.java b/blog/GenHtml.java index 414d212..c59d786 100644 --- a/blog/GenHtml.java +++ b/blog/GenHtml.java @@ -16,11 +16,9 @@ public class GenHtml { private static String head = ""; private static String head1 = ""; private static String leftjs = ""; - private static String indexBody = ""; - + private static String path = GenHtml.class.getClassLoader().getResource("").getPath(); GenHtml() { - String path = GenHtml.class.getClassLoader().getResource("").getPath(); try { BufferedReader br = new BufferedReader(new FileReader(path + "blog/source/head.html")); String temp = ""; @@ -41,22 +39,29 @@ public class GenHtml { } br.close(); - br = new BufferedReader(new FileReader(path + "blog/post/index.html")); + } catch (Exception e) { + System.out.println(e); + } + } + + public static String getIndexBody() { + + String indexBody = ""; + String temp = ""; + try { + BufferedReader br = new BufferedReader(new FileReader(path + "blog/post/index.html")); while ((temp = br.readLine()) != null) { indexBody += temp; } br.close(); - } catch (Exception e) { System.out.println(e); } - } - public static String getIndexBody() { Matcher matcher = Pattern.compile("").matcher(indexBody); if (matcher.find() && matcher.end() < indexBody.length()) { - final String substring = indexBody.substring(matcher.end(), indexBody.length()); - return indexBody; + final String substring = indexBody.substring(matcher.end()); + return substring; } return null; }