First working version of file content replacement system
This commit is contained in:
parent
d09e232843
commit
9a2a5e029d
37
main.cpp
37
main.cpp
@ -1,21 +1,42 @@
|
|||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
|
#include <filesystem>
|
||||||
|
|
||||||
#include "../C++UTF8Test/utf8.h"
|
#include "../C++UTF8Test/utf8.h"
|
||||||
|
|
||||||
|
namespace fs = std::filesystem;
|
||||||
|
|
||||||
const int MAX_FILE_SIZE = 8096;
|
const int MAX_FILE_SIZE = 8096;
|
||||||
|
|
||||||
int main() {
|
string32 readfile(const char* name) {
|
||||||
std::fstream layout_file;
|
std::fstream file_stream;
|
||||||
layout_file.open("testfiles/_layout.html");
|
file_stream.open(name);
|
||||||
|
|
||||||
char* data = new char [MAX_FILE_SIZE];
|
char* data = new char [MAX_FILE_SIZE];
|
||||||
int count(0);
|
int count(0);
|
||||||
while (layout_file)
|
while (file_stream)
|
||||||
data[count++] = layout_file.get();
|
data[count++] = file_stream.get();
|
||||||
|
file_stream.close();
|
||||||
data[--count] = 0;
|
data[--count] = 0;
|
||||||
|
string32 file = string32 (data);
|
||||||
string32 layout (data);
|
|
||||||
|
|
||||||
delete data;
|
delete data;
|
||||||
|
return file;
|
||||||
|
}
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
std::string path = "source";
|
||||||
|
|
||||||
|
string32 layout = readfile("source/_layout.html");
|
||||||
|
|
||||||
|
for (const auto & file : fs::recursive_directory_iterator(path)) {
|
||||||
|
if (file.is_regular_file()) {
|
||||||
|
if (file.path().stem().string().at(0) != '_') {
|
||||||
|
string32 newFile = layout;
|
||||||
|
newFile.replace("{{ content }}", readfile(file.path().string().c_str()));
|
||||||
|
std::cout << "File: " << file.path() << "\n-----\n" << newFile << "\n-----\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
std::cout << layout << "\n";
|
std::cout << layout << "\n";
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user