website

website.git
git clone git://git.lenczewski.org/website.git
Log | Files | Refs

commit 95e5221ecf69b617af8ba959fa6ccaf01cb4e7ea
parent 9070fddd10448ed35fadde4078469b2522a46319
Author: MikoĊ‚aj Lenczewski <mblenczewski@gmail.com>
Date:   Fri, 21 Feb 2025 17:25:14 +0000

Add better title naming

Diffstat:
M.gitignore | 3+++
Mdate.sh | 8++++----
Msrc/blog/cdoku.html | 2--
Asrc/blog/cdoku.html.title.meta | 1+
Msrc/blog/clfs.html | 2--
Asrc/blog/clfs.html.title.meta | 1+
Msrc/blog/pyecs.html | 2--
Asrc/blog/pyecs.html.title.meta | 1+
Msrc/blog/test.html | 2+-
Asrc/blog/test.html.title.meta | 1+
Msrc/css/style.css | 2+-
Msrc/templates/blogpost.html | 2++
Mtools/template.c | 38++++++++++++++++++++++++++++++--------
Mtools/utils.h | 14+++++++-------
14 files changed, 52 insertions(+), 27 deletions(-)

diff --git a/.gitignore b/.gitignore @@ -5,6 +5,9 @@ tmp/ public/** !public/.keep +# posts under construction +scratch/ + # per-user files imgui.ini **/.*.swp diff --git a/date.sh b/date.sh @@ -2,7 +2,7 @@ set -ex -touch -d 20200910 src/blog/test.html -touch -d 20210514 src/blog/cdoku.html -touch -d 20201112 src/blog/pyecs.html -touch -d 20201010 src/blog/clfs.html +touch -a -m -d 20200910 src/blog/test.html +touch -a -m -d 20201010 src/blog/clfs.html +touch -a -m -d 20201112 src/blog/pyecs.html +touch -a -m -d 20210514 src/blog/cdoku.html diff --git a/src/blog/cdoku.html b/src/blog/cdoku.html @@ -1,5 +1,3 @@ -<h2>A Sudoku Solver</h2> - <h3>Solving Sudoku</h3> <p> A while ago, for a university assignment, we were asked to write a sudoku solver. diff --git a/src/blog/cdoku.html.title.meta b/src/blog/cdoku.html.title.meta @@ -0,0 +1 @@ +Writing a Sudoku Solver diff --git a/src/blog/clfs.html b/src/blog/clfs.html @@ -1,5 +1,3 @@ -<h2>Building an OS for Dummies</h2> - <h3>I did a thing!</h3> <p> Today I finished a semi-long-term project. I managed to complete the diff --git a/src/blog/clfs.html.title.meta b/src/blog/clfs.html.title.meta @@ -0,0 +1 @@ +Building an OS for Dummies diff --git a/src/blog/pyecs.html b/src/blog/pyecs.html @@ -1,5 +1,3 @@ -<h2>ECS with Python and Tkinter</h2> - <h3>The Specification</h3> <p> Recently at Uni we were given a piece of coursework that had us write a game diff --git a/src/blog/pyecs.html.title.meta b/src/blog/pyecs.html.title.meta @@ -0,0 +1 @@ +Writing an ECS with Python and Tkinter diff --git a/src/blog/test.html b/src/blog/test.html @@ -1,4 +1,4 @@ -<h3>Hello, Blog</h3> +<h3>YARB: Yet Another Blog Rewrite</h3> <p> Yet another rewrite of my blog, this time even simpler. Who needs Markdown when plain HTML works just as well! Code blocks will be exceedingly annoying diff --git a/src/blog/test.html.title.meta b/src/blog/test.html.title.meta @@ -0,0 +1 @@ +Hello, Blog diff --git a/src/css/style.css b/src/css/style.css @@ -19,7 +19,7 @@ hr { } .container { - max-width: 40em; + max-width: 60em; margin-left: auto; margin-right: auto; padding: 1em; diff --git a/src/templates/blogpost.html b/src/templates/blogpost.html @@ -43,6 +43,8 @@ </header> <main> <div class="container"> + <h1>{title}</h1> + <hr /> {body} </div> </main> diff --git a/tools/template.c b/tools/template.c @@ -134,15 +134,34 @@ title_from_basename(char const *basename, char buf[static SUBST_TITLE_CAP]) return res; } +static inline struct str +title_from_filepath(char *filepath, char buf[static SUBST_TITLE_CAP]) +{ + struct str res; + + char path[PATH_MAX]; + strcpy(stpncpy(path, filepath, sizeof path), ".title.meta"); + + int title_file = open(path, O_RDONLY); + if (title_file < 0) + return title_from_basename(basename(filepath), buf); + + res.ptr = buf; + res.len = read(title_file, res.ptr, SUBST_TITLE_CAP); + + return res; +} + #define SUBST_TIME_CAP 32 static inline struct str date_from_timespec(struct timespec *ts, char buf[static SUBST_TIME_CAP]) { + strftime(buf, SUBST_TIME_CAP, "%Y/%m/%d", localtime(&ts->tv_sec)); + struct str res; - res.ptr = asctime_r(localtime(&ts->tv_sec), buf); - res.len = strlen(res.ptr) - 1; - res.ptr[res.len] = '\0'; // strip trailing '\n' + res.ptr = buf; + res.len = strlen(res.ptr); return res; } @@ -160,8 +179,8 @@ htmlpage_compare(void const *a, void const *b, void *arg) { (void) arg; - struct htmlpage const *lhs = a, *rhs = b; - return timestamp(&lhs->created) - timestamp(&rhs->created); + struct htmlpage const *lhs = b, *rhs = a; // reverse order + return timespec_compare(&lhs->created, &rhs->created); } static void @@ -172,7 +191,7 @@ format_index_page(struct htmlpage *pages, size_t len, int fd, char *urlfrag) for (size_t i = 0; i < len; i++) { struct htmlpage *page = pages + i; - dprintf(fd, "<li><span><a href=\"%s%s\">%s - %s</a></span></li>\n", + dprintf(fd, "<li><span><a href=\"%s%s\">%s: %s</a></span></li>\n", urlfrag, page->path, page->created_buf, page->title); } } @@ -223,7 +242,10 @@ main(int argc, char **argv) }; for (size_t i = 0; i < opts.sources.len; i++) { - char *srcpath = opts.sources.ptr[i]; + char *original_srcpath = opts.sources.ptr[i]; + + char srcpath[PATH_MAX]; + *stpncpy(srcpath, original_srcpath, sizeof srcpath) = 0; if (opts.verbose) printf("Processing source file: %s\n", srcpath); @@ -255,7 +277,7 @@ main(int argc, char **argv) struct substitutions substs; - substs.title = title_from_basename(page->path, page->title); + substs.title = title_from_filepath(original_srcpath, page->title); substs.created = date_from_timespec(&page->created, page->created_buf); substs.body.ptr = source; diff --git a/tools/utils.h b/tools/utils.h @@ -148,12 +148,12 @@ error: return -1; } -inline uint64_t -timestamp(struct timespec const *ts) +inline int +timespec_compare(struct timespec const *lhs, struct timespec const *rhs) { -#define NANOS 1000000000ULL - return (ts->tv_sec * NANOS) + ts->tv_nsec; -#undef NANOS + if (lhs->tv_sec == rhs->tv_sec) + return lhs->tv_nsec - rhs->tv_nsec; + return lhs->tv_sec - rhs->tv_sec; } inline char * @@ -198,8 +198,8 @@ list_pop_tail(struct list *list); extern inline int mmap_file(char *path, int flags, char **out_src, size_t *out_len, struct stat *out_stat); -extern inline uint64_t -timestamp(struct timespec const *ts); +extern inline int +timespec_compare(struct timespec const *lhs, struct timespec const *rhs); extern inline char * strnchr(char *restrict src, char const *restrict end, char marker);