stamd

Static Markdown Page Generator
git clone git://git.dimitrijedobrota.com/stamd.git
Log | Files | Refs | README | LICENSE

article.hpp (1433B)


      1 #pragma once
      2 
      3 #include <optional>
      4 #include <set>
      5 #include <string>
      6 #include <unordered_map>
      7 #include <vector>
      8 
      9 namespace stamd {
     10 
     11 class article
     12 {
     13 public:
     14   using symbols_t    = std::unordered_map<std::string, std::string>;
     15   using categories_t = std::set<std::string>;
     16 
     17   explicit article(std::string filename, categories_t categories = {})
     18       : m_categories(std::move(categories))
     19       , m_symbols({{"filename", filename}})
     20   {
     21   }
     22 
     23   void write_header(std::ostream& ost) const;
     24   void write_footer(std::ostream& ost) const;
     25 
     26   void insert(const std::string& category) { m_categories.emplace(category); }
     27   void insert(const std::string& key, const std::string& value)
     28   {
     29     m_symbols.insert_or_assign(key, value);
     30   }
     31 
     32   auto get_categories() const { return m_categories; }
     33 
     34   void set_hidden(bool state) { m_hidden = state; }
     35   void set_nonav(bool state) { m_nonav = state; }
     36 
     37   bool is_hidden() const { return m_hidden; }
     38 
     39   std::optional<std::string> get(const std::string& key) const;
     40 
     41   std::string get_filename() const;
     42   std::string get_date() const;
     43   std::string get_title() const;
     44   std::string get_language() const;
     45 
     46 private:
     47   static void print_nav(std::ostream& ost);
     48   static void print_categories(std::ostream& ost,
     49                                const categories_t& categories);
     50 
     51   bool m_hidden = false;
     52   bool m_nonav  = false;
     53 
     54   categories_t m_categories;
     55   symbols_t m_symbols;
     56 };
     57 
     58 }  // namespace stamd