Fixed link generation for template specializations

This commit is contained in:
Bartek Kryza
2023-12-10 11:54:52 +01:00
parent 85ffe2cdee
commit cea427e32d
12 changed files with 59 additions and 35 deletions

View File

@@ -218,17 +218,22 @@ inja::json generator<C, D>::element_context(const E &e) const
if (!e.file().empty()) {
std::filesystem::path file{e.file()};
std::string relative_path = file.string();
std::string git_relative_path = file.string();
if (!e.file_relative().empty()) {
#if _MSC_VER
if (file.is_absolute() && ctx.contains("git"))
if (file.is_absolute() && ctx.contains("git"))
#else
if (file.is_absolute() && ctx.template contains("git"))
if (file.is_absolute() && ctx.template contains("git"))
#endif
relative_path =
std::filesystem::relative(file, ctx["git"]["toplevel"])
.string();
git_relative_path =
std::filesystem::relative(file, ctx["git"]["toplevel"])
.string();
}
else {
git_relative_path = "";
}
ctx["element"]["source"]["path"] = util::path_to_url(relative_path);
ctx["element"]["source"]["path"] = util::path_to_url(git_relative_path);
ctx["element"]["source"]["full_path"] = file.string();
ctx["element"]["source"]["name"] = file.filename().string();
ctx["element"]["source"]["line"] = e.line();
@@ -477,13 +482,12 @@ void generator<C, D>::generate_link(std::ostream &ostr, const E &e) const
{
const auto &config = generators::generator<C, D>::config();
if (e.file().empty())
if (e.file_relative().empty())
return;
ostr << " [[";
try {
if (!config.generate_links().link.empty()) {
ostr << env().render(std::string_view{config.generate_links().link},
element_context(e));
}