commit eb9ac98982fafada622d81511fe981c4bf21a3ad
parent 305ff08d9b5d328f1bc540dc57848c19e0174428
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Thu, 21 Mar 2024 11:17:59 -0700
Add 'active' class to current page link in tk_header
This allows css selection of the link to the current page to mark
it visually in some way.
Diffstat:
1 file changed, 9 insertions(+), 2 deletions(-)
diff --git a/html.c b/html.c
@@ -27,8 +27,15 @@ htmllink(struct pagedata *pd, char *link, char *text)
{
enum kcgi_err status;
- if ((status = khtml_attr(&pd->html, KELEM_A,
- KATTR_HREF, link, KATTR__MAX)) != KCGI_OK ||
+ if (strcmp(link, pd->pages[pd->req.page]) == 0) {
+ status = khtml_attr(&pd->html, KELEM_A,
+ KATTR_HREF, link, KATTR_CLASS, "active", KATTR__MAX);
+ } else {
+ status = khtml_attr(&pd->html, KELEM_A,
+ KATTR_HREF, link, KATTR__MAX);
+ }
+
+ if (status != KCGI_OK ||
(status = khtml_puts(&pd->html, text)) != KCGI_OK ||
(status = khtml_closeelem(&pd->html, 1)) != KCGI_OK)
return status;