Fix sub-blog and post sorting

This commit is contained in:
MrLetsplay 2024-02-17 21:25:12 +01:00
parent 636edfb44c
commit 867c972988
Signed by: mr
SSH Key Fingerprint: SHA256:92jBH80vpXyaZHjaIl47pjRq+Yt7XGTArqQg1V7hSqg

View File

@ -6,8 +6,10 @@ import java.nio.file.Path;
import java.nio.file.StandardWatchEventKinds; import java.nio.file.StandardWatchEventKinds;
import java.nio.file.WatchKey; import java.nio.file.WatchKey;
import java.nio.file.WatchService; import java.nio.file.WatchService;
import java.time.Instant;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
@ -130,6 +132,7 @@ public class MdBlog {
String indexMd = templates.render(Template.INDEX, String indexMd = templates.render(Template.INDEX,
"name", blogName, "name", blogName,
"sub_blogs", directories.stream() "sub_blogs", directories.stream()
.sorted(Comparator.comparing(p -> p.getName()))
.map(p -> { .map(p -> {
HtmlElement name = new HtmlElement("a"); HtmlElement name = new HtmlElement("a");
name.setAttribute("href", p.toString()); name.setAttribute("href", p.toString());
@ -139,8 +142,9 @@ public class MdBlog {
}) })
.collect(Collectors.joining("\n\n")), .collect(Collectors.joining("\n\n")),
"posts", postsInDir.stream() "posts", postsInDir.stream()
.sorted(Comparator.<PostPath, Instant>comparing(p -> posts.get(path.concat(p)).getMetadata().date()).reversed())
.map(p -> { .map(p -> {
Post post = posts.get(path == null ? p : path.concat(p)); Post post = posts.get(path.concat(p));
PostMetadata meta = post.getMetadata(); PostMetadata meta = post.getMetadata();
if(tag != null && !meta.tags().contains(tag)) return null; if(tag != null && !meta.tags().contains(tag)) return null;