mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-09-07 12:10:42 +02:00
moved all the file operation logic into io module
This commit is contained in:
BIN
src/.cache/clangd/index/config.cpp.A68A2AE9FDFA8117.idx
Normal file
BIN
src/.cache/clangd/index/config.cpp.A68A2AE9FDFA8117.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/config.hpp.C519F3A7E0A75094.idx
Normal file
BIN
src/.cache/clangd/index/config.hpp.C519F3A7E0A75094.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/format.cpp.047FF551BC8DE01E.idx
Normal file
BIN
src/.cache/clangd/index/format.cpp.047FF551BC8DE01E.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/main.cpp.AC604CCC20973D23.idx
Normal file
BIN
src/.cache/clangd/index/main.cpp.AC604CCC20973D23.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/markdown.cpp.A5D40F1BF5766683.idx
Normal file
BIN
src/.cache/clangd/index/markdown.cpp.A5D40F1BF5766683.idx
Normal file
Binary file not shown.
BIN
src/.cache/clangd/index/markdown.hpp.66A7ABFD738DA42D.idx
Normal file
BIN
src/.cache/clangd/index/markdown.hpp.66A7ABFD738DA42D.idx
Normal file
Binary file not shown.
@@ -5,10 +5,10 @@
|
||||
#include <toml++/impl/parser.hpp>
|
||||
#include <toml++/toml.hpp>
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
#include "markdown/markdown.hpp"
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
#include <string>
|
||||
|
||||
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 "";
|
||||
}
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "markdown.hpp"
|
||||
#include <ctime>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <map>
|
||||
#include <md4c-html.h>
|
||||
@@ -8,21 +7,21 @@
|
||||
#include <sstream>
|
||||
#include <toml++/toml.hpp>
|
||||
|
||||
std::optional<Metadata> get_metadata(const std::string &FILE_PATH) {
|
||||
std::fstream file(FILE_PATH);
|
||||
std::optional<Metadata> 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<std::string, std::string> 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';
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user