Skip to content

Commit

Permalink
#98 sitemap generator added
Browse files Browse the repository at this point in the history
  • Loading branch information
Thorsten Marx committed Dec 3, 2023
1 parent b1ea159 commit 6811a87
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,18 @@
* @author t.marx
*/
public record ContentNode(String uri, String name, Map<String, Object> data,
boolean directory, Map<String, ContentNode> children) {
boolean directory, Map<String, ContentNode> children, LocalDate lastmodified) {

public ContentNode(String uri, String name, Map<String, Object> data, boolean directory, Map<String, ContentNode> children) {
this(uri, name, data, directory, children, LocalDate.now());
}

public ContentNode(String uri, String name, Map<String, Object> data, boolean directory) {
this(uri, name, data, directory, new HashMap<String, ContentNode>());
this(uri, name, data, directory, new HashMap<String, ContentNode>(), LocalDate.now());
}

public ContentNode(String uri, String name, Map<String, Object> data) {
this(uri, name, data, false, new HashMap<String, ContentNode>());
this(uri, name, data, false, new HashMap<String, ContentNode>(), LocalDate.now());
}

public boolean isDirectory() {
Expand Down
Binary file modified cms-server/modules/seo-module/libs/seo-module-2.14.0.jar
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.io.IOException;
import java.io.OutputStream;
import java.nio.charset.StandardCharsets;
import java.time.format.DateTimeFormatter;
import lombok.RequiredArgsConstructor;

/**
Expand All @@ -49,12 +50,27 @@ public void addNode (final ContentNode node) throws IOException {
output.write("<url>".getBytes(StandardCharsets.UTF_8));
output.write("<loc>%s/%s</loc>".formatted(
siteProperties.getOrDefault("baseurl", ""),
node.uri()
patchURi(node.uri())
).getBytes(StandardCharsets.UTF_8));
output.write("<lastmod></lastmod>".getBytes(StandardCharsets.UTF_8));
output.write("<lastmod>%s</lastmod>"
.formatted(DateTimeFormatter.ISO_LOCAL_DATE.format(node.lastmodified()))
.getBytes(StandardCharsets.UTF_8));
output.write("</url>".getBytes(StandardCharsets.UTF_8));
}

private String patchURi (String uri) {
if (uri.endsWith("index.md")) {
uri = uri.replace("index.md", "");
}
if (uri.endsWith("/")) {
uri = uri.substring(0, uri.lastIndexOf("/"));
}
if (uri.endsWith(".md")) {
uri = uri.substring(0, uri.lastIndexOf("."));
}
return uri;
}

@Override
public void close() throws Exception {
output.write("</urlset>".getBytes(StandardCharsets.UTF_8));
Expand Down

0 comments on commit 6811a87

Please sign in to comment.