stamd

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

article.hpp (1713B)


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