aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael McVady <femtonaut@gmail.com>2024-01-13 15:56:36 -0600
committerMichael McVady <femtonaut@gmail.com>2024-01-13 15:56:36 -0600
commitef7cd622768b9dfe99ad18b7af5bd0e328b4d503 (patch)
treed46505f75b2d5831e16074470c42135b8ae05d22
parent53e31bbbd4e77ff08d697d1a848bccf044172432 (diff)
Add message for no search results
-rw-r--r--assets/search.html4
-rw-r--r--assets/static/css/retro.css9
-rw-r--r--src/clog.c60
3 files changed, 37 insertions, 36 deletions
diff --git a/assets/search.html b/assets/search.html
index 28a93c3..6bc98b6 100644
--- a/assets/search.html
+++ b/assets/search.html
@@ -1,4 +1,6 @@
<form>
- <input type="search" id="query" name="query" placeholder="Search...">
+ <input type="search" id="query" name="query" placeholder="Search..." value="%s">
<button>Search</button>
</form>
+
+<hr>
diff --git a/assets/static/css/retro.css b/assets/static/css/retro.css
index c8f671b..ec715d1 100644
--- a/assets/static/css/retro.css
+++ b/assets/static/css/retro.css
@@ -204,14 +204,15 @@ blockquote {
}
table :is(td, th) {
+ width: 100%;
border: 1px solid #999;
padding: 0.3em;
}
-/* tr:nth-child(even) {
- background-color: rgb(3, 192, 255);
+tr:nth-child(even) {
+ background-color: #222;
}
tr:nth-child(odd) {
- background-color: rgb(7, 99, 7);
-} */
+ background-color: #333;
+}
diff --git a/src/clog.c b/src/clog.c
index c018565..4c65a33 100644
--- a/src/clog.c
+++ b/src/clog.c
@@ -167,12 +167,13 @@ int validate_text(struct http_request *req, char *data) {
}
int http_ok_resp(
- struct http_request *req,
- enum http_status_code status,
- struct kore_buf *content
+ struct http_request *req, enum http_status_code status, struct kore_buf *content
) {
- struct kore_buf *resp_buf = kore_buf_alloc(0);
- const char *body = kore_buf_stringify(content, NULL);
+ struct kore_buf *resp_buf = NULL;
+ const char *body = NULL;
+
+ resp_buf = kore_buf_alloc(0);
+ body = kore_buf_stringify(content, NULL);
http_response_header(req, "content-type", "text/html; charset=utf-8");
kore_buf_append(resp_buf, asset_html_header_html, asset_len_html_header_html);
@@ -186,11 +187,10 @@ int http_ok_resp(
return KORE_RESULT_OK;
}
-int http_err_resp(
- struct http_request *req,
- enum http_status_code status
-) {
- struct kore_buf *resp_buf = kore_buf_alloc(0);
+int http_err_resp(struct http_request *req, enum http_status_code status) {
+ struct kore_buf *resp_buf = NULL;
+
+ resp_buf = kore_buf_alloc(0);
http_response_header(req, "content-type", "text/html; charset=utf-8");
kore_buf_append(resp_buf, asset_html_header_html, asset_len_html_header_html);
@@ -241,31 +241,30 @@ int get_index(struct http_request *req) {
kore_buf_append(content, asset_header_html, asset_len_header_html);
// Write search form.
- kore_buf_append(content, asset_search_html, asset_len_search_html);
+ kore_buf_appendf(content, (const char *) asset_search_html, query ? query : "");
- // Write table header.
- kore_buf_append(content, asset_table_header_html, asset_len_table_header_html);
-
- // Iterate over entries and render them.
- for (i = 0; i < eq.num_entries; i++) {
- // Append rendered MD entry.
- kore_buf_appendf(
- content,
- (const char *) asset_table_row_html,
- eq.entries[i]->id, eq.entries[i]->title, eq.entries[i]->created_at, eq.entries[i]->updated_at
- );
+ if (eq.num_entries == 0 && query) {
+ kore_buf_appendf(content, (const char *) asset_error_html, "No results found.");
}
-
- // Write table footer.
- kore_buf_append(content, asset_table_footer_html, asset_len_table_footer_html);
-
-
+ else {
+ kore_buf_append(content, asset_table_header_html, asset_len_table_header_html);
+ // Iterate over entries and render them.
+ for (i = 0; i < eq.num_entries; i++) {
+ // Append rendered MD entry.
+ kore_buf_appendf(
+ content,
+ (const char *) asset_table_row_html,
+ eq.entries[i]->id, eq.entries[i]->title, eq.entries[i]->created_at, eq.entries[i]->updated_at
+ );
+ }
+ kore_buf_append(content, asset_table_footer_html, asset_len_table_footer_html);
+ }
+
http_ok_resp(req, HTTP_STATUS_OK, content);
out: ;
kore_free(content);
-
entry_query_cleanup(&eq);
return KORE_RESULT_OK;
@@ -331,12 +330,11 @@ out: ;
int edit_entry(struct http_request *req) {
int err = 0;
+ char *id = NULL;
struct entry_query eq;
struct kore_buf *content = NULL;
struct kore_buf *rendered_body = NULL;
-
- char *id = NULL;
-
+
content = kore_buf_alloc(0);
rendered_body = kore_buf_alloc(0);