summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorWormHeamer2025-03-09 15:51:15 -0400
committerWormHeamer2025-03-09 15:51:15 -0400
commit2ba77b1163e3c3a9aa7cc89b1b284ba21ddfd78c (patch)
tree034bfa5274f4f7d34ae7e074227f6fb1e5ea78ed
parent317582f6b58d4a7518b6f65f86bf8862e815ff82 (diff)
add -t --title
-rw-r--r--main.c22
1 files changed, 14 insertions, 8 deletions
diff --git a/main.c b/main.c
index 5304802..996a3ad 100644
--- a/main.c
+++ b/main.c
@@ -283,7 +283,8 @@ void usage(const char *cmd) {
" -s --standalone prefix with html metadata\n"
" -h --hvar define a css variable (--name) with a random value,\n"
" selected by a hash of the document's title\n"
- " -c --css embed the given file within a <style> element\n",
+ " -c --css embed the given file within a <style> element\n"
+ " -t --title set the document title (does nothing without --standalone)\n",
cmd, cmd);
}
@@ -355,9 +356,10 @@ int main(int argc, const char **argv) {
Str param = { 0 };
opts.from_stdin = 1;
- while ((r = arg_get(&a, "?sc:h:", &param,
+ while ((r = arg_get(&a, "?sc:h:t:", &param,
"help", '?',
"standalone", 's',
+ ":title", 't',
":css", 'c',
":hvar", 'h')) >= ARG_OK) {
Arena reset = scratch;
@@ -372,6 +374,9 @@ int main(int argc, const char **argv) {
case 'c':
opts.stylesheet = param;
break;
+ case 't':
+ opts.title = param;
+ break;
case 'h':
if (opts.hvarc == countof(opts.hvarv)) {
fprintf(stderr, "too many hash variables!\n");
@@ -424,12 +429,13 @@ int main(int argc, const char **argv) {
}
}
- if (doc && opts.standalone) {
- opts.title = doc->title;
- while (doc->prev) {
- doc = doc->prev;
- if (doc->title.s) opts.title = doc->title;
- }
+ if (doc && !opts.title.s) opts.title = doc->title;
+ while (doc && doc->prev) {
+ doc = doc->prev;
+ if (doc->title.s && !opts.title.s) opts.title = doc->title;
+ }
+
+ if (opts.standalone) {
str_put(html_head(&opts, &perm, &scratch));
}