Renamed the article struct in PagedArticle to PagedArticleEntry, and moved it to it's own file. Also made it inherit from reference.

This commit is contained in:
Relintai 2022-02-04 20:36:09 +01:00
parent 3361d576de
commit 01c43bf369
4 changed files with 49 additions and 29 deletions

View File

@ -11,7 +11,7 @@
void PagedArticle::handle_request_main(Request *request) {
const String r = request->get_current_path_segment();
Article *s = pages[r];
PagedArticleEntry *s = pages[r];
if (s == nullptr) {
request->send_error(404);
@ -94,7 +94,7 @@ void PagedArticle::load() {
String ff = folder + "/" + fn;
String wp = base_path + "/" + fn;
Article *a = load_folder(np, wp);
PagedArticleEntry *a = load_folder(np, wp);
if (a) {
@ -116,7 +116,7 @@ void PagedArticle::load() {
generate_summaries();
}
Article *PagedArticle::load_folder(const String &folder, const String &path) {
PagedArticleEntry *PagedArticle::load_folder(const String &folder, const String &path) {
printf("PagedArticle: loading: %s\n", folder.c_str());
Vector<String> files;
@ -152,7 +152,7 @@ Article *PagedArticle::load_folder(const String &folder, const String &path) {
//todo
//std::sort(files.begin(), files.end());
Article *article = new Article();
PagedArticleEntry *article = new PagedArticleEntry();
for (uint32_t i = 0; i < files.size(); ++i) {
String file_path = folder;
@ -202,12 +202,12 @@ Article *PagedArticle::load_folder(const String &folder, const String &path) {
}
void PagedArticle::generate_summaries() {
for (std::map<String, Article *>::iterator it = pages.begin(); it != pages.end(); ++it) {
for (std::map<String, PagedArticleEntry *>::iterator it = pages.begin(); it != pages.end(); ++it) {
generate_summary((*it).second);
}
}
void PagedArticle::generate_summary(Article *article) {
void PagedArticle::generate_summary(PagedArticleEntry *article) {
if (article->summary_page != "") {
return;
}

View File

@ -9,26 +9,7 @@
#include "core/http/web_node.h"
#include "core/http/request.h"
struct Article {
String url;
String summary_page;
std::map<String, String *> pages;
FileCache *file_cache;
Article() {
file_cache = new FileCache();
}
~Article() {
for (std::map<String, String *>::iterator it = pages.begin(); it != pages.end(); ++it) {
delete ((*it).second);
}
pages.clear();
delete file_cache;
}
};
#include "paged_article_entry.h"
class PagedArticle : public WebNode {
RCPP_OBJECT(PagedArticle, WebNode);
@ -37,14 +18,14 @@ public:
void handle_request_main(Request *request);
void load();
Article *load_folder(const String &folder, const String &path);
PagedArticleEntry *load_folder(const String &folder, const String &path);
void generate_summaries();
void generate_summary(Article *article);
void generate_summary(PagedArticleEntry *article);
PagedArticle();
~PagedArticle();
std::map<String, Article *> pages;
std::map<String, PagedArticleEntry *> pages;
String folder;
String base_path;
};

View File

@ -0,0 +1,2 @@
#include "paged_article_entry.h"

View File

@ -0,0 +1,37 @@
#ifndef PAGED_ARTICLE_ENTRY_H
#define PAGED_ARTICLE_ENTRY_H
#include <map>
#include "core/containers/vector.h"
#include "core/string.h"
#include "core/file_cache.h"
#include "core/http/web_node.h"
#include "core/http/request.h"
#include "core/reference.h"
class PagedArticleEntry : public Reference {
RCPP_OBJECT(PagedArticleEntry, Reference);
public:
String url;
String summary_page;
std::map<String, String *> pages;
FileCache *file_cache;
PagedArticleEntry() {
file_cache = new FileCache();
}
~PagedArticleEntry() {
for (std::map<String, String *>::iterator it = pages.begin(); it != pages.end(); ++it) {
delete ((*it).second);
}
pages.clear();
delete file_cache;
}
};
#endif