startgitStatic page generator for git repositories |
git clone git://git.dimitrijedobrota.com/startgit.git |
Log | Files | Refs | README | LICENSE | HACKING | CONTRIBUTING | CODE_OF_CONDUCT | BUILDING | |
commit | ca1520b757d1d7eee862d92d07f5bceed0864608 |
parent | 305fec6e237a01963474848e9bd5454bb446f891 |
author | Dimitrije Dobrota <mail@dimitrijedobrota.com> |
date | Mon, 20 Jan 2025 18:43:16 +0100 |
Variable number of rendered files
Diffstat:M | CMakeLists.txt | | | +- |
M | source/branch.cpp | | | ++++++++++++++ |
M | source/branch.hpp | | | ++ |
M | source/main.cpp | | | +++++++++++++++++++++++++++------------------------------------- |
M | source/repository.cpp | | | -- |
5 files changed, 44 insertions(+), 40 deletions(-)
diff --git a/CMakeLists.txt b/CMakeLists.txt
@@ -4,7 +4,7 @@ include(cmake/prelude.cmake)
project(
startgit
VERSION 0.1.27
VERSION 0.1.28
DESCRIPTION "Static page generator for git repositories"
HOMEPAGE_URL "https://git.dimitrijedobrota.com/stargit.git"
LANGUAGES CXX
diff --git a/source/branch.cpp b/source/branch.cpp
@@ -1,4 +1,6 @@
#include <algorithm>
#include <functional>
#include <unordered_set>
#include "branch.hpp"
@@ -44,11 +46,23 @@ branch::branch(git2wrap::branch brnch, repository& repo)
continue;
}
static const std::unordered_set<std::filesystem::path> special {
"README.md",
"LICENSE.md",
"BUILDING.md",
"HACKING.md",
};
m_files.emplace_back(entry, full_path);
if (!path.empty() || !special.contains(entry.get_name())) {
continue;
}
m_special.emplace_back(entry, full_path);
}
};
traverse(get_last_commit().get_tree(), "");
std::reverse(m_special.begin(), m_special.end());
}
} // namespace startgit
diff --git a/source/branch.hpp b/source/branch.hpp
@@ -30,6 +30,7 @@ public:
const auto& get_commits() const { return m_commits; }
const auto& get_files() const { return m_files; }
const auto& get_special() const { return m_special; }
private:
git2wrap::branch m_branch;
@@ -38,6 +39,7 @@ private:
std::vector<commit> m_commits;
std::vector<file> m_files;
std::vector<file> m_special;
};
} // namespace startgit
diff --git a/source/main.cpp b/source/main.cpp
@@ -3,7 +3,6 @@
#include <fstream>
#include <iostream>
#include <string>
#include <unordered_set>
#include <git2wrap/error.hpp>
#include <git2wrap/libgit2.hpp>
@@ -111,7 +110,7 @@ void write_header(std::ostream& ost,
void write_title(std::ostream& ost,
const startgit::repository& repo,
const std::string& branch_name,
const startgit::branch& branch,
const std::string& relpath = "./")
{
using namespace hemplate; // NOLINT
@@ -123,10 +122,10 @@ void write_title(std::ostream& ost,
span.add(html::select(
{{"id", "branch"}, {"onChange", "switchPage(this.value)"}}));
for (const auto& branch : repo.get_branches()) {
auto option = html::option(branch.get_name());
option.set("value", branch.get_name());
if (branch.get_name() == branch_name) {
for (const auto& c_branch : repo.get_branches()) {
auto option = html::option(c_branch.get_name());
option.set("value", c_branch.get_name());
if (c_branch.get_name() == branch.get_name()) {
option.set("selected", "true");
}
span.add(option);
@@ -145,19 +144,21 @@ void write_title(std::ostream& ost,
.add(html::text("git clone "))
.add(html::a(repo.get_url()).set("href", repo.get_url())));
ost << html::tr().add(
html::td()
.add(html::a("Log").set("href", relpath + "log.html"))
.add(html::text(" | "))
.add(html::a("Files").set("href", relpath + "files.html"))
.add(html::text(" | "))
.add(html::a("Refs").set("href", relpath + "refs.html"))
.add(html::text(" | "))
.add(html::a("README").set("href", relpath + "README.html"))
.add(html::text(" | "))
.add(html::a("LICENSE").set("href", relpath + "LICENSE.html"))
.add(html::text(" | "))
.add(dropdown));
ost << html::tr() << html::td();
ost << html::a("Log").set("href", relpath + "log.html");
ost << html::text(" | ")
<< html::a("Files").set("href", relpath + "files.html");
ost << html::text(" | ")
<< html::a("Refs").set("href", relpath + "refs.html");
for (const auto& file : branch.get_special()) {
const auto filename = file.get_path().replace_extension("html").string();
const auto name = file.get_path().replace_extension().string();
ost << html::text(" | ") << html::a(name).set("href", relpath + filename);
}
ost << html::text(" | ") << dropdown;
ost << html::td() << html::tr();
ost << html::table();
ost << html::hr();
@@ -535,7 +536,7 @@ void write_log(const std::filesystem::path& base,
std::ofstream ofs(base / "log.html");
write_header(ofs, repo, branch, "Commit list");
write_title(ofs, repo, branch.get_name());
write_title(ofs, repo, branch);
write_commit_table(ofs, branch);
write_footer(ofs);
}
@@ -547,7 +548,7 @@ void write_file(const std::filesystem::path& base,
std::ofstream ofs(base / "files.html");
write_header(ofs, repo, branch, "File list");
write_title(ofs, repo, branch.get_name());
write_title(ofs, repo, branch);
write_files_table(ofs, branch);
write_footer(ofs);
}
@@ -559,7 +560,7 @@ void write_refs(const std::filesystem::path& base,
std::ofstream ofs(base / "refs.html");
write_header(ofs, repo, branch, "Refs list");
write_title(ofs, repo, branch.get_name());
write_title(ofs, repo, branch);
write_branch_table(ofs, repo, branch.get_name());
write_tag_table(ofs, repo);
write_footer(ofs);
@@ -574,7 +575,7 @@ void write_commits(const std::filesystem::path& base,
std::ofstream ofs(base / filename);
write_header(ofs, repo, branch, commit.get_summary(), "../");
write_title(ofs, repo, branch.get_name(), "../");
write_title(ofs, repo, branch, "../");
write_commit_diff(ofs, commit);
write_footer(ofs);
}
@@ -598,7 +599,7 @@ void write_files(const std::filesystem::path& base,
}
write_header(ofs, repo, branch, file.get_path(), relpath);
write_title(ofs, repo, branch.get_name(), relpath);
write_title(ofs, repo, branch, relpath);
write_file_title(ofs, file);
write_file_content(ofs, file);
write_footer(ofs);
@@ -609,21 +610,10 @@ void write_readme_licence(const std::filesystem::path& base,
const startgit::repository& repo,
const startgit::branch& branch)
{
static const std::unordered_set<std::filesystem::path> paths {
"README",
"README.md",
"LICENSE",
"LICENSE.md",
};
for (const auto& file : branch.get_files()) {
if (!paths.contains(file.get_path())) {
continue;
}
for (const auto& file : branch.get_special()) {
std::ofstream ofs(base / file.get_path().replace_extension("html"));
write_header(ofs, repo, branch, file.get_path());
write_title(ofs, repo, branch.get_name());
write_title(ofs, repo, branch);
write_html(ofs, file);
write_footer(ofs);
}
diff --git a/source/repository.cpp b/source/repository.cpp
@@ -19,8 +19,6 @@ repository::repository(const std::filesystem::path& path)
it != m_repo.branch_end();
++it)
{
// const branch brnch(it->dup(), *this);
// m_branches.push_front(std::move(brnch));
m_branches.emplace_back(it->dup(), *this);
}