stamd

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

commitcb91fd3a2930f24272da2bd9a260bc1ace838322
parent68acb3567a5817c6f1545d11b6c7d74497d8a0e4
authorDimitrije Dobrota <mail@dimitrijedobrota.com>
dateSat, 4 Jan 2025 18:48:23 +0100

Add author and keywords meta tags

Diffstat:
MCMakeLists.txt|+-
Msource/article.cpp|+++++++++++++++++++++++++++++++++++++++++++++++++---------------------------------
Msource/article.hpp|++++++--

3 files changed, 61 insertions(+), 39 deletions(-)


diff --git a/CMakeLists.txt b/CMakeLists.txt

@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)

project(
stamd
VERSION 0.3.0
VERSION 0.3.1
DESCRIPTION "Static Markdown Page Generator"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/stamd.git"
LANGUAGES CXX

diff --git a/source/article.cpp b/source/article.cpp

@@ -1,6 +1,7 @@

#include <format>
#include <iostream>
#include <iterator>
#include <numeric>
#include <optional>
#include <string>

@@ -26,7 +27,7 @@ std::optional<std::string> Article::get(const std::string& key) const

std::string Article::get_filename() const
{
return m_symbols.find("filename")->second;
return m_filename;
}
std::string Article::get_date() const

@@ -44,6 +45,31 @@ std::string Article::get_language() const

return get("language").value_or("en");
}
std::string Article::get_desciprtion() const
{
return get("description").value_or(m_options.description);
}
std::string Article::get_author() const
{
return get("author").value_or(m_options.author);
}
std::string Article::get_keywords() const
{
static const auto concat = [](const categories_t& categories)
{
if (categories.empty()) return std::string();
return std::accumulate(std::next(std::begin(categories)),
std::end(categories),
*categories.begin(),
[](const auto& acc, const auto& str)
{ return acc + ", " + str; });
};
return get("keywords").value_or(concat(m_categories));
}
void Article::print_nav(std::ostream& ost, const std::string& base)
{
using namespace hemplate; // NOLINT

@@ -76,48 +102,40 @@ void Article::write_header(std::ostream& ost) const

{
using namespace hemplate; // NOLINT
static const char* description_s =
"Dimitrije Dobrota's personal site. You can find my daily "
"findings in a "
"form of articles on my blog as well as various programming "
"projects.";
static const attributeList icon = {{"rel", "icon"}, {"type", "image/png"}};
static const attributeList style = {{"rel", "stylesheet"},
{"type", "text/css"}};
static const attributeList viewport = {
{"content", "width=device-width, initial-scale=1"},
{"name", "viewport"}};
static const attributeList description = {{"name", "description"},
{"content", description_s}};
static const attributeList rss = {{"rel", "alternate"},
{"type", "application/atom+xml"},
{"title", "RSS feed"},
{"href", "/blog/rss.xml"}};
static const attributeList atom = {{"rel", "alternate"},
{"type", "application/atom+xml"},
{"title", "Atom feed"},
{"href", "/blog/atom.xml"}};
ost << html::doctype();
ost << html::html().set("lang", get_language());
ost << html::head()
.add(html::title(get_title()))
.add(html::meta(viewport))
// Meta tags
.add(html::meta({{"charset", "UTF-8"}}))
.add(html::meta(description))
.add(html::link(style).set("href", "/css/index.css"))
.add(html::link(style).set("href", "/css/colors.css"))
.add(html::link(rss))
.add(html::link(atom))
.add(html::link(icon)
.add(html::meta({{"name", "author"}, {"content", get_author()}}))
.add(html::meta(
{{"name", "description"}, {"content", get_desciprtion()}}))
.add(html::meta(
{{"name", "keywords"}, {"content", get_keywords()}}))
.add(html::meta(
{{"content", "width=device-width, initial-scale=1"},
{"name", "viewport"}}))
// Stylesheets
.add(html::link({{"rel", "stylesheet"}, {"type", "text/css"}})
.set("href", "/css/index.css"))
.add(html::link({{"rel", "stylesheet"}, {"type", "text/css"}})
.set("href", "/css/colors.css"))
// Rss feed
.add(html::link({{"rel", "alternate"},
{"type", "application/atom+xml"},
{"title", "RSS feed"},
{"href", "/blog/rss.xml"}}))
// Atom feed
.add(html::link({{"rel", "alternate"},
{"type", "application/atom+xml"},
{"title", "Atom feed"},
{"href", "/blog/atom.xml"}}))
// Icons
.add(html::link({{"rel", "icon"}, {"type", "image/png"}})
.set("sizes", "32x32")
.set("href", "/img/favicon-32x32.png"))
.add(html::link(icon)
.add(html::link({{"rel", "icon"}, {"type", "image/png"}})
.set("sizes", "16x16")
.set("href", "/img/favicon-16x16.png"));

diff --git a/source/article.hpp b/source/article.hpp

@@ -18,9 +18,9 @@ public:

explicit Article(std::string filename,
options_t options,
categories_t categories = {})
: m_categories(std::move(categories))
: m_filename(std::move(filename))
, m_categories(std::move(categories))
, m_options(std::move(options))
, m_symbols({{"filename", filename}})
{
}

@@ -46,6 +46,9 @@ public:

std::string get_date() const;
std::string get_title() const;
std::string get_language() const;
std::string get_desciprtion() const;
std::string get_author() const;
std::string get_keywords() const;
private:
static void print_nav(std::ostream& ost, const std::string& base);

@@ -55,6 +58,7 @@ private:

bool m_hidden = false;
bool m_nonav = false;
std::string m_filename;
categories_t m_categories;
options_t m_options;
symbols_t m_symbols;