Add the new virtuals to the static pages.

This commit is contained in:
Relintai 2022-02-14 23:14:33 +01:00
parent 34e669c55b
commit 809de8a01c
2 changed files with 25 additions and 8 deletions

View File

@ -1,31 +1,39 @@
#include "static_page.h"
#include "core/os/directory.h"
#include "web/file_cache.h"
#include "web/html/html_builder.h"
#include "web/http/request.h"
#include "web/html/utils.h"
#include "core/os/directory.h"
#include "web/http/request.h"
void StaticPage::_handle_request_main(Request *request) {
if (should_render_menu) {
render_menu(request);
}
request->body += data;
render(request);
request->compile_and_send_body();
}
void StaticPage::render(Request *request) {
request->body += data;
}
void StaticPage::render_preview(Request *request) {
request->body += preview_data;
}
void StaticPage::load_file(const String &path) {
Ref<Directory> d;
d.instance();
d->read_file_into(path, &data);
}
void StaticPage::load_and_process_file(const String &path) {
Ref<Directory> d;
d.instance();
d->read_file_into(path, &data);
if (path.file_get_extension() == "md") {
@ -36,21 +44,25 @@ void StaticPage::load_and_process_file(const String &path) {
void StaticPage::load_md_file(const String &path) {
Ref<Directory> d;
d.instance();
d->read_file_into(path, &data);
Utils::markdown_to_html(&data);
}
void StaticPage::set_data_md(const String &d) {
data.clear();
Utils::markdown_to_html(&data);
}
void StaticPage::set_data(const String &d) {
data = d;
}
void StaticPage::set_preview_data(const String &d) {
preview_data = d;
}
StaticPage::StaticPage() :
WebNode() {

View File

@ -11,14 +11,19 @@ class StaticPage : public WebNode {
public:
void _handle_request_main(Request *request);
void render(Request *request);
void render_preview(Request *request);
void load_file(const String &path);
void load_and_process_file(const String &path);
void load_md_file(const String &path);
void set_data_md(const String &d);
void set_data(const String &d);
void set_preview_data(const String &d);
String data;
String preview_data;
bool should_render_menu;
StaticPage();