mirror of
https://github.com/szymon-jozef/static-site-generator.git
synced 2026-09-07 20:20:41 +02:00
Merge pull request #6 from szymon-jozef/refactor/reorganize
refactor/reorganize
This commit is contained in:
4
.gitignore
vendored
4
.gitignore
vendored
@@ -1,4 +1,6 @@
|
|||||||
out/
|
out/
|
||||||
posts/
|
posts/
|
||||||
src/tests/tests
|
src/build/
|
||||||
|
/src/blog
|
||||||
|
/src/tests
|
||||||
*.o
|
*.o
|
||||||
|
|||||||
74
src/compile_commands.json
Normal file
74
src/compile_commands.json
Normal file
@@ -0,0 +1,74 @@
|
|||||||
|
[
|
||||||
|
{
|
||||||
|
"file": "main.cpp",
|
||||||
|
"arguments": [
|
||||||
|
"g++",
|
||||||
|
"-std=c++17",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-O2",
|
||||||
|
"-I",
|
||||||
|
".",
|
||||||
|
"-c",
|
||||||
|
"main.cpp",
|
||||||
|
"-o",
|
||||||
|
"build/main.o"
|
||||||
|
],
|
||||||
|
"directory": "/home/szymon/Dokumenty/kodowanie/blog/src",
|
||||||
|
"output": "build/main.o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "config/config.cpp",
|
||||||
|
"arguments": [
|
||||||
|
"g++",
|
||||||
|
"-std=c++17",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-O2",
|
||||||
|
"-I",
|
||||||
|
".",
|
||||||
|
"-c",
|
||||||
|
"config/config.cpp",
|
||||||
|
"-o",
|
||||||
|
"build/config/config.o"
|
||||||
|
],
|
||||||
|
"directory": "/home/szymon/Dokumenty/kodowanie/blog/src",
|
||||||
|
"output": "build/config/config.o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "format/format.cpp",
|
||||||
|
"arguments": [
|
||||||
|
"g++",
|
||||||
|
"-std=c++17",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-O2",
|
||||||
|
"-I",
|
||||||
|
".",
|
||||||
|
"-c",
|
||||||
|
"format/format.cpp",
|
||||||
|
"-o",
|
||||||
|
"build/format/format.o"
|
||||||
|
],
|
||||||
|
"directory": "/home/szymon/Dokumenty/kodowanie/blog/src",
|
||||||
|
"output": "build/format/format.o"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"file": "markdown/markdown.cpp",
|
||||||
|
"arguments": [
|
||||||
|
"g++",
|
||||||
|
"-std=c++17",
|
||||||
|
"-Wall",
|
||||||
|
"-Wextra",
|
||||||
|
"-O2",
|
||||||
|
"-I",
|
||||||
|
".",
|
||||||
|
"-c",
|
||||||
|
"markdown/markdown.cpp",
|
||||||
|
"-o",
|
||||||
|
"build/markdown/markdown.o"
|
||||||
|
],
|
||||||
|
"directory": "/home/szymon/Dokumenty/kodowanie/blog/src",
|
||||||
|
"output": "build/markdown/markdown.o"
|
||||||
|
}
|
||||||
|
]
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "markdown.hpp"
|
#include "markdown/markdown.hpp"
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
#include <string>
|
#include <string>
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
#include "config.hpp"
|
#include "config/config.hpp"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
|
|||||||
60
src/makefile
60
src/makefile
@@ -1,37 +1,51 @@
|
|||||||
CXX = g++
|
CXX = g++
|
||||||
CXXFLAGS = -std=c++17 -Wall
|
CXXFLAGS = -std=c++17 -Wall -Wextra -O2 -I .
|
||||||
TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2
|
|
||||||
LIBS = -lmd4c-html
|
LIBS = -lmd4c-html
|
||||||
TEST_DIR = tests
|
TEST_LIBS = -lmd4c-html -lCatch2Main -lCatch2
|
||||||
|
|
||||||
all: blog
|
BUILD_DIR = build
|
||||||
|
|
||||||
blog: main.o config.o utils.o
|
SOURCES = main.cpp \
|
||||||
$(CXX) $(CXXFLAGS) main.o config.o -o blog $(LIBS)
|
config/config.cpp \
|
||||||
|
format/format.cpp \
|
||||||
|
markdown/markdown.cpp
|
||||||
|
|
||||||
main.o: main.cpp config.hpp
|
OBJECTS = $(SOURCES:%.cpp=$(BUILD_DIR)/%.o)
|
||||||
$(CXX) $(CXXFLAGS) -c main.cpp
|
|
||||||
|
|
||||||
config.o: config.cpp config.hpp
|
TEST_SOURCES = tests.cpp \
|
||||||
$(CXX) $(CXXFLAGS) -c config.cpp
|
config/config.cpp \
|
||||||
|
format/format.cpp \
|
||||||
|
markdown/markdown.cpp
|
||||||
|
|
||||||
utils.o: utils.cpp utils.hpp
|
TEST_OBJECTS = $(TEST_SOURCES:%.cpp=$(BUILD_DIR)/%.o)
|
||||||
$(CXX) $(CXXFLAGS) -c utils.cpp
|
|
||||||
|
|
||||||
markdown.o: markdown.cpp markdown.hpp
|
TARGET = blog
|
||||||
$(CXX) $(CXXFLAGS) -c markdown.cpp
|
TEST_TARGET = tests
|
||||||
|
|
||||||
formatter.o: formatter.cpp formatter.hpp
|
.PHONY: all clean test directories
|
||||||
$(CXX) $(CXXFLAGS) -c formatter.cpp
|
|
||||||
|
|
||||||
tests.o: $(TEST_DIR)/tests.cpp config.hpp
|
all: directories $(TARGET)
|
||||||
$(CXX) $(CXXFLAGS) -c $(TEST_DIR)/tests.cpp
|
|
||||||
|
|
||||||
tests: tests.o config.o utils.o markdown.o formatter.o
|
directories:
|
||||||
g++ -std=c++17 -Wall tests.o config.o utils.o markdown.o formatter.o -o $(TEST_DIR)/tests $(TEST_LIBS)
|
@mkdir -p $(BUILD_DIR)/config
|
||||||
|
@mkdir -p $(BUILD_DIR)/format
|
||||||
|
@mkdir -p $(BUILD_DIR)/markdown
|
||||||
|
|
||||||
check: tests
|
$(TARGET): $(OBJECTS)
|
||||||
$(TEST_DIR)/tests
|
$(CXX) $(CXXFLAGS) -o $@ $^ $(LIBS)
|
||||||
|
|
||||||
|
$(TEST_TARGET): $(TEST_OBJECTS)
|
||||||
|
$(CXX) $(CXXFLAGS) -o $@ $^ $(TEST_LIBS)
|
||||||
|
|
||||||
|
$(BUILD_DIR)/%.o: %.cpp
|
||||||
|
@mkdir -p $(dir $@)
|
||||||
|
$(CXX) $(CXXFLAGS) -c $< -o $@
|
||||||
|
|
||||||
|
test: directories $(TEST_TARGET)
|
||||||
|
./$(TEST_TARGET)
|
||||||
|
|
||||||
clean:
|
clean:
|
||||||
rm -f *.o $(TEST_DIR)/*.o blog $(TEST_DIR)/tests
|
rm -rf $(BUILD_DIR)
|
||||||
|
rm -f $(TARGET) $(TEST_TARGET)
|
||||||
|
|
||||||
|
rebuild: clean all
|
||||||
|
|||||||
@@ -1,5 +1,4 @@
|
|||||||
#include "markdown.hpp"
|
#include "markdown.hpp"
|
||||||
#include "utils.hpp"
|
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
Before Width: | Height: | Size: 290 KiB After Width: | Height: | Size: 290 KiB |
@@ -1,7 +1,6 @@
|
|||||||
#include "../config.hpp"
|
#include "config/config.hpp"
|
||||||
#include "../formatter.hpp"
|
#include "format/format.hpp"
|
||||||
#include "../markdown.hpp"
|
#include "markdown/markdown.hpp"
|
||||||
#include "../utils.hpp"
|
|
||||||
#include <catch2/catch_all.hpp>
|
#include <catch2/catch_all.hpp>
|
||||||
#include <catch2/catch_test_macros.hpp>
|
#include <catch2/catch_test_macros.hpp>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
@@ -9,7 +8,7 @@
|
|||||||
#include <string>
|
#include <string>
|
||||||
|
|
||||||
TEST_CASE("Checking config file read", "[config]") {
|
TEST_CASE("Checking config file read", "[config]") {
|
||||||
const std::string FILE_NAME = "tests/config.toml";
|
const std::string FILE_NAME = "test_files/config.toml";
|
||||||
|
|
||||||
Config config = get_config(FILE_NAME);
|
Config config = get_config(FILE_NAME);
|
||||||
|
|
||||||
@@ -21,7 +20,7 @@ TEST_CASE("Checking config file read", "[config]") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("get_metadata function data correctness test") {
|
TEST_CASE("get_metadata function data correctness test") {
|
||||||
const std::string FILE_NAME = "./tests/post.md";
|
const std::string FILE_NAME = "./test_files/post.md";
|
||||||
Metadata result = get_metadata(FILE_NAME).value();
|
Metadata result = get_metadata(FILE_NAME).value();
|
||||||
|
|
||||||
std::string expected_author = "joseph";
|
std::string expected_author = "joseph";
|
||||||
@@ -42,13 +41,13 @@ TEST_CASE("get_metadata function data correctness test") {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("get_metadata function test with a file that doesn't have metadata") {
|
TEST_CASE("get_metadata function test with a file that doesn't have metadata") {
|
||||||
const std::string FILE_NAME = ".tests/no_metadata_post.md";
|
const std::string FILE_NAME = ".test_files/no_metadata_post.md";
|
||||||
std::optional<Metadata> result = get_metadata(FILE_NAME);
|
std::optional<Metadata> result = get_metadata(FILE_NAME);
|
||||||
REQUIRE(result == std::nullopt);
|
REQUIRE(result == std::nullopt);
|
||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("get_html function parsing test") {
|
TEST_CASE("get_html function parsing test") {
|
||||||
const std::string INPUT = "./tests/post.md";
|
const std::string INPUT = "./test_files/post.md";
|
||||||
const std::string EXPECTED_OUTPUT = R"HTML(<h1>This is an example post</h1>
|
const std::string EXPECTED_OUTPUT = R"HTML(<h1>This is an example post</h1>
|
||||||
<p>In this example we will do a couple of cool markdown things.</p>
|
<p>In this example we will do a couple of cool markdown things.</p>
|
||||||
<h2>This is a h2 header</h2>
|
<h2>This is a h2 header</h2>
|
||||||
@@ -86,7 +85,7 @@ int main() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
TEST_CASE("formatter injection test") {
|
TEST_CASE("formatter injection test") {
|
||||||
const std::string FILE_NAME = "./tests/formatter.html";
|
const std::string FILE_NAME = "./test_files/formatter.html";
|
||||||
const std::string EXPECTED_OUTPUT = R"(<!DOCTYPE html>
|
const std::string EXPECTED_OUTPUT = R"(<!DOCTYPE html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
@@ -1,10 +0,0 @@
|
|||||||
#include <set>
|
|
||||||
#include <sstream>
|
|
||||||
#include <string>
|
|
||||||
|
|
||||||
void trim(std::string &str) {
|
|
||||||
str.erase(str.find_last_not_of(' ') + 1);
|
|
||||||
str.erase(0, str.find_first_not_of(' '));
|
|
||||||
str.erase(str.find_last_not_of('"') + 1);
|
|
||||||
str.erase(0, str.find_first_not_of('"'));
|
|
||||||
}
|
|
||||||
@@ -1,4 +0,0 @@
|
|||||||
#include <string>
|
|
||||||
|
|
||||||
// trim string in-place, removing all whitespaces and surrounding '"' symbols
|
|
||||||
void trim(std::string &str);
|
|
||||||
Reference in New Issue
Block a user