diff --git a/src/Article.cxx b/src/Article.cxx index e668d5f..556ccc9 100644 --- a/src/Article.cxx +++ b/src/Article.cxx @@ -103,7 +103,6 @@ namespace Article { } bool reading_article_metadata = false; - for (std::string const &line : cfg_lines) { std::cout << "[!] Line: " << line << "\n"; // Check namespace @@ -131,5 +130,11 @@ namespace Article { fclose(a); } + bool Comparator::comp(Metadata *a, Metadata *b) { + 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 d483901..121be1d 100644 --- a/src/Article.hxx +++ b/src/Article.hxx @@ -44,6 +44,11 @@ namespace Article { mature_content_reason[256]; }; + class Comparator { + public: + static bool comp(Metadata *a, Metadata *b); + static bool equiv(Metadata *a, Metadata *b); + }; void get_metadata(std::string const &path, Metadata *m); } diff --git a/src/Common.hxx b/src/Common.hxx index 3651593..449f707 100644 --- a/src/Common.hxx +++ b/src/Common.hxx @@ -35,4 +35,3 @@ #define RETURN_FAILED_WEBSITE_BUILD_EXISTS 4 #define RETURN_FAILED_UNKNOWN_ERROR 10 - diff --git a/src/WebsiteBuilder.cxx b/src/WebsiteBuilder.cxx index 075e155..be8980e 100644 --- a/src/WebsiteBuilder.cxx +++ b/src/WebsiteBuilder.cxx @@ -24,8 +24,8 @@ #include #include #include - #include +#include "time.h" #include "SwgRuntime.hxx" #include "SwgContext.hxx" @@ -138,6 +138,7 @@ void build_blog_structure(std::string const &path, std::string const &prefix, st } std::list am; + //std::map> sorted_articles; for (std::string const &a : articles) { std::string articlePath = blog_relative_path(prefix, a); @@ -150,7 +151,8 @@ void build_blog_structure(std::string const &path, std::string const &prefix, st // Go ahead and parse article metadata. Article::Metadata *articleMetadata = (Article::Metadata*) malloc(sizeof(Article::Metadata)); Article::get_metadata(a, articleMetadata); - std::cout << "Parsed metadata for article \"" << articleMetadata->title << "\"\n"; + 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 @@ -178,6 +180,8 @@ void build_blog_structure(std::string const &path, std::string const &prefix, st exit(RETURN_FAILED_UNKNOWN_ERROR); } } + // Sort am list. + am.sort(Article::Comparator::comp); } /**