Sort articles by timestamp
Sort articles in std::list by timestamp to generate blog catalogs.
This commit is contained in:
parent
1e8660fb86
commit
4753920f3d
|
@ -103,7 +103,6 @@ namespace Article {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool reading_article_metadata = false;
|
bool reading_article_metadata = false;
|
||||||
|
|
||||||
for (std::string const &line : cfg_lines) {
|
for (std::string const &line : cfg_lines) {
|
||||||
std::cout << "[!] Line: " << line << "\n";
|
std::cout << "[!] Line: " << line << "\n";
|
||||||
// Check namespace
|
// Check namespace
|
||||||
|
@ -131,5 +130,11 @@ namespace Article {
|
||||||
|
|
||||||
fclose(a);
|
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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -44,6 +44,11 @@ namespace Article {
|
||||||
|
|
||||||
mature_content_reason[256];
|
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);
|
void get_metadata(std::string const &path, Metadata *m);
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,4 +35,3 @@
|
||||||
#define RETURN_FAILED_WEBSITE_BUILD_EXISTS 4
|
#define RETURN_FAILED_WEBSITE_BUILD_EXISTS 4
|
||||||
|
|
||||||
#define RETURN_FAILED_UNKNOWN_ERROR 10
|
#define RETURN_FAILED_UNKNOWN_ERROR 10
|
||||||
|
|
||||||
|
|
|
@ -24,8 +24,8 @@
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <list>
|
#include <list>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
|
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include "time.h"
|
||||||
|
|
||||||
#include "SwgRuntime.hxx"
|
#include "SwgRuntime.hxx"
|
||||||
#include "SwgContext.hxx"
|
#include "SwgContext.hxx"
|
||||||
|
@ -138,6 +138,7 @@ void build_blog_structure(std::string const &path, std::string const &prefix, st
|
||||||
}
|
}
|
||||||
|
|
||||||
std::list<Article::Metadata*> am;
|
std::list<Article::Metadata*> am;
|
||||||
|
//std::map<std::string, std::list<std::string>> sorted_articles;
|
||||||
|
|
||||||
for (std::string const &a : articles) {
|
for (std::string const &a : articles) {
|
||||||
std::string articlePath = blog_relative_path(prefix, a);
|
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.
|
// Go ahead and parse article metadata.
|
||||||
Article::Metadata *articleMetadata = (Article::Metadata*) malloc(sizeof(Article::Metadata));
|
Article::Metadata *articleMetadata = (Article::Metadata*) malloc(sizeof(Article::Metadata));
|
||||||
Article::get_metadata(a, articleMetadata);
|
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);
|
am.push_back(articleMetadata);
|
||||||
|
|
||||||
// TODO: This code could be optimized by removing directory
|
// 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);
|
exit(RETURN_FAILED_UNKNOWN_ERROR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Sort am list.
|
||||||
|
am.sort(Article::Comparator::comp);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue