Add custom localized timestamp override

Add support for a custom key in the article metadata that allows users
to override the default date string (e.g. January 1, 1970).  This is
useful for other locales.
This commit is contained in:
luca0N! 2022-04-27 20:51:39 -03:00
parent 2cf3706a83
commit 647ad56349
Signed by: luca0N
GPG Key ID: 2E7B4655CF16D7D6
3 changed files with 18 additions and 11 deletions

View File

@ -124,13 +124,16 @@ namespace Article {
if (reading_article_metadata) {
std::string k_title = "Title=",
k_authors = "Authors=",
k_published = "Published=";
k_published = "Published=",
k_published_str = "PublishedString=";
if (line.find(k_title) == 0)
strncpy(m->title, line.substr(k_title.length()).c_str(), sizeof(m->title));
else if (line.find(k_authors) == 0)
strncpy(m->authors, line.substr(k_authors.length()).c_str(), sizeof(m->authors));
else if (line.find(k_published) == 0)
m->publish_ts = atol(line.substr(k_published.length()).c_str());
else if (line.find(k_published_str) == 0)
strncpy(m->publish_str, line.substr(k_published_str.length()).c_str(), sizeof(m->publish_str));
else
std::cerr << "warning: ignoring unknown key/value due to unknown key: " << line << std::endl;
} else if (line[0] == '[') {

View File

@ -30,9 +30,10 @@ namespace Article {
char path[256]; // Path to this article
// Epoch timestamps
long original_ts; // Original article timestamp (for "Originally written on [...]")
long publish_ts; // (for "Published on [...]")
long update_ts; // (for "Last updated on [...]")
long original_ts; // Original article timestamp (for "Originally written on [...]")
long publish_ts; // (for "Published on [...]")
long update_ts; // (for "Last updated on [...]")
char publish_str[32]; // Override localized publish timestamps
// Article flags
bool partially_obsoleted,

View File

@ -138,16 +138,19 @@ void compile_markdown(std::string const &path, std::string const &md, std::strin
std::string article_html;
if (metadata != NULL) {
// Get time information.
struct tm *publish_tm = gmtime(&(metadata->publish_ts));
article_html = "<h1>";
article_html += metadata->title;
article_html += "</h1>\n<span><b>Published on ";
//article_html += ctime(&(metadata->publish_ts));
article_html += HR_MONTH[publish_tm->tm_mon];
article_html += " ";
article_html += std::to_string(publish_tm->tm_mday);
article_html += ", ";
article_html += std::to_string(publish_tm->tm_year + 1900);
if (metadata->publish_str[0] == '\0') {
struct tm *publish_tm = gmtime(&(metadata->publish_ts));
//article_html += ctime(&(metadata->publish_ts));
article_html += HR_MONTH[publish_tm->tm_mon];
article_html += " ";
article_html += std::to_string(publish_tm->tm_mday);
article_html += ", ";
article_html += std::to_string(publish_tm->tm_year + 1900);
} else
article_html += metadata->publish_str;
article_html += "</b></span><br/>\n<span><b>Written by ";
article_html += metadata->authors;
article_html += "</b></span><br/>";