From 8c2089dd8117835cfbfaed2c8f50cd34e666487f Mon Sep 17 00:00:00 2001 From: Toni Uhlig <matzeton@googlemail.com> Date: Mon, 25 Oct 2021 14:35:32 +0200 Subject: Added CMake install targets and reworked wwwroot folder structure. Signed-off-by: Toni Uhlig <matzeton@googlemail.com> --- CMakeLists.txt | 11 +++++++++++ blog/my-second-blog-entry.json | 8 -------- blog/my-second-blog-entry.md | 5 ----- blog/my-third-blog-entry.json | 8 -------- blog/my-third-blog-entry.md | 2 -- blog/my-very-first-blog-entry.json | 8 -------- blog/my-very-first-blog-entry.md | 8 -------- pages/index.md | 2 -- src/main.cpp | 28 +++++++++------------------- wwwroot/blog/my-second-blog-entry.json | 8 ++++++++ wwwroot/blog/my-second-blog-entry.md | 5 +++++ wwwroot/blog/my-third-blog-entry.json | 8 ++++++++ wwwroot/blog/my-third-blog-entry.md | 2 ++ wwwroot/blog/my-very-first-blog-entry.json | 8 ++++++++ wwwroot/blog/my-very-first-blog-entry.md | 8 ++++++++ wwwroot/pages/index.md | 2 ++ wwwroot/static/test.txt | 1 + 17 files changed, 62 insertions(+), 60 deletions(-) delete mode 100644 blog/my-second-blog-entry.json delete mode 100644 blog/my-second-blog-entry.md delete mode 100644 blog/my-third-blog-entry.json delete mode 100644 blog/my-third-blog-entry.md delete mode 100644 blog/my-very-first-blog-entry.json delete mode 100644 blog/my-very-first-blog-entry.md delete mode 100644 pages/index.md create mode 100644 wwwroot/blog/my-second-blog-entry.json create mode 100644 wwwroot/blog/my-second-blog-entry.md create mode 100644 wwwroot/blog/my-third-blog-entry.json create mode 100644 wwwroot/blog/my-third-blog-entry.md create mode 100644 wwwroot/blog/my-very-first-blog-entry.json create mode 100644 wwwroot/blog/my-very-first-blog-entry.md create mode 100644 wwwroot/pages/index.md create mode 100644 wwwroot/static/test.txt diff --git a/CMakeLists.txt b/CMakeLists.txt index 1de9b72..6494836 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,14 @@ cmake_minimum_required(VERSION 3.1.9) project(cpp-web) +set(CPACK_PACKAGE_CONTACT "toni@impl.cc") +set(CPACK_DEBIAN_PACKAGE_NAME "cpp-web") +set(CPACK_DEBIAN_PACKAGE_SHLIBDEPS ON) +set(CPACK_PACKAGE_VERSION_MAJOR 1) +set(CPACK_PACKAGE_VERSION_MINOR 0) + +include(CPack) + set(CMAKE_CXX_FLAGS "-Wall -Wextra -std=c++17") set(CMAKE_CXX_FLAGS_DEBUG "-g3 -fpic -fno-omit-frame-pointer -fno-rtti -ffunction-sections -fdata-sections -fsanitize=address -fsanitize=leak") set(CMAKE_CXX_FLAGS_RELEASE "-Os -fpic -fomit-frame-pointer -ffunction-sections -fdata-sections -flto") @@ -33,3 +41,6 @@ if(CMAKE_BUILD_TYPE MATCHES Release) set_target_properties(cpp-web PROPERTIES LINK_FLAGS "-no-pie -flto -Wl,--gc-sections -Wl,-z,norelro -Wl,--hash-style=gnu -Wl,--build-id=none") endif() target_link_libraries(cpp-web stdc++fs pthread event magic) + +install(TARGETS cpp-web RUNTIME DESTINATION bin) +install(DIRECTORY ${PROJECT_SOURCE_DIR}/wwwroot/ DESTINATION ${CMAKE_INSTALL_PREFIX}/share/cpp-web/wwwroot) diff --git a/blog/my-second-blog-entry.json b/blog/my-second-blog-entry.json deleted file mode 100644 index ecb2b8b..0000000 --- a/blog/my-second-blog-entry.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "title": "Second blog entry.", - "tags": [ "bla" ], - "author": "lns", - "createDate": "23.02.1989 23:59", - "publishDate": "30.12.2020 1:00", - "published": true -} diff --git a/blog/my-second-blog-entry.md b/blog/my-second-blog-entry.md deleted file mode 100644 index 054046a..0000000 --- a/blog/my-second-blog-entry.md +++ /dev/null @@ -1,5 +0,0 @@ -Text -======= - -*lorem* **ipsum** -~~striked~~ diff --git a/blog/my-third-blog-entry.json b/blog/my-third-blog-entry.json deleted file mode 100644 index 9682cd2..0000000 --- a/blog/my-third-blog-entry.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "title": "Third.", - "tags": [ "test" ], - "author": "lns", - "createDate": "24.02.1989 23:59", - "publishDate": "31.12.2020 1:00", - "published": false -} diff --git a/blog/my-third-blog-entry.md b/blog/my-third-blog-entry.md deleted file mode 100644 index 292b1e1..0000000 --- a/blog/my-third-blog-entry.md +++ /dev/null @@ -1,2 +0,0 @@ -Text -======= diff --git a/blog/my-very-first-blog-entry.json b/blog/my-very-first-blog-entry.json deleted file mode 100644 index 52f52f7..0000000 --- a/blog/my-very-first-blog-entry.json +++ /dev/null @@ -1,8 +0,0 @@ -{ - "title": "My first blog entry!", - "tags": [ "test", "bla" ], - "author": "lns", - "createDate": "22.02.1989 23:59", - "publishDate": "31.12.2020 1:00", - "published": true -} diff --git a/blog/my-very-first-blog-entry.md b/blog/my-very-first-blog-entry.md deleted file mode 100644 index 017cbfc..0000000 --- a/blog/my-very-first-blog-entry.md +++ /dev/null @@ -1,8 +0,0 @@ -Text -======= - -`test` - -``` -some code... -``` diff --git a/pages/index.md b/pages/index.md deleted file mode 100644 index 99bd385..0000000 --- a/pages/index.md +++ /dev/null @@ -1,2 +0,0 @@ -*Just HTML* -~~plaintext~~ diff --git a/src/main.cpp b/src/main.cpp index 61407d8..8256717 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -19,7 +19,7 @@ int main(int argc, char ** argv) if (argc <= 1 || argc > 5) { - std::cout << "usage: cpp-web [HOST] [PORT] [STATIC-WWWROOT] [DYNAMIC-WWWROOT]" << std::endl; + std::cout << "usage: cpp-web [HOST] [PORT] [WWWROOT]" << std::endl; if (argc > 5) { return 1; @@ -34,6 +34,10 @@ int main(int argc, char ** argv) { port = atoi(argv[2]); } + if (argc > 3) + { + wwwroot = argv[3]; + } std::shared_ptr<TemplateManager> tmgr = std::make_shared<TemplateManager>(); std::shared_ptr<ContentManager> cmgr = std::make_shared<ContentManager>(); @@ -41,36 +45,22 @@ int main(int argc, char ** argv) { std::shared_ptr<Filesystem> static_fs = std::make_shared<Filesystem>(); - if (argc > 3) - { - if (static_fs->Scan(argv[3]) != true) - { - return 1; - } - } - std::cout << "Static fs: " << wwwroot << std::endl; - static_fs->Scan(wwwroot, {"html", "tmpl"}, true); + std::cout << "Static fs: " << wwwroot + "/static" << std::endl; + static_fs->Scan(wwwroot + "/static", {"html", "tmpl"}, true); cmgr->RegisterModule(std::make_shared<Static>("/static", static_fs)); } { Filesystem dynamic_fs; - if (argc > 4) - { - if (dynamic_fs.Scan(argv[4]) != true) - { - return 1; - } - } std::cout << "Dynamic fs: " << wwwroot << std::endl; dynamic_fs.Scan(wwwroot, {"html", "tmpl"}, false); tmgr->ParseTemplates(dynamic_fs); } - cmgr->RegisterModule(std::make_shared<Markdown>("/", "./pages", "index.html")); - cmgr->RegisterModule(std::make_shared<Blog>("/blog", "./blog", "blog/index.html")); + cmgr->RegisterModule(std::make_shared<Markdown>("/", wwwroot + "/pages", "index.html")); + cmgr->RegisterModule(std::make_shared<Blog>("/blog", wwwroot + "/blog", "blog/index.html")); if (cmgr->InitAll() == false) { diff --git a/wwwroot/blog/my-second-blog-entry.json b/wwwroot/blog/my-second-blog-entry.json new file mode 100644 index 0000000..ecb2b8b --- /dev/null +++ b/wwwroot/blog/my-second-blog-entry.json @@ -0,0 +1,8 @@ +{ + "title": "Second blog entry.", + "tags": [ "bla" ], + "author": "lns", + "createDate": "23.02.1989 23:59", + "publishDate": "30.12.2020 1:00", + "published": true +} diff --git a/wwwroot/blog/my-second-blog-entry.md b/wwwroot/blog/my-second-blog-entry.md new file mode 100644 index 0000000..054046a --- /dev/null +++ b/wwwroot/blog/my-second-blog-entry.md @@ -0,0 +1,5 @@ +Text +======= + +*lorem* **ipsum** +~~striked~~ diff --git a/wwwroot/blog/my-third-blog-entry.json b/wwwroot/blog/my-third-blog-entry.json new file mode 100644 index 0000000..9682cd2 --- /dev/null +++ b/wwwroot/blog/my-third-blog-entry.json @@ -0,0 +1,8 @@ +{ + "title": "Third.", + "tags": [ "test" ], + "author": "lns", + "createDate": "24.02.1989 23:59", + "publishDate": "31.12.2020 1:00", + "published": false +} diff --git a/wwwroot/blog/my-third-blog-entry.md b/wwwroot/blog/my-third-blog-entry.md new file mode 100644 index 0000000..292b1e1 --- /dev/null +++ b/wwwroot/blog/my-third-blog-entry.md @@ -0,0 +1,2 @@ +Text +======= diff --git a/wwwroot/blog/my-very-first-blog-entry.json b/wwwroot/blog/my-very-first-blog-entry.json new file mode 100644 index 0000000..52f52f7 --- /dev/null +++ b/wwwroot/blog/my-very-first-blog-entry.json @@ -0,0 +1,8 @@ +{ + "title": "My first blog entry!", + "tags": [ "test", "bla" ], + "author": "lns", + "createDate": "22.02.1989 23:59", + "publishDate": "31.12.2020 1:00", + "published": true +} diff --git a/wwwroot/blog/my-very-first-blog-entry.md b/wwwroot/blog/my-very-first-blog-entry.md new file mode 100644 index 0000000..017cbfc --- /dev/null +++ b/wwwroot/blog/my-very-first-blog-entry.md @@ -0,0 +1,8 @@ +Text +======= + +`test` + +``` +some code... +``` diff --git a/wwwroot/pages/index.md b/wwwroot/pages/index.md new file mode 100644 index 0000000..99bd385 --- /dev/null +++ b/wwwroot/pages/index.md @@ -0,0 +1,2 @@ +*Just HTML* +~~plaintext~~ diff --git a/wwwroot/static/test.txt b/wwwroot/static/test.txt new file mode 100644 index 0000000..50bb49a --- /dev/null +++ b/wwwroot/static/test.txt @@ -0,0 +1 @@ +This is a static text file. -- cgit v1.2.3