Allow tags in post template, Fix blog index
This commit is contained in:
parent
4db5029118
commit
636edfb44c
@ -12,6 +12,7 @@ import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Objects;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
@ -163,6 +164,7 @@ public class MdBlog {
|
||||
})
|
||||
.collect(Collectors.joining(", ")));
|
||||
})
|
||||
.filter(Objects::nonNull)
|
||||
.collect(Collectors.joining("\n\n")));
|
||||
|
||||
index.getBodyNode().appendChild(new MdRenderer().render(MdParser.parse(indexMd)));
|
||||
@ -244,8 +246,6 @@ public class MdBlog {
|
||||
System.out.println("Update");
|
||||
indexTemplates.clear();
|
||||
|
||||
System.out.println(posts);
|
||||
|
||||
Files.walk(POSTS_PATH)
|
||||
.filter(Files::isRegularFile)
|
||||
.filter(f -> f.getFileName().toString().endsWith(Post.FILE_EXTENSION))
|
||||
|
@ -3,30 +3,31 @@ package me.mrletsplay.mdblog.blog;
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Path;
|
||||
import java.security.MessageDigest;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import me.mrletsplay.mdblog.markdown.MdParser;
|
||||
import me.mrletsplay.mdblog.markdown.MdRenderer;
|
||||
import me.mrletsplay.mdblog.template.Template;
|
||||
import me.mrletsplay.mdblog.template.Templates;
|
||||
import me.mrletsplay.mdblog.util.TimeFormatter;
|
||||
import me.mrletsplay.mrcore.http.HttpUtils;
|
||||
import me.mrletsplay.simplehttpserver.dom.html.HtmlDocument;
|
||||
import me.mrletsplay.simplehttpserver.dom.html.HtmlElement;
|
||||
|
||||
public class Post {
|
||||
|
||||
public static final String FILE_EXTENSION = ".md";
|
||||
|
||||
private static final MessageDigest MD_5;
|
||||
//private static final MessageDigest MD_5;
|
||||
private static final MdRenderer RENDERER = new MdRenderer();
|
||||
|
||||
static {
|
||||
try {
|
||||
MD_5 = MessageDigest.getInstance("MD5");
|
||||
} catch (NoSuchAlgorithmException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
// static {
|
||||
// try {
|
||||
// MD_5 = MessageDigest.getInstance("MD5");
|
||||
// } catch (NoSuchAlgorithmException e) {
|
||||
// throw new RuntimeException(e);
|
||||
// }
|
||||
// }
|
||||
|
||||
private Path filePath;
|
||||
// private String checksum; TODO currently unused, post also needs to update when templates change
|
||||
@ -61,15 +62,25 @@ public class Post {
|
||||
|
||||
this.metadata = PostMetadata.load(spl[0]);
|
||||
|
||||
HtmlDocument document = new HtmlDocument();
|
||||
document.getBodyNode().appendChild(RENDERER.render(MdParser.parse(templates.render(Template.POST,
|
||||
String postMd = templates.render(Template.POST,
|
||||
"content", spl[1],
|
||||
"title", metadata.title(),
|
||||
"author", metadata.author(),
|
||||
"description", metadata.description(),
|
||||
"date", TimeFormatter.toDateOnly(metadata.date()),
|
||||
"date_time", TimeFormatter.toDateAndTime(metadata.date()),
|
||||
"date_relative", TimeFormatter.toRelativeTime(metadata.date())))));
|
||||
"date_relative", TimeFormatter.toRelativeTime(metadata.date()),
|
||||
"tags", metadata.tags().stream()
|
||||
.map(t -> {
|
||||
HtmlElement link = new HtmlElement("a");
|
||||
link.setText(t);
|
||||
link.setAttribute("href", "./?tag=" + HttpUtils.urlEncode(t));
|
||||
return link.toString();
|
||||
})
|
||||
.collect(Collectors.joining(", ")));
|
||||
|
||||
HtmlDocument document = new HtmlDocument();
|
||||
document.getBodyNode().appendChild(RENDERER.render(MdParser.parse(postMd)));
|
||||
document.setTitle(metadata.title());
|
||||
document.setDescription(metadata.description());
|
||||
document.addStyleSheet("_/style/base.css");
|
||||
|
Loading…
Reference in New Issue
Block a user