diff --git a/src/.cache/clangd/index/config.cpp.A68A2AE9FDFA8117.idx b/src/.cache/clangd/index/config.cpp.A68A2AE9FDFA8117.idx new file mode 100644 index 0000000..e7480b6 Binary files /dev/null and b/src/.cache/clangd/index/config.cpp.A68A2AE9FDFA8117.idx differ diff --git a/src/.cache/clangd/index/config.hpp.C519F3A7E0A75094.idx b/src/.cache/clangd/index/config.hpp.C519F3A7E0A75094.idx new file mode 100644 index 0000000..1139254 Binary files /dev/null and b/src/.cache/clangd/index/config.hpp.C519F3A7E0A75094.idx differ diff --git a/src/.cache/clangd/index/format.cpp.047FF551BC8DE01E.idx b/src/.cache/clangd/index/format.cpp.047FF551BC8DE01E.idx new file mode 100644 index 0000000..3611aef Binary files /dev/null and b/src/.cache/clangd/index/format.cpp.047FF551BC8DE01E.idx differ diff --git a/src/.cache/clangd/index/main.cpp.AC604CCC20973D23.idx b/src/.cache/clangd/index/main.cpp.AC604CCC20973D23.idx new file mode 100644 index 0000000..a2de7f5 Binary files /dev/null and b/src/.cache/clangd/index/main.cpp.AC604CCC20973D23.idx differ diff --git a/src/.cache/clangd/index/markdown.cpp.A5D40F1BF5766683.idx b/src/.cache/clangd/index/markdown.cpp.A5D40F1BF5766683.idx new file mode 100644 index 0000000..4050d1b Binary files /dev/null and b/src/.cache/clangd/index/markdown.cpp.A5D40F1BF5766683.idx differ diff --git a/src/.cache/clangd/index/markdown.hpp.66A7ABFD738DA42D.idx b/src/.cache/clangd/index/markdown.hpp.66A7ABFD738DA42D.idx new file mode 100644 index 0000000..5730bda Binary files /dev/null and b/src/.cache/clangd/index/markdown.hpp.66A7ABFD738DA42D.idx differ diff --git a/src/config/config.cpp b/src/config/config.cpp index 4deede6..37b7c6e 100644 --- a/src/config/config.cpp +++ b/src/config/config.cpp @@ -5,10 +5,10 @@ #include #include -Config get_config(const std::string &CONFIG_FILE) { +Config get_config(const std::string &CONFIGURATION) { toml::table toml_table; try { - toml_table = toml::parse_file(CONFIG_FILE); + toml_table = toml::parse(CONFIGURATION); } catch (const toml::parse_error &err) { std::cerr << "Parsing failed:" << std::endl << err << std::endl; } diff --git a/src/config/config.hpp b/src/config/config.hpp index 30e25ee..1c40f89 100644 --- a/src/config/config.hpp +++ b/src/config/config.hpp @@ -17,4 +17,7 @@ struct Config { General general; }; -Config get_config(const std::string &CONFIG_FILE); +// @brief Load config into `Config` struct +// @param CONFIGURATION content of `.toml` file containing configuration +// @return Config with parsed configuration +Config get_config(const std::string &CONFIGURATION); diff --git a/src/format/format.cpp b/src/format/format.cpp index 5bf4f23..68516de 100644 --- a/src/format/format.cpp +++ b/src/format/format.cpp @@ -1,6 +1,4 @@ #include "markdown/markdown.hpp" -#include -#include #include static bool replace_once(std::string &str, const std::string &from, @@ -11,20 +9,3 @@ static bool replace_once(std::string &str, const std::string &from, str.replace(start_pos, from.length(), to); return true; } - -std::string inject_html_into_template(const std::string &FILE_NAME, - const std::string &TEMPLATE, - const std::string &HTML) { - std::string result; - std::ifstream file(FILE_NAME); - if (!file.is_open()) { - return ""; - } - std::ostringstream ss; - ss << file.rdbuf(); - result = ss.str(); - if (replace_once(result, TEMPLATE, HTML)) { - return result; - } - return ""; -} diff --git a/src/markdown/markdown.cpp b/src/markdown/markdown.cpp index 34bf0c5..81790c5 100644 --- a/src/markdown/markdown.cpp +++ b/src/markdown/markdown.cpp @@ -1,6 +1,5 @@ #include "markdown.hpp" #include -#include #include #include #include @@ -8,21 +7,21 @@ #include #include -std::optional get_metadata(const std::string &FILE_PATH) { - std::fstream file(FILE_PATH); +std::optional get_metadata(const std::string &FILE_CONTENTS) { + std::stringstream file_contents(FILE_CONTENTS); std::stringstream metadata_s; std::string buffer; /* if there's no ---, then no metadata in file there is */ - if (!getline(file, buffer) || buffer != "---") { - std::cerr << "File " << FILE_PATH << " does not contain metadata. " + if (!getline(file_contents, buffer) || buffer != "---") { + std::clog << "File does not contain any metadata. Is this intentional?" << std::endl; return std::nullopt; } std::map metadata_map; - while (getline(file, buffer)) { + while (getline(file_contents, buffer)) { if (buffer == "---") { break; } @@ -69,15 +68,15 @@ static void html_callback(const MD_CHAR *data, MD_SIZE size, void *userdata) { out->append(data, size); } -std::string get_html(const std::string &FILE_PATH) { - std::fstream file(FILE_PATH); +std::string get_html(const std::string &FILE_CONTENTS) { + std::stringstream file_contents(FILE_CONTENTS); std::string buffer, file_string, out; - getline(file, buffer); + getline(file_contents, buffer); bool is_metadata = buffer == "---"; /* skip metadata */ if (is_metadata) { - while (getline(file, buffer)) { + while (getline(file_contents, buffer)) { if (buffer == "---") { break; } @@ -86,7 +85,7 @@ std::string get_html(const std::string &FILE_PATH) { file_string += buffer + '\n'; } - while (getline(file, buffer)) { + while (getline(file_contents, buffer)) { file_string += buffer + '\n'; }