diff --git a/CMakeLists.txt b/CMakeLists.txt index df54c49..ac4b6bd 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -72,7 +72,6 @@ set_property(TARGET lmdb include_directories(${Boost_INCLUDE_DIRS}) include_directories("ext/mstch/include") - # add ext/ subfolder add_subdirectory(ext/) @@ -83,9 +82,25 @@ add_subdirectory(src/) set(SOURCE_FILES main.cpp) +ADD_CUSTOM_TARGET(driver DEPENDS src/templates/index.html) + add_executable(${PROJECT_NAME} ${SOURCE_FILES}) +#add_custom_command(OUTPUT template_folder +# COMMAND ${CMAKE_COMMAND} -E +# copy_directory "${CMAKE_CURRENT_SOURCE_DIR}/src/templates" "${CMAKE_CURRENT_BINARY_DIR}" +# DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/src/templates") +# +#add_custom_target(index_html +# ALL DEPENDS "${CMAKE_CURRENT_BINARY_DIR}/templates") +# +#ADD_DEPENDENCIES(${PROJECT_NAME} +# index_html) + +file(COPY "${CMAKE_CURRENT_SOURCE_DIR}/src/templates" + DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") + target_link_libraries(${PROJECT_NAME} myxrm myext diff --git a/main.cpp b/main.cpp index 0214043..1d64f92 100644 --- a/main.cpp +++ b/main.cpp @@ -42,16 +42,15 @@ int main() { fmt::print("\n\n" "Top block height : {:d}\n", height); - std::ifstream t("src/templates/index.html"); - std::string index_tmpl_str((std::istreambuf_iterator(t)), - std::istreambuf_iterator()); + + std::string view = xmreg::read("./templates/index.html"); mstch::map context { {"height", fmt::format("{:d}", height)}, {"blocks", mstch::array()} }; - size_t no_of_last_blocks {10}; + size_t no_of_last_blocks {50}; mstch::array& blocks = boost::get(context["blocks"]); @@ -72,7 +71,7 @@ int main() { CROW_ROUTE(app, "/") ([&]() { - return mstch::render(index_tmpl_str, context); + return mstch::render(view, context); }); app.port(8080).multithreaded().run(); diff --git a/src/templates/index.html b/src/templates/index.html index 9f4367f..03b5e94 100644 --- a/src/templates/index.html +++ b/src/templates/index.html @@ -6,11 +6,15 @@
-

{{height}}

+

Detailed Monero blockchain explorer

+

Current height: {{height}}

- {{#blocks}} - {{height}}: {{hash}} - {{/blocks}} +
    + {{#blocks}} +
  • {{height}}: {{hash}}
  • + {{/blocks}} +
+
diff --git a/src/tools.cpp b/src/tools.cpp index 9e27756..a0a72e8 100644 --- a/src/tools.cpp +++ b/src/tools.cpp @@ -334,4 +334,18 @@ namespace xmreg }; + string + read(string filename) + { + if (!bf::exists(bf::path(filename))) + { + return string(); + } + + std::ifstream t("./templates/index.html"); + return string(std::istreambuf_iterator(t), + std::istreambuf_iterator()); + } + + } diff --git a/src/tools.h b/src/tools.h index f8be91d..fdbf01c 100644 --- a/src/tools.h +++ b/src/tools.h @@ -144,6 +144,9 @@ namespace xmreg array timestamp_difference(uint64_t t1, uint64_t t2); + string + read(string filename); + } #endif //XMREG01_TOOLS_H