stamdStatic Markdown Page Generator |
git clone git://git.dimitrijedobrota.com/stamd.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING |
article.hpp (1669B)
0 #pragma once 1 2 #include <optional> 3 #include <set> 4 #include <string> 5 #include <unordered_map> 6 7 #include <hemplate/html.hpp> 8 9 #include "options.hpp" 10 11 namespace stamd 12 { 13 14 class Article 15 { 16 public: 17 using symbols_t = std::unordered_map<std::string, std::string>; 18 using categories_t = std::set<std::string>; 19 20 explicit Article( 21 std::string filename, options_t options, categories_t categories = {} 22 ) 23 : m_filename(std::move(filename)) 24 , m_categories(std::move(categories)) 25 , m_options(std::move(options)) 26 { 27 } 28 29 using content_t = std::function<hemplate::element()>; 30 hemplate::element write(const content_t& content) const; 31 32 void insert(const std::string& category) { m_categories.emplace(category); } 33 void insert(const std::string& key, const std::string& value) 34 { 35 m_symbols.insert_or_assign(key, value); 36 } 37 38 auto get_categories() const { return m_categories; } 39 40 void set_hidden() { m_hidden = true; } 41 void set_nonav() { m_nonav = true; } 42 43 bool is_hidden() const { return m_hidden; } 44 45 std::optional<std::string> get(const std::string& key) const; 46 47 std::string get_filename() const; 48 std::string get_date() const; 49 std::string get_title() const; 50 std::string get_language() const; 51 std::string get_desciprtion() const; 52 std::string get_author() const; 53 std::string get_keywords() const; 54 55 private: 56 static hemplate::element print_nav(const std::string& base); 57 static hemplate::element print_categories(const categories_t& categories); 58 59 bool m_hidden = false; 60 bool m_nonav = false; 61 62 std::string m_filename; 63 categories_t m_categories; 64 options_t m_options; 65 symbols_t m_symbols; 66 }; 67 68 } // namespace stamd