stamd

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

commit 4f9cded954e4bcb29d9dce3b9b24f461e9e6755f
parent 710ea86850e41ea1d189dfe53fa59a7f0d45be5d
Author: Dimitrije Dobrota <mail@dimitrijedobrota.com>
Date:   Thu, 27 Jun 2024 00:35:31 +0200

Include indexes in the sitemap

Diffstat:
MCMakeLists.txt | 2+-
Msource/index.cpp | 16+++++++++-------
Msource/index.hpp | 8++++----
Msource/main.cpp | 23+++++++++++++----------
4 files changed, 27 insertions(+), 22 deletions(-)

diff --git a/CMakeLists.txt b/CMakeLists.txt @@ -4,7 +4,7 @@ include(cmake/prelude.cmake) project( stamd - VERSION 0.2.5 + VERSION 0.2.6 DESCRIPTION "Static Markdown Page Generator" HOMEPAGE_URL "https://git.dimitrijedobrota.com/stamd.git" LANGUAGES CXX diff --git a/source/index.cpp b/source/index.cpp @@ -61,16 +61,16 @@ std::string to_rfc3339(const std::string& date) return std::format(rfc3339_f, chrono_time); } -void create_index(std::ostream& ost, - const std::string& name, - const article_list& articles, - const categories_t& categories) +std::shared_ptr<article> create_index(std::ostream& ost, + const std::string& name, + const article_list& articles, + const categories_t& categories) { using namespace hemplate; // NOLINT - const article index(name, categories); + auto index = std::make_shared<article>(name, categories); - index.write_header(ost); + index->write_header(ost); ost << html::h1(name); ost << html::ul().set("class", "index"); for (const auto& article : articles) @@ -86,7 +86,9 @@ void create_index(std::ostream& ost, .add(html::a(title).set("href", filename)); }; ost << html::ul(); - index.write_footer(ost); + index->write_footer(ost); + + return index; } void create_atom(std::ostream& ost, diff --git a/source/index.hpp b/source/index.hpp @@ -22,9 +22,9 @@ void create_rss(std::ostream& ost, const std::string& name, const article_list& articles); -void create_index(std::ostream& ost, - const std::string& name, - const article_list& articles, - const categories_t& categories); +std::shared_ptr<article> create_index(std::ostream& ost, + const std::string& name, + const article_list& articles, + const categories_t& categories); } // namespace stamd diff --git a/source/main.cpp b/source/main.cpp @@ -154,25 +154,28 @@ int main(int argc, char* argv[]) [](const auto& lft, const auto& rht) { return lft->get_date() > rht->get_date(); }); - std::ofstream atom(args.output_dir / "atom.xml"); std::ofstream rss(args.output_dir / "rss.xml"); - std::ofstream sitemap(args.output_dir / "sitemap.xml"); - std::ofstream robots(args.output_dir / "robots.txt"); - std::ofstream index(args.output_dir / "index.html"); - - create_sitemap(sitemap, all_articles); - create_robots(robots); - create_rss(rss, "index", all_articles); + + std::ofstream atom(args.output_dir / "atom.xml"); create_atom(atom, "index", all_articles); - create_index(index, "index", all_articles, all_categories); + std::ofstream index(args.output_dir / "index.html"); + + all_articles.push_back( + create_index(index, "index", all_articles, all_categories)); for (const auto& [category, articles] : category_map) { auto ctgry = category; std::ofstream ost(args.output_dir / (normalize(ctgry) + ".html")); - create_index(ost, category, articles, {}); + all_articles.push_back(create_index(ost, category, articles, {})); } + std::ofstream robots(args.output_dir / "robots.txt"); + create_robots(robots); + + std::ofstream sitemap(args.output_dir / "sitemap.xml"); + create_sitemap(sitemap, all_articles); + return 0; }