dag

Djmoch's Auto Generator
git clone git://git.danielmoch.com/dag.git
Log | Files | Refs | README | LICENSE

commit d4df6f3674eaf673d5b4808514cd8ab01b94e6c7
parent e0b4a895abe1be782ed5ef6fd2d4e1735523929c
Author: Daniel Moch <daniel@danielmoch.com>
Date:   Fri, 26 Nov 2021 07:30:10 -0500

Add sitemap_only feature

Diffstat:
Mdagindex.1 | 9+++++++++
Mdagindex.c | 13++++++++++++-
Mdb.c | 18+++++++++++++-----
Mdb.h | 1+
Mhtml.c | 4++++
Mxml.c | 4++++
6 files changed, 43 insertions(+), 6 deletions(-)

diff --git a/dagindex.1 b/dagindex.1 @@ -17,6 +17,7 @@ .Op Fl u Ar date_updated .Op Fl c Ar category .Op Fl d Ar description +.Op Fl x Ar sitemap_only .Nm .Fl G .Fl o Ar fmt @@ -93,6 +94,14 @@ as the category of the entry to be added to the database. Use .Ar description as the description of the entry to be added to the database. +.It Fl x Ar sitemap_only +Use the value of +.Ar sitemap_only +to control whether the entry should only be printed in sitemaps +(i.e., whether the entry should be excluded from HTML indexes and +RSS feeds). +A value of 0 means to print the entry in all indexes. +A value of 1 means to print the entry only in sitemaps. .El .Pp Generate mode options: diff --git a/dagindex.c b/dagindex.c @@ -48,6 +48,7 @@ usage(int rv) fprintf(fp, "usage: %s -Vh\n", argv0); fprintf(fp, "\t%s -A -t title -s slug -p date_published [-a author]\n", argv0); fprintf(fp, "\t\t[-u date_updated] [-c category] [-d description]\n"); + fprintf(fp, "\t\t[-x sitemap_only]\n"); fprintf(fp, "\t%s -G -o fmt [-t title] [-f fqdn] [-d description]\n", argv0); fprintf(fp, "\t\t[-r rss_url] [-l language] [-c copyright]\n"); exit(rv); @@ -114,10 +115,11 @@ main(int argc, char **argv) char ch, *author = NULL, *c = NULL, *desc = NULL, *fmt = NULL, *fqdn = NULL, *lang = NULL, *pub = NULL, *rss_url = NULL, *slug = NULL, *title = NULL, *updated = NULL; + unsigned short sitemap_only = 0; argv0 = basename(argv[0]); - while ((ch = getopt(argc, argv, "AGVa:c:d:f:hl:o:p:r:s:t:u:v")) != -1) { + while ((ch = getopt(argc, argv, "AGVa:c:d:f:hl:o:p:r:s:t:u:vx:")) != -1) { switch (ch) { case 'A': if (mode != NONE) { @@ -205,6 +207,13 @@ main(int argc, char **argv) case 'v': verbose += 1; break; + case 'x': + if (mode != ADD) { + warnx("specifying -x without -A makes no sense"); + usage(ERR_ARGS); + } + sitemap_only = atoi(optarg); + break; default: usage(ERR_UNKNOWN_OPTION); } @@ -247,6 +256,7 @@ main(int argc, char **argv) fprintf(stderr, "\tslug = %s\n", slug); fprintf(stderr, "\ttitle = %s\n", title); fprintf(stderr, "\tdate_updated = %s\n", updated); + fprintf(stderr, "\tsitemap_only = %hu\n", sitemap_only); } index = db_index_open(index_file); @@ -260,6 +270,7 @@ main(int argc, char **argv) entry->slug = populate_str(slug, ""); entry->title = populate_str(title, ""); entry->date_updated = populate_time(updated); + entry->sitemap_only = sitemap_only; entry->next = NULL; db_entry_add(index, entry); diff --git a/db.c b/db.c @@ -99,6 +99,7 @@ db_index_write(struct db_index *index) fputs(entry->title, fp); fwrite(&nul, sizeof(char), 1, fp); fwrite(&(entry->date_updated), sizeof(time_t), 1, fp); + fwrite(&(entry->sitemap_only), sizeof(unsigned short), 1, fp); entry = entry->next; } @@ -220,6 +221,7 @@ db_entry_fprint(FILE *fp, struct db_entry *entry) fprintf(fp, "\tslug = %s\n", entry->slug); fprintf(fp, "\ttitle = %s\n", entry->title); fprintf(fp, "\tdate_updated = %s\n", ustring); + fprintf(fp, "\tsitemap_only = %s\n", (entry->sitemap_only == 0) ? "false" : "true"); } static struct db_entry * @@ -244,19 +246,22 @@ getentry(FILE *fp) if ((entry->category = getstring(fp)) == NULL) { errx(1, "index db file corrupt!"); } - if((entry->description = getstring(fp)) == NULL) { + if ((entry->description = getstring(fp)) == NULL) { errx(1, "index db file corrupt!"); } - if(fread(&(entry->date_published), sizeof(time_t), 1, fp) == 0) { + if (fread(&(entry->date_published), sizeof(time_t), 1, fp) == 0) { errx(1, "index db file corrupt!"); } - if((entry->slug = getstring(fp)) == NULL) { + if ((entry->slug = getstring(fp)) == NULL) { errx(1, "index db file corrupt!"); } - if((entry->title = getstring(fp)) == NULL) { + if ((entry->title = getstring(fp)) == NULL) { errx(1, "index db file corrupt!"); } - if(fread(&(entry->date_updated), sizeof(time_t), 1, fp) == 0) { + if (fread(&(entry->date_updated), sizeof(time_t), 1, fp) == 0) { + errx(1, "index db file corrupt!"); + } + if (fread(&(entry->sitemap_only), sizeof(unsigned short), 1, fp) == 0) { errx(1, "index db file corrupt!"); } entry->next = NULL; @@ -314,6 +319,9 @@ entrycmp(struct db_entry *e1, struct db_entry *e2) if (e1->date_updated != e2->date_updated) { return 1; } + if (e1->sitemap_only != e2->sitemap_only) { + return 1; + } return 0; } diff --git a/db.h b/db.h @@ -8,6 +8,7 @@ struct db_entry { char *slug; char *title; time_t date_updated; + unsigned short sitemap_only; struct db_entry *next; }; diff --git a/html.c b/html.c @@ -23,6 +23,10 @@ html_db_fmt(struct db_index *index) char pub[DATE_STRING_LENGTH]; while (entry != NULL) { + if (entry->sitemap_only) { + entry = entry->next; + continue; + } if ((pub_tm = gmtime(&(entry->date_published))) == NULL) { errx(1, "call to gmtime failed"); } diff --git a/xml.c b/xml.c @@ -149,6 +149,10 @@ xml_db_fmt_rss(char *title, char *fqdn, char *description, char *rss_url, puts(" <docs>http://blogs.law.harvard.edu/tech/rss</docs>"); while (entry != NULL) { + if (entry->sitemap_only) { + entry = entry->next; + continue; + } char *etitle, *elink, *ecreator, *edescription, *eslug; if ((etitle = strdup(entry->title)) == NULL) {