-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Thorsten Marx
committed
Dec 3, 2023
1 parent
08f3569
commit 8c72757
Showing
20 changed files
with
181 additions
and
148 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
cms-api/src/main/java/com/github/thmarx/cms/api/db/ContentNode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package com.github.thmarx.cms.api.db; | ||
|
||
import com.github.thmarx.cms.api.Constants; | ||
import com.github.thmarx.cms.api.PreviewContext; | ||
import com.github.thmarx.cms.api.utils.SectionUtil; | ||
import java.time.Instant; | ||
import java.util.Date; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
/** | ||
* | ||
* @author t.marx | ||
*/ | ||
public record ContentNode(String uri, String name, Map<String, Object> data, | ||
boolean directory, Map<String, ContentNode> children) { | ||
|
||
public ContentNode(String uri, String name, Map<String, Object> data, boolean directory) { | ||
this(uri, name, data, directory, new HashMap<String, ContentNode>()); | ||
} | ||
|
||
public ContentNode(String uri, String name, Map<String, Object> data) { | ||
this(uri, name, data, false, new HashMap<String, ContentNode>()); | ||
} | ||
|
||
public boolean isDirectory() { | ||
return directory; | ||
} | ||
|
||
public boolean isHidden() { | ||
return name.startsWith("."); | ||
} | ||
|
||
public boolean isDraft() { | ||
return (boolean) data().getOrDefault(Constants.MetaFields.DRAFT, false); | ||
} | ||
|
||
public boolean isPublished() { | ||
if (PreviewContext.IS_PREVIEW.get()) { | ||
return true; | ||
} | ||
var localDate = (Date) data.getOrDefault(Constants.MetaFields.PUBLISHED, Date.from(Instant.now())); | ||
var now = Date.from(Instant.now()); | ||
return !isDraft() && (localDate.before(now) || localDate.equals(now)); | ||
} | ||
|
||
public boolean isSection() { | ||
return SectionUtil.isSection(name); | ||
} | ||
|
||
@Override | ||
public boolean equals (Object other) { | ||
|
||
if (this == other) { | ||
return true; | ||
} | ||
|
||
if (other == null) { | ||
return false; | ||
} | ||
|
||
if (!(other instanceof ContentNode)) { | ||
return false; | ||
} | ||
|
||
var otherNode = (ContentNode)other; | ||
|
||
return uri.equals(otherNode.uri); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.