diff --git a/src/Article.cxx b/src/Article.cxx index 556ccc9..df7650f 100644 --- a/src/Article.cxx +++ b/src/Article.cxx @@ -131,7 +131,7 @@ namespace Article { fclose(a); } bool Comparator::comp(Metadata *a, Metadata *b) { - return a->publish_ts < b->publish_ts; + return a->publish_ts > b->publish_ts; } bool Comparator::equiv(Metadata *a, Metadata *b) { return a->publish_ts == b->publish_ts; diff --git a/src/Article.hxx b/src/Article.hxx index 121be1d..702f9d1 100644 --- a/src/Article.hxx +++ b/src/Article.hxx @@ -27,6 +27,7 @@ namespace Article { struct Metadata { char title[128]; char authors[128]; // Author (or authors) for this article + char path[256]; // Path to this article // Epoch timestamps long original_ts; // Original article timestamp (for "Originally written on [...]") diff --git a/src/WebsiteBuilder.cxx b/src/WebsiteBuilder.cxx index be8980e..37d584f 100644 --- a/src/WebsiteBuilder.cxx +++ b/src/WebsiteBuilder.cxx @@ -153,7 +153,6 @@ void build_blog_structure(std::string const &path, std::string const &prefix, st Article::get_metadata(a, articleMetadata); std::cout << "Parsed metadata for article \"" << articleMetadata->title << "\"\n\tPublished on " << ctime(&(articleMetadata->publish_ts)) << "\n"; - am.push_back(articleMetadata); // TODO: This code could be optimized by removing directory // checks for every single article. Instead, add @@ -162,18 +161,25 @@ void build_blog_structure(std::string const &path, std::string const &prefix, st // directories later as needed. try { // Create directory for the year of this article if it doesn't exist. - std::filesystem::path oad = obp; // Output Article Directory + std::filesystem::path oad = obp, // Output Article Directory + rap; // Relative Article Path oad /= year; + rap /= year; if (!std::filesystem::exists(oad)) std::filesystem::create_directory(oad); // Do the same for the article month. oad /= month; + rap /= month; if (!std::filesystem::exists(oad)) std::filesystem::create_directory(oad); // Now create the article file. - oad /= getFilename(a, false); - oad += ".html"; + std::string new_article_filename = getFilename(a, false); + new_article_filename += ".html"; + oad /= new_article_filename; + rap /= new_article_filename; compile_markdown(path, a, oad); + strncpy(articleMetadata->path, rap.c_str(), sizeof(articleMetadata->path)); + am.push_back(articleMetadata); } catch (std::filesystem::filesystem_error const &e) { std::cerr << "error: failed to create directory for an article from blog \"" << blog->name << "\": " << e.what() << std::endl; @@ -182,6 +188,47 @@ void build_blog_structure(std::string const &path, std::string const &prefix, st } // Sort am list. am.sort(Article::Comparator::comp); + // Generate blog catalog. + std::string blog_html_catalog = "