aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/FileAssembler.cpp58
-rw-r--r--src/main.cpp4
2 files changed, 28 insertions, 34 deletions
diff --git a/src/FileAssembler.cpp b/src/FileAssembler.cpp
index b224a0c..cc8cc98 100644
--- a/src/FileAssembler.cpp
+++ b/src/FileAssembler.cpp
@@ -33,13 +33,14 @@ FileAssembler::FileAssembler(string path): path(path){
pages[l2.path().filename()] = content.substr(0,content.length()-1); //keeping plaintext link
else
pages[l2.path().filename()] = parser->Parse(ss); //parsing md to html
- }else{
+ }else{ // Posts
ss.str(content);
posts[l2.path().filename()] = parser->Parse(ss); //parsing md to html
}
}
}
}
+ ordered_posts_indexes = get_ordered_posts_indexes(); // Only used when a listing of posts in a page is necessary
}
void FileAssembler::parse_variables(){
@@ -76,28 +77,22 @@ string FileAssembler::get_file_content(string path){
return content;
}
-map <string, string> FileAssembler::get_pages(){
+map<string, string> FileAssembler::get_pages(){
return assemble_from_iterator(pages.begin(), pages.end(), false);
}
-map <string, string> FileAssembler::get_posts(){
+map<string, string> FileAssembler::get_posts(){
return assemble_from_iterator(posts.begin(), posts.end(), true);
}
-map <string, string> FileAssembler::assemble_from_iterator(map<string, string>::iterator it, map<string, string>::iterator end, bool is_post){
+map<string, string> FileAssembler::assemble_from_iterator(map<string, string>::iterator it, map<string, string>::iterator end, bool is_post){
if(templates.find("header.html") == templates.end()){
cerr << "Error: swg: header.html is not present in the sourced folder." << endl;
exit(2);
} else if(templates.find("footer.html") == templates.end()){
cerr << "Error: swg: footer.html is not present in the sourced folder." << endl;
exit(2);
- }/* else if(templates.find("menu_listing.html") == templates.end()){
- cerr << "Error: swg: menu_listing.html is not present in the sourced folder." << endl;
- exit(2);
- } else if(templates.find("post_listing.html") == templates.end()){
- cerr << "Error: swg: post_listing.html is not present in the sourced folder." << endl;
- exit(2);
- }*/
+ }
map<string, string> p_it;
while (it != end){
if(it->first.substr(0, 5) != "link_"){ // Ignoring link pages
@@ -143,8 +138,8 @@ string FileAssembler::parse(string title, string to_parse, bool is_post){
output = title;
else if(input.substr(0, 5) == "date("){
- variables["date"] = parse_arg("date",to_parse);
- output = " "; // I have to fill the variable to erase the $ section
+ variables["date"] = parse_arg(input);
+ output = variables["date"];
}else if(variables.find(input) != variables.end()) //VARIABLES
output = variables[input];
@@ -171,8 +166,15 @@ string FileAssembler::parse(string title, string to_parse, bool is_post){
} else if(input.substr(0,5) == "list_"){ //LISTINGS
-
- string name = input.substr(5,input.length()-1-4);
+ string name = "";
+ int arg = -1;
+ static std::regex rgx("\\_([a-z]*)(\\((\\d*)\\))?");
+ std::smatch match;
+ if (std::regex_search(input, match, rgx)){
+ name = match[1];
+ if(match[3] != "")
+ arg = stoi(match[3]);
+ }
string list_template = name + "_listing.html";
if(templates.find(list_template) == templates.end()){
@@ -190,20 +192,25 @@ string FileAssembler::parse(string title, string to_parse, bool is_post){
variables["link"] = current_link;
}else if(name == "post"){
string current_date = "";
- string current_link = variables["link"];
+ string current_link = variables["link"];
if(variables.find("date") != templates.end())
current_date = variables["date"];
- map<string, string>::iterator it = posts.begin();
- while (it != posts.end()){
- string date = parse_arg("date", it->second);
+
+ int i = 0;
+ vector<string>::iterator it = ordered_posts_indexes.begin();
+ while (it != ordered_posts_indexes.end() &&
+ (arg == -1 || i < arg) // Limiting the number of posts shown if arg is set
+ ){
+ string date = parse_arg(posts[*it]);
if(date != "")
variables["date"] = date;
else{
- cerr << "Error: swg: Variable 'date' of post '" << it->first << "' is not defined." << endl;
+ cerr << "Error: swg: Variable 'date' of post '" << *it << "' is not defined." << endl;
exit(5);
}
- output += parse(it->first,templates[list_template], true);
+ output += parse(*it,templates[list_template], true);
it ++;
+ i ++;
}
if(current_date != "")
variables["date"] = current_date;
@@ -221,12 +228,3 @@ string FileAssembler::parse(string title, string to_parse, bool is_post){
return parsed;
}
-string FileAssembler::parse_arg(string arg_name, string to_parse){
- if(to_parse.substr(3,6) != "$"+arg_name+"(")
- return "";
- size_t end = to_parse.find(")");
- if (end == string::npos)
- return "";
- string parsed = to_parse.substr(9, end-9);
- return parsed;
-}
diff --git a/src/main.cpp b/src/main.cpp
index 333a841..634d6fc 100644
--- a/src/main.cpp
+++ b/src/main.cpp
@@ -21,10 +21,6 @@ void write_file(string path, string content){
}
}
-void recursive_directory_copy(const fs::path& src, const fs::path& dst) noexcept
-{
-}
-
int generateWebsite(string arg, string config){
// cout << arg << " " << config << endl;
if(config[config.length()-1] != '/')