From ac3493bfa89fca547e574ee630bd5e4f3ab3c8f9 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Mon, 10 Mar 2025 18:11:23 +0100 Subject: [PATCH] Implement hidden article Signed-off-by: Minecon724 --- src/main/java/eu/m724/blog/BlogBuilder.java | 5 ++++- .../m724/blog/template/TemplateExtension.java | 20 ++++++++++++++++++- 2 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/main/java/eu/m724/blog/BlogBuilder.java b/src/main/java/eu/m724/blog/BlogBuilder.java index c5dac9b..ef1f98a 100644 --- a/src/main/java/eu/m724/blog/BlogBuilder.java +++ b/src/main/java/eu/m724/blog/BlogBuilder.java @@ -205,7 +205,10 @@ public class BlogBuilder { } catch (FileAlreadyExistsException ignored) { } Files.writeString(outFile, render); - articles.add(article); + + // TODO Is this the right way? To just ignore hidden? Right now it doesn't matter, but in the future? + if (!article.hidden()) + articles.add(article); } } diff --git a/src/main/java/eu/m724/blog/template/TemplateExtension.java b/src/main/java/eu/m724/blog/template/TemplateExtension.java index 2130623..20ed933 100644 --- a/src/main/java/eu/m724/blog/template/TemplateExtension.java +++ b/src/main/java/eu/m724/blog/template/TemplateExtension.java @@ -61,10 +61,28 @@ public class TemplateExtension extends AbstractExtension { path = CacheBuster.insertHashInPath(path, hash); } + return site.directory() + path; + } + }, + "url_for", new Function() { + @Override + public List getArgumentNames() { + return List.of("path"); + } + + @Override + public Object execute(Map args, PebbleTemplate self, EvaluationContext context, int lineNumber) { + var path = args.get("path").toString(); + + if (path.startsWith("/")) { + path = path.substring(1); + } else { + // TODO Should we apply special treatment? Relative path? + } + return site.directory() + path; } } - // TODO make url_for that supports relative and absolute paths ); }