changeset 1055:bd0e1b140566

post fmt 2: reintroduce raw html format support This time, however, the implementation is much simpler and the post files use the .html file extension. Signed-off-by: Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
author Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
date Sat, 08 Aug 2020 20:44:28 -0400
parents 9ec759a83693
children 0ed8141471c9
files docs/lisp-metadata.txt post.c
diffstat 2 files changed, 22 insertions(+), 3 deletions(-) [+]
line wrap: on
line diff
--- a/docs/lisp-metadata.txt	Fri Aug 21 08:59:58 2020 -0400
+++ b/docs/lisp-metadata.txt	Sat Aug 08 20:44:28 2020 -0400
@@ -29,6 +29,7 @@
 
    The supported formats are:
 
+     2: raw HTML
      3: pseudo-LaTeX
 
  tags: list of tags associated with this post
--- a/post.c	Fri Aug 21 08:59:58 2020 -0400
+++ b/post.c	Sat Aug 08 20:44:28 2020 -0400
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2009-2019 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
+ * Copyright (c) 2009-2020 Josef 'Jeff' Sipek <jeffpc@josefsipek.net>
  *
  * Permission is hereby granted, free of charge, to any person obtaining a copy
  * of this software and associated documentation files (the "Software"), to deal
@@ -233,6 +233,15 @@
 	val_putref(list);
 }
 
+static int __do_load_post_body_fmt2(struct post *post, struct str *html)
+{
+	str_putref(post->body); /* free the previous */
+	post->body = str_getref(html);
+	ASSERT(post->body);
+
+	return 0;
+}
+
 static int __do_load_post_body_fmt3(struct post *post, const struct str *input)
 {
 	struct parser_output x;
@@ -296,6 +305,7 @@
 static int __load_post_body(struct post *post)
 {
 	static const char *exts[4] = {
+		[2] = "html",
 		[3] = "tex",
 	};
 
@@ -303,7 +313,8 @@
 	struct str *raw;
 	int ret;
 
-	ASSERT3U(post->fmt, ==, 3);
+	ASSERT3U(post->fmt, >=, 2);
+	ASSERT3U(post->fmt, <=, 3);
 
 	snprintf(path, FILENAME_MAX, "%s/posts/%d/post.%s",
 		 str_cstr(config.data_dir), post->id, exts[post->fmt]);
@@ -312,7 +323,14 @@
 	if (IS_ERR(raw))
 		return PTR_ERR(raw);
 
-	ret = __do_load_post_body_fmt3(post, raw);
+	switch (post->fmt) {
+		case 2:
+			ret = __do_load_post_body_fmt2(post, raw);
+			break;
+		case 3:
+			ret = __do_load_post_body_fmt3(post, raw);
+			break;
+	}
 
 	str_putref(raw);