From f6250699a5464796693d6bb637e8cf6de26bbef5 Mon Sep 17 00:00:00 2001 From: radhitya Date: Thu, 25 Jun 2026 12:23:26 +0700 Subject: site config, frontmatter, readme --- CMakeLists.txt | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 62 insertions(+) create mode 100644 CMakeLists.txt (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..496b2cd --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,62 @@ +cmake_minimum_required(VERSION 3.20) +project(ahsi VERSION 0.1.0 LANGUAGES CXX C) + +set(CMAKE_CXX_STANDARD 20) +set(CMAKE_CXX_STANDARD_REQUIRED ON) +set(CMAKE_CXX_EXTENSIONS OFF) + +include(FetchContent) + +FetchContent_Declare( + tomlplusplus + GIT_REPOSITORY https://github.com/marzer/tomlplusplus.git + GIT_TAG v3.4.0 +) +FetchContent_MakeAvailable(tomlplusplus) + +FetchContent_Declare( + json + GIT_REPOSITORY https://github.com/nlohmann/json.git + GIT_TAG v3.11.3 +) +FetchContent_MakeAvailable(json) + +FetchContent_Declare( + inja + GIT_REPOSITORY https://github.com/pantor/inja.git + GIT_TAG v3.4.0 +) + +set(INJA_USE_EMBEDDED_JSON OFF CACHE BOOL "" FORCE) +set(INJA_BUILD_TESTS OFF CACHE BOOL "" FORCE) +set(BUILD_TESTING OFF CACHE BOOL "" FORCE) +set(BUILD_BENCHMARK OFF CACHE BOOL "" FORCE) +set(INJA_INSTALL OFF CACHE BOOL "" FORCE) + +FetchContent_MakeAvailable(inja) + +FetchContent_Declare( + cmark + GIT_REPOSITORY https://github.com/commonmark/cmark.git + GIT_TAG 0.31.1 +) +FetchContent_MakeAvailable(cmark) + +file(GLOB AHSI_SOURCES CONFIGURE_DEPENDS src/*.cpp) + +add_executable(ahsi ${AHSI_SOURCES}) + +target_include_directories(ahsi PRIVATE + src + ${tomlplusplus_SOURCE_DIR}/include + ${json_SOURCE_DIR}/include + ${inja_SOURCE_DIR}/include +) + +target_link_libraries(ahsi PRIVATE cmark) + +set_target_properties(ahsi PROPERTIES + VERSION ${PROJECT_VERSION} + OUTPUT_NAME "ahsi" +) + -- cgit v1.2.3 From 3e5f9473f963d1c33b4d817105ff8f32e32e521a Mon Sep 17 00:00:00 2001 From: radhitya Date: Thu, 25 Jun 2026 14:14:03 +0700 Subject: markdown processing + cmark --- CMakeLists.txt | 1 + src/main.cpp | 16 ++++++++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) (limited to 'CMakeLists.txt') diff --git a/CMakeLists.txt b/CMakeLists.txt index 496b2cd..947ebcd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -51,6 +51,7 @@ target_include_directories(ahsi PRIVATE ${tomlplusplus_SOURCE_DIR}/include ${json_SOURCE_DIR}/include ${inja_SOURCE_DIR}/include + ${cmark_SOURCE_DIR}/include ) target_link_libraries(ahsi PRIVATE cmark) diff --git a/src/main.cpp b/src/main.cpp index bffbe5f..0902b19 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include using namespace std::string_literals; struct MainConfig { @@ -18,6 +19,7 @@ struct FrontmatterConfig { std::string categories; std::string tags; bool draft; + std::string body; }; struct Config { @@ -75,10 +77,19 @@ frontmatter(const std::string& filepath) std::cerr << "parsing failed: " << err << std::endl; throw; } + cfg.frontmatter.body = content.substr(second_fence + 3); } return cfg; } +std::string +markdown_processing(const std::string& md) { + char *raw = cmark_markdown_to_html(md.c_str(), md.size(),0); + std::string html(raw); + free(raw); + return html; +} + int main(int argc, char *argv[]) { try { Config my_config = parse_config("config.toml"); @@ -89,11 +100,12 @@ int main(int argc, char *argv[]) { Config front = frontmatter(argv[1]); std::cout << "title page: " << front.frontmatter.title << std::endl; - std::cout << "title date: " << front.frontmatter.title << std::endl; + std::cout << "title date: " << front.frontmatter.date << std::endl; std::cout << "title categories: " << front.frontmatter.categories << std::endl; std::cout << "title tags: " << front.frontmatter.tags << std::endl; std::cout << "title draft: " << front.frontmatter.draft << std::endl; - + std::cout << "title body: " << markdown_processing(front.frontmatter.body) << std::endl; + } catch (const std::exception& e) { std::cerr << e.what() << std::endl; return 1; -- cgit v1.2.3