From 84428c144e54170ec629b379e1daf86857da2be8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Gassmann?= Date: Thu, 17 Mar 2022 16:14:17 +0100 Subject: [~] Refactoring of the FileAssembler, Extraction of methods in PParser --- src/main.cpp | 53 +++++++++++++++++++++-------------------------------- 1 file changed, 21 insertions(+), 32 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 634d6fc..cb5ad2f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1,9 +1,7 @@ #include "../inc/FileAssembler.h" #include -#include #include -#include -#include +#include using namespace std; @@ -21,6 +19,14 @@ void write_file(string path, string content){ } } +static string lowercase(string s){ + string low = ""; + for (int i = 0; i < s.length(); i++) { + low += tolower(s[i]); + } + return low; +} + int generateWebsite(string arg, string config){ // cout << arg << " " << config << endl; if(config[config.length()-1] != '/') @@ -28,8 +34,7 @@ int generateWebsite(string arg, string config){ FileAssembler *fa = new FileAssembler(config); /* TODO * clean or don't clean*/ - map pages = fa->get_pages(); - map posts = fa->get_posts(); + map* website = fa->get_website(); string target = fa->get_target(); string index = fa->get_index(); @@ -41,43 +46,27 @@ int generateWebsite(string arg, string config){ cerr << "Error: swg: Directory '" << target << "/posts' could not be created!" << endl; exit(6); } - map::iterator it = pages.begin(); - while(it != pages.end()){ + map::iterator it = website[0].begin(); + while(it != website[0].end()){ if(it->first == index){ write_file(target+"/index.html", it->second); }else{ - write_file(target+"/"+FileAssembler::lowercase(it->first)+".html", it->second); + write_file(target+"/"+lowercase(it->first)+".html", it->second); } it++; } - it = posts.begin(); - while(it != posts.end()){ - write_file(target+"/posts/"+FileAssembler::lowercase(it->first)+".html", it->second); + it = website[1].begin(); + while(it != website[1].end()){ + write_file(target+"/posts/"+lowercase(it->first)+".html", it->second); it++; } - if (false){ // Only copying the cached resources vs all of them - /** list resources = fa->get_cached_resources(); - - list::iterator res = resources.begin(); - while(res != resources.end()){ - error_code ec; - fs::copy(config+"resources/"+*res, target+"/"+*res,ec); - if(ec.value() != 0){ - cerr << "Error: swg: Resource file '" << *res << "' could not be copied!" << endl; - exit(6); - } - res ++; - } - **/ - }else{ - // Recursively copies all files and folders from src to target and overwrites existing files in target. - try{ - fs::copy(config+"resources/", target, fs::copy_options::overwrite_existing | fs::copy_options::recursive); - }catch (std::exception& e){ - std::cout << e.what(); // TODO better print - } + // Recursively copies all files and folders from src to target and overwrites existing files in target. + try{ + fs::copy(config+"resources/", target, fs::copy_options::overwrite_existing | fs::copy_options::recursive); + }catch (std::exception& e){ + std::cout << e.what(); // TODO better print } return 0; -- cgit v1.2.3