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:
parent
2cf3706a83
commit
647ad56349
|
@ -124,13 +124,16 @@ namespace Article {
|
||||||
if (reading_article_metadata) {
|
if (reading_article_metadata) {
|
||||||
std::string k_title = "Title=",
|
std::string k_title = "Title=",
|
||||||
k_authors = "Authors=",
|
k_authors = "Authors=",
|
||||||
k_published = "Published=";
|
k_published = "Published=",
|
||||||
|
k_published_str = "PublishedString=";
|
||||||
if (line.find(k_title) == 0)
|
if (line.find(k_title) == 0)
|
||||||
strncpy(m->title, line.substr(k_title.length()).c_str(), sizeof(m->title));
|
strncpy(m->title, line.substr(k_title.length()).c_str(), sizeof(m->title));
|
||||||
else if (line.find(k_authors) == 0)
|
else if (line.find(k_authors) == 0)
|
||||||
strncpy(m->authors, line.substr(k_authors.length()).c_str(), sizeof(m->authors));
|
strncpy(m->authors, line.substr(k_authors.length()).c_str(), sizeof(m->authors));
|
||||||
else if (line.find(k_published) == 0)
|
else if (line.find(k_published) == 0)
|
||||||
m->publish_ts = atol(line.substr(k_published.length()).c_str());
|
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
|
else
|
||||||
std::cerr << "warning: ignoring unknown key/value due to unknown key: " << line << std::endl;
|
std::cerr << "warning: ignoring unknown key/value due to unknown key: " << line << std::endl;
|
||||||
} else if (line[0] == '[') {
|
} else if (line[0] == '[') {
|
||||||
|
|
|
@ -30,9 +30,10 @@ namespace Article {
|
||||||
char path[256]; // Path to this article
|
char path[256]; // Path to this article
|
||||||
|
|
||||||
// Epoch timestamps
|
// Epoch timestamps
|
||||||
long original_ts; // Original article timestamp (for "Originally written on [...]")
|
long original_ts; // Original article timestamp (for "Originally written on [...]")
|
||||||
long publish_ts; // (for "Published on [...]")
|
long publish_ts; // (for "Published on [...]")
|
||||||
long update_ts; // (for "Last updated on [...]")
|
long update_ts; // (for "Last updated on [...]")
|
||||||
|
char publish_str[32]; // Override localized publish timestamps
|
||||||
|
|
||||||
// Article flags
|
// Article flags
|
||||||
bool partially_obsoleted,
|
bool partially_obsoleted,
|
||||||
|
|
|
@ -138,16 +138,19 @@ void compile_markdown(std::string const &path, std::string const &md, std::strin
|
||||||
std::string article_html;
|
std::string article_html;
|
||||||
if (metadata != NULL) {
|
if (metadata != NULL) {
|
||||||
// Get time information.
|
// Get time information.
|
||||||
struct tm *publish_tm = gmtime(&(metadata->publish_ts));
|
|
||||||
article_html = "<h1>";
|
article_html = "<h1>";
|
||||||
article_html += metadata->title;
|
article_html += metadata->title;
|
||||||
article_html += "</h1>\n<span><b>Published on ";
|
article_html += "</h1>\n<span><b>Published on ";
|
||||||
//article_html += ctime(&(metadata->publish_ts));
|
if (metadata->publish_str[0] == '\0') {
|
||||||
article_html += HR_MONTH[publish_tm->tm_mon];
|
struct tm *publish_tm = gmtime(&(metadata->publish_ts));
|
||||||
article_html += " ";
|
//article_html += ctime(&(metadata->publish_ts));
|
||||||
article_html += std::to_string(publish_tm->tm_mday);
|
article_html += HR_MONTH[publish_tm->tm_mon];
|
||||||
article_html += ", ";
|
article_html += " ";
|
||||||
article_html += std::to_string(publish_tm->tm_year + 1900);
|
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 += "</b></span><br/>\n<span><b>Written by ";
|
||||||
article_html += metadata->authors;
|
article_html += metadata->authors;
|
||||||
article_html += "</b></span><br/>";
|
article_html += "</b></span><br/>";
|
||||||
|
|
Loading…
Reference in New Issue