aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2024-01-12 15:39:59 -0600
committerMichael McVady <femtonaut@gmail.com>2024-01-12 15:39:59 -0600
commitff008cf17716c1b0b4394e9d0b83969e419eb844 (patch)
tree57208a67bfa86829df6c355f9c3dabb5553fd036
parentd0ce4ab8075cc3d14075b66260ecc9d8674dfba7 (diff)
Clean up hardcoded strings
-rw-r--r--README.md3
-rw-r--r--assets/entry_edit.html4
-rw-r--r--assets/footer.html (renamed from assets/index_end.html)0
-rw-r--r--assets/header.html (renamed from assets/index_begin.html)0
-rw-r--r--src/clog.c30
5 files changed, 12 insertions, 25 deletions
diff --git a/README.md b/README.md
index 82bb8d1..876e5ff 100644
--- a/README.md
+++ b/README.md
@@ -40,7 +40,7 @@ Use `psql` and load `db/db.sql` for models,
1. ~Only do HTTP stuff at the edge.~
2. ~`PUT`~/`PATCH`? entries.
-3. pagination
+3. pagination of index ?
4. ~HTML form for edits~
5. ~Make <h1> first class markdown citizen~
6. ~Remove JSON API?~
@@ -50,6 +50,7 @@ Use `psql` and load `db/db.sql` for models,
10. Get rid of `requests` dependency in `tests.py`
11. Fix `PATCH` redirects?
12. Search
+13. Add preview functionality to edit form
## But using C in 2024 is dangerous?
diff --git a/assets/entry_edit.html b/assets/entry_edit.html
index 01e5cd5..9982731 100644
--- a/assets/entry_edit.html
+++ b/assets/entry_edit.html
@@ -3,7 +3,7 @@
<input type="text" id="title" name="title" value="%s" placeholder="title"/>
<textarea id="body" name="body" rows="50" cols="100">%s</textarea>
<br>
-<input type="button" value="Preview">
-<input type="submit" value="Save">
+<!--input type="button" value="Preview"-->
+<input type="submit" value="Update">
</form>
diff --git a/assets/index_end.html b/assets/footer.html
index 6131a40..6131a40 100644
--- a/assets/index_end.html
+++ b/assets/footer.html
diff --git a/assets/index_begin.html b/assets/header.html
index 0ff3660..0ff3660 100644
--- a/assets/index_begin.html
+++ b/assets/header.html
diff --git a/src/clog.c b/src/clog.c
index 6f54d0f..5f41ce5 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -52,9 +52,6 @@ static const char * const error_msg[] = {
[HTTP_STATUS_INTERNAL_ERROR] = "There was an error processing the request.", // 500
};
-// void entry_init();
-// void entry_cleanup();
-
void entry_query_init(struct entry_query *eq, const char *id);
void entry_query_cleanup(struct entry_query *eq);
@@ -71,8 +68,6 @@ int get_entry(struct http_request *req);
int edit_entry(struct http_request *req);
int update_entry(struct http_request *req);
-// int v_example_func(struct http_request *req, char *data);
-
int sql_select(struct entry_query *eq);
int sql_update(const char *id, const char *title, const char *body);
// int sql_delete(const char *id);
@@ -152,9 +147,9 @@ int http_ok_resp(
const char *body = kore_buf_stringify(content, NULL);
http_response_header(req, "content-type", "text/html; charset=utf-8");
- kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html);
+ kore_buf_append(resp_buf, asset_header_html, asset_len_header_html);
kore_buf_append(resp_buf, body, strlen(body));
- kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html);
+ kore_buf_append(resp_buf, asset_footer_html, asset_len_footer_html);
http_response(req, status, resp_buf->data, resp_buf->offset);
@@ -170,9 +165,9 @@ int http_err_resp(
struct kore_buf *resp_buf = kore_buf_alloc(0);
http_response_header(req, "content-type", "text/html; charset=utf-8");
- kore_buf_append(resp_buf, asset_index_begin_html, asset_len_index_begin_html);
+ kore_buf_append(resp_buf, asset_header_html, asset_len_header_html);
kore_buf_appendf(resp_buf, (const char *) asset_error_html, error_msg[status]);
- kore_buf_append(resp_buf, asset_index_end_html, asset_len_index_end_html);
+ kore_buf_append(resp_buf, asset_footer_html, asset_len_footer_html);
http_response(req, status, resp_buf->data, resp_buf->offset);
@@ -205,29 +200,21 @@ int get_index(struct http_request *req) {
}
// Write table header.
- kore_buf_append(
- content,
- (const char *) "<h1>clog.bunkergate.org</h1>\r\n<table><tr><th>title</th><th>created</th><th>updated</th></tr>\r\n",
- 94
- );
+ kore_buf_append(content, asset_index_header_html, asset_len_index_header_html);
// Iterate over entries and render them.
for (row = 0; row < eq.num_entries; row++) {
// Append rendered MD entry.
kore_buf_appendf(
content,
- (const char *) "<tr><td><a href=\"/entries/%s\">%s</a></td><td>%s</td><td>%s</td></tr>\r\n",
+ (const char *) asset_index_row_html,
eq.entries[row]->id, eq.entries[row]->title, eq.entries[row]->created_at, eq.entries[row]->updated_at
);
-
}
// Write table footer.
- kore_buf_append(
- content,
- (const char *) "</table>\r\n",
- 10
- );
+ kore_buf_append(content, asset_index_footer_html, asset_len_index_footer_html);
+
http_ok_resp(req, HTTP_STATUS_OK, content);
@@ -403,7 +390,6 @@ int update_entry(struct http_request *req) {
}
err = sql_update(id, title, body);
- // err = KORE_RESULT_ERROR;
if (err == KORE_RESULT_ERROR) {
kore_log(LOG_ERR, "Error updating entry id %s.", id);
http_err_resp(req, HTTP_STATUS_INTERNAL_ERROR);