Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion blog/BlogLogger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
66 changes: 57 additions & 9 deletions blog/DealFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public void search() throws IOException {
File[] types = file.listFiles();
List<PostFile> 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();
// 每一篇文章
Expand Down Expand Up @@ -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!*********************");
}

Expand Down Expand Up @@ -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;
}
}
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -271,7 +274,6 @@ private void dealFile(String path, String html) {
}

public void makeIndexHtml() {
makeDir(classPath + "WebContent/post");
String indexHtml = "";
indexHtml += "<!doctype html>\n" + "<html>" + GenHtml.getHead();
// 开始 body
Expand Down Expand Up @@ -306,8 +308,15 @@ public void makeIndexHtml() {
cntp++;

}
indexHtml += " }" + "</script>" + GenHtml.getIndexBody();
indexHtml += " }" + "</script>" ;

String indexBody = GenHtml.getIndexBody();
Matcher matcher = Pattern.compile("</body>").matcher(indexBody);
if (matcher.find()){
indexHtml += indexBody.substring(0,matcher.start());
}
indexHtml += "<div id='write' class='is-node'><p onclick='window.open(\"allblogs.html\")'><strong><span >文章列表</span></strong></p></div>";
indexHtml += indexBody.substring(matcher.start(),matcher.end());
indexHtml = indexHtml.trim();
try {
BufferedWriter br = new BufferedWriter(new FileWriter(classPath + "WebContent/index.html"));
Expand All @@ -321,4 +330,43 @@ public void makeIndexHtml() {
}


private void makeAllBlogs() {
String indexHtml = "";
indexHtml += "<!doctype html>\n" + "<html>" + GenHtml.getHead();
// 开始 body
indexHtml += "<body class='typora-export os-windows'>";
indexHtml += "<div id='write' class = 'is-node'>";

int cntp = 1;
int cnt = 0;
for (String i : this.getTypes()) {
if (dataBasa.get(cntp) != null) {
int cntpp = 1;
for (Pair<String, String> d : dataBasa.get(cntp)) {
indexHtml += " <p onclick='window.open(\"post/dir" + (cntp + "/file" + cntpp++ + ".html") + "\")'><strong><span >" + cnt++ +" - "+ d.getKey().split("-")[1] + "</span></strong></p>" + " <hr/>" + " <p><span>";
indexHtml += d.getValue().length() > 200 ? d.getValue().substring(0, 200) : d.getValue();
indexHtml += "+ </span>" + "</p>" + "<p>&nbsp;</p> \n ";
}
}
cntp++;

}
//生成页尾
indexHtml += " <p><span>@Author: Firefly</span></p>" + " </div> ;";
indexHtml += "</body></html>";
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());
}

}


}
23 changes: 14 additions & 9 deletions blog/GenHtml.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 = "";
Expand All @@ -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("<body.*?>").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;
}
Expand Down