diff options
author | Jakob Kaivo <jkk@ung.org> | 2019-07-18 20:24:32 -0400 |
---|---|---|
committer | Jakob Kaivo <jkk@ung.org> | 2019-07-18 20:24:32 -0400 |
commit | e77c62e0f9725acca092f718b07555e841372190 (patch) | |
tree | bdeb2cc668e285a873bb1594d53b6649262dac6d /blog.c | |
parent | 16714b9d818c059605667fa7f589e6e9f6593833 (diff) |
trime whitespace from title, avoid duplicate hyphens in URI
Diffstat (limited to 'blog.c')
-rw-r--r-- | blog.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -49,11 +49,26 @@ int handle_post(void) mkdirat(blogdir, ymd, 0755); char *title = find_post_data("title"); + while (isblank(*title)) { + title++; + } + size_t len = strlen(title); + while (isblank(title[--len])) { + title[len] = '\0'; + } + char uri[FILENAME_MAX] = { 0 }; char *end = stpcpy(uri, ymd); *end++ = '/'; + int dash = 0; for (char *f = title; *f != '\0'; f++) { - *end++ = isalnum(*f) ? tolower(*f) : '-'; + if (isalnum(*f)) { + *end++ = tolower(*f); + dash = 0; + } else if (!dash) { + dash = 1; + *end++ = '-'; + } } int newpost = openat(blogdir, uri, O_WRONLY | O_CREAT, 0644); |