From b6fb184b0544d4916ab24b6beb480472e4fa7101 Mon Sep 17 00:00:00 2001 From: Minecon724 Date: Mon, 10 Mar 2025 17:55:19 +0100 Subject: [PATCH] Improve Article class and add 'hidden' property Signed-off-by: Minecon724 --- .../java/eu/m724/blog/object/Article.java | 34 +++++-------------- 1 file changed, 8 insertions(+), 26 deletions(-) diff --git a/src/main/java/eu/m724/blog/object/Article.java b/src/main/java/eu/m724/blog/object/Article.java index d43a75a..3303762 100644 --- a/src/main/java/eu/m724/blog/object/Article.java +++ b/src/main/java/eu/m724/blog/object/Article.java @@ -30,7 +30,7 @@ import java.util.Map; * @param createdAt The timestamp of when the article was first created. * @param modifiedBy The name of the author who last modified the article. * @param modifiedAt The timestamp of the last modification to the article. - * @param custom A map of custom properties or metadata associated with the article. + * @param custom Map of raw properties, including those that aren't represented with a property * @param rawContent The raw content of the article, which currently is usually HTML. */ public record Article( @@ -38,6 +38,7 @@ public record Article( String title, String summary, boolean draft, + boolean hidden, int revisions, String createdBy, @@ -85,31 +86,12 @@ public record Article( var content = String.join("\n", lines).strip(); - /* filter properties from read file */ + /* read properties */ - String title = "NO TITLE SET"; - String summary = "NO SUMMARY SET"; - boolean draft = true; - - var custom = new HashMap(); - - for (Map.Entry property : properties.entrySet()) { - var value = property.getValue(); - - switch (property.getKey()) { - case "title": - title = value; - break; - case "summary": - summary = value; - break; - case "live": // an article is live (not draft) if the key is there - draft = false; - break; - default: - custom.put(property.getKey(), value); - } - } + String title = properties.getOrDefault("title", "NO TITLE SET"); + String summary = properties.getOrDefault("summary", "NO SUMMARY SET"); // TODO maybe it's not always needed? + boolean draft = !properties.containsKey("live"); + boolean hidden = properties.containsKey("hidden"); /* get revisions */ @@ -134,6 +116,6 @@ public record Article( LOGGER.warn("[Article {}] Draft because of a VC exception: {}", slug, e.getMessage()); } - return new Article(slug, title, summary, draft, revisions, createdBy, createdAt, modifiedBy, modifiedAt, custom, content); + return new Article(slug, title, summary, draft, hidden, revisions, createdBy, createdAt, modifiedBy, modifiedAt, properties, content); } }