aboutsummaryrefslogtreecommitdiff
path: root/src/content/markdown
diff options
context:
space:
mode:
Diffstat (limited to 'src/content/markdown')
-rw-r--r--src/content/markdown/Markdown.cpp47
-rw-r--r--src/content/markdown/Markdown.hpp11
2 files changed, 49 insertions, 9 deletions
diff --git a/src/content/markdown/Markdown.cpp b/src/content/markdown/Markdown.cpp
index 2009772..63358b4 100644
--- a/src/content/markdown/Markdown.cpp
+++ b/src/content/markdown/Markdown.cpp
@@ -1,7 +1,10 @@
#include "Markdown.hpp"
-Markdown::Markdown(std::string uriBasePath, std::string markdownFilesPath)
- : Content(), m_UriBasePath(uriBasePath), m_MainTemplatePath(""), m_MarkdownFilesPath(markdownFilesPath)
+Markdown::Markdown(std::string uriBasePath, std::string markdownFilesPath, std::string mainTemplatePath)
+ : Content(),
+ m_UriBasePath(uriBasePath),
+ m_MainTemplatePath(mainTemplatePath),
+ m_MarkdownFilesPath(markdownFilesPath)
{
}
@@ -11,11 +14,18 @@ bool Markdown::Init()
std::vector<std::string> extensions = {"md"};
- if (m_MarkdownFiles.Scan(m_MarkdownFilesPath, extensions, false) == false)
+ Filesystem fs;
+ if (fs.Scan(m_MarkdownFilesPath, extensions, false) == false)
{
return false;
}
+ for (auto const & mfile : fs.GetFiles())
+ {
+ m_Markdowns[mfile.first] =
+ std::make_shared<std::string>(std::string(mfile.second.data.begin(), mfile.second.data.end()));
+ }
+
return true;
}
@@ -26,13 +36,16 @@ void Markdown::Shutdown()
bool Markdown::Render(RequestResponse & rr, RenderData & rd, std::string & out)
{
+ (void)rr;
+ (void)rd;
(void)out;
- rd["blub"] = "Yoh21!";
- rr.UseOutputHeader();
- rr.AddOutputHeader("blaaaa", "blubb");
+ if (m_MainTemplatePath.empty() == true)
+ {
+ return false;
+ }
- return true;
+ return false; /* TODO: Make markdown module usable as standalone module?! */
}
std::string const & Markdown::GetUriBasePath() const
@@ -49,3 +62,23 @@ Redirections const & Markdown::GetRedirections() const
{
return m_Redirections;
}
+
+bool Markdown::HasMarkdownFile(std::string filePath) const
+{
+ return m_Markdowns.find(filePath) != m_Markdowns.end();
+}
+
+bool Markdown::HasMarkdownURI(std::string uriPath) const
+{
+ return HasMarkdownFile(uriPath.substr(m_UriBasePath.length() + 1, std::string::npos));
+}
+
+Markdowns const & Markdown::GetMarkdowns() const
+{
+ return m_Markdowns;
+}
+
+std::shared_ptr<std::string> const & Markdown::GetMarkdownHTML(std::string uriPath)
+{
+ return m_Markdowns[uriPath];
+}
diff --git a/src/content/markdown/Markdown.hpp b/src/content/markdown/Markdown.hpp
index 41c8b4d..9c4d3c4 100644
--- a/src/content/markdown/Markdown.hpp
+++ b/src/content/markdown/Markdown.hpp
@@ -4,10 +4,12 @@
#include "../../Content.hpp"
#include "../../Filesystem.hpp"
+using Markdowns = std::unordered_map<std::string, std::shared_ptr<std::string> >;
+
class Markdown : public Content
{
public:
- explicit Markdown(std::string uriBasePath, std::string markdownFilesPath);
+ explicit Markdown(std::string uriBasePath, std::string markdownFilesPath, std::string mainTemplatePath = "");
bool Init();
void Shutdown();
@@ -17,12 +19,17 @@ public:
std::string const & GetMainTemplate() const;
Redirections const & GetRedirections() const;
+ bool HasMarkdownFile(std::string filePath) const;
+ bool HasMarkdownURI(std::string uriPath) const;
+ Markdowns const & GetMarkdowns() const;
+ std::shared_ptr<std::string> const & GetMarkdownHTML(std::string uriPath);
+
private:
std::string m_UriBasePath;
std::string m_MainTemplatePath;
std::string m_MarkdownFilesPath;
Redirections m_Redirections;
- Filesystem m_MarkdownFiles;
+ Markdowns m_Markdowns;
};
#endif