about summary refs log tree commit diff
path: root/templates
diff options
context:
space:
mode:
authorsternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-08-24 19:59:49 +0200
committersternenseemann <0rpkxez4ksa01gb3typccl0i@systemli.org>2020-08-24 20:12:29 +0200
commit5d4cf98ad932666857841c986aef01eadd22fd0f (patch)
tree55b50c17ffced14bcbafe22a58d7912b25a96111 /templates
parent34c00ef36a5c250618f283c6a2a150fb0a694352 (diff)
feat(main): add atom feed
feat(templates/simple.c): link to atom feed as well
refactor(templates/simple.c): replace make_link with catn_alloc
Diffstat (limited to 'templates')
-rw-r--r--templates/simple.c51
1 files changed, 19 insertions, 32 deletions
diff --git a/templates/simple.c b/templates/simple.c
index 06d69e8..eeee6db 100644
--- a/templates/simple.c
+++ b/templates/simple.c
@@ -7,40 +7,12 @@
 #include <template.h>
 #include <config.h>
 #include <cgiutil.h>
+#include <stringutil.h>
 #include <timeutil.h>
 #include <xml.h>
 
 static struct xml_context ctx;
 
-int make_link(char *buf, size_t size, char *abs_path) {
-    // TODO pass to template somehow?
-    char *script_name = getenv("SCRIPT_NAME");
-
-    if(script_name == NULL || buf == NULL || abs_path == NULL) {
-        return -1;
-    }
-
-    size_t script_name_len = strlen(script_name);
-    size_t abs_path_len = strlen(abs_path);
-
-    size_t min_buf_len = script_name_len + abs_path_len + 1;
-
-    if(min_buf_len > size) {
-        return -1;
-    }
-
-    if(script_name_len > 0) {
-        memcpy(buf, script_name, script_name_len);
-    }
-    if(abs_path_len > 0) {
-        memcpy(buf + script_name_len, abs_path, abs_path_len);
-    }
-
-    buf[script_name_len + abs_path_len] = '\0';
-
-    return min_buf_len;
-}
-
 void output_entry_time(struct xml_context *ctx, struct entry entry) {
     char strtime[MAX_TIMESTR_SIZE];
 
@@ -90,11 +62,26 @@ void template_footer(void) {
 
     xml_open_tag(&ctx, "footer");
 
-    char rss_link[256];
-    if(make_link(rss_link, sizeof rss_link, "/rss.xml") != -1) {
+    char *script_name = getenv("SCRIPT_NAME");
+    char *rss_link = catn_alloc(2, script_name, "/rss.xml");
+    char *atom_link = catn_alloc(2, script_name, "/atom.xml");
+
+    if(rss_link != NULL) {
         xml_open_tag_attrs(&ctx, "a", 1, "href", rss_link);
-        xml_raw(&ctx, "RSS Feed");
+        xml_escaped(&ctx, "RSS Feed");
         xml_close_tag(&ctx, "a");
+
+        free(rss_link);
+    }
+
+    if(atom_link != NULL) {
+        xml_raw(&ctx, " &bull; ");
+
+        xml_open_tag_attrs(&ctx, "a", 1, "href", atom_link);
+        xml_escaped(&ctx, "Atom Feed");
+        xml_close_tag(&ctx, "a");
+
+        free(atom_link);
     }
 
     xml_close_all(&ctx);