diff --git a/src/main/java/com/pawandubey/griffin/DirectoryCrawler.java b/src/main/java/com/pawandubey/griffin/DirectoryCrawler.java index f04997c..66e8f3c 100644 --- a/src/main/java/com/pawandubey/griffin/DirectoryCrawler.java +++ b/src/main/java/com/pawandubey/griffin/DirectoryCrawler.java @@ -18,10 +18,10 @@ import com.moandjiezana.toml.Toml; import static com.pawandubey.griffin.Configurator.LINE_SEPARATOR; import static com.pawandubey.griffin.Data.config; -import static com.pawandubey.griffin.renderer.HandlebarsRenderer.templateRoot; import com.pawandubey.griffin.model.Page; import com.pawandubey.griffin.model.Parsable; import com.pawandubey.griffin.model.Post; +import static com.pawandubey.griffin.renderer.Renderer.templateRoot; import java.io.BufferedReader; import java.io.IOException; import java.nio.charset.StandardCharsets; @@ -168,14 +168,14 @@ public FileVisitResult visitFile(Path file, BasicFileAttributes attrs) throws IO LocalDateTime fileModified = LocalDateTime.ofInstant(Files.getLastModifiedTime(file).toInstant(), ZoneId.systemDefault()); LocalDateTime lastParse = LocalDateTime.parse(InfoHandler.LAST_PARSE_DATE, InfoHandler.formatter); Path resolvedPath = Paths.get(OUTPUT_DIRECTORY).resolve(rootPath.relativize(file)); - if (fileModified.isAfter(lastParse)) { - if (Files.probeContentType(file).equals("text/x-markdown")) { + if (Files.probeContentType(file).equals("text/x-markdown")) { + if (fileModified.isAfter(lastParse)) { Parsable parsable = createParsable(file); Data.fileQueue.put(parsable); } - else { - Files.copy(file, resolvedPath, StandardCopyOption.REPLACE_EXISTING); - } + } + else { + Files.copy(file, resolvedPath, StandardCopyOption.REPLACE_EXISTING); } } diff --git a/src/main/java/com/pawandubey/griffin/Parser.java b/src/main/java/com/pawandubey/griffin/Parser.java index 54a90a2..0ed53c9 100644 --- a/src/main/java/com/pawandubey/griffin/Parser.java +++ b/src/main/java/com/pawandubey/griffin/Parser.java @@ -169,7 +169,11 @@ private void renderIndexRssAnd404() throws IOException { */ protected void renderTags() throws IOException { if (config.getRenderTags()) { - //System.out.println(tags.get("code").size()); + for (List l : tags.values()) { + l.sort((s, t) -> { + return t.getDate().compareTo(s.getDate()); + }); + } int numThreads = (tags.size() / 10) + 1; ExecutorService tagExecutor = Executors.newFixedThreadPool(numThreads); executorSet.add(tagExecutor); @@ -197,8 +201,8 @@ protected void renderTags() throws IOException { } } - List parsables = tags.get(a); - + List parsables = tags.get(a); + for (Parsable p : parsables) { Path slugPath = tagDir.resolve(p.getSlug()); if (Files.notExists(slugPath)) { @@ -219,9 +223,9 @@ protected void renderTags() throws IOException { } } } + if (lock.tryLock()) { - try (BufferedWriter bw = Files.newBufferedWriter(tagDir.resolve("index.html"), StandardCharsets.UTF_8)) { - //System.out.println(a + " : " + tags.get(a)); + try (BufferedWriter bw = Files.newBufferedWriter(tagDir.resolve("index.html"), StandardCharsets.UTF_8)) { bw.write(renderer.renderTagIndex(a, parsables)); } catch (IOException ex) { @@ -291,7 +295,7 @@ private String readFile(Path p) { private void writeParsedFile(Parsable p) throws IOException { Path htmlPath = resolveHtmlPath(p); - if (config.getRenderTags()) { + if (config.getRenderTags() && p instanceof Post) { resolveTags(p, htmlPath); }