Skip to content

Commit

Permalink
Elevate page metadata to index entries (#68)
Browse files Browse the repository at this point in the history
Signed-off-by: Juan Cruz Viotti <[email protected]>
  • Loading branch information
jviotti authored Jan 3, 2025
1 parent f74ec19 commit e3ab2e9
Showing 1 changed file with 8 additions and 21 deletions.
29 changes: 8 additions & 21 deletions src/enterprise/enterprise_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,33 +32,20 @@ auto generate_toc(const sourcemeta::jsontoolkit::JSON &configuration,
const auto entry_relative_path{
entry.path().string().substr(base.string().size())};
if (entry.is_directory()) {
entry_json.assign("type", sourcemeta::jsontoolkit::JSON{"directory"});
entry_json.assign(
"url", sourcemeta::jsontoolkit::JSON{
entry.path().string().substr(base.string().size())});

const auto collection_entry_name{entry_relative_path.substr(1)};
if (configuration.defines("pages") &&
configuration.at("pages").defines(collection_entry_name)) {
const auto &page_entry{
configuration.at("pages").at(collection_entry_name)};
if (page_entry.defines("title")) {
entry_json.assign("title", sourcemeta::jsontoolkit::JSON{
configuration.at("pages")
.at(collection_entry_name)
.at("title")
.to_string()});
}

if (page_entry.defines("description")) {
entry_json.assign("description", sourcemeta::jsontoolkit::JSON{
configuration.at("pages")
.at(collection_entry_name)
.at("description")
.to_string()});
for (const auto &page_entry :
configuration.at("pages").at(collection_entry_name).as_object()) {
entry_json.assign(page_entry.first, page_entry.second);
}
}

entry_json.assign("type", sourcemeta::jsontoolkit::JSON{"directory"});
entry_json.assign(
"url", sourcemeta::jsontoolkit::JSON{
entry.path().string().substr(base.string().size())});

entries.push_back(std::move(entry_json));
} else if (entry.path().extension() == ".json" &&
!entry.path().stem().string().starts_with(".")) {
Expand Down

0 comments on commit e3ab2e9

Please sign in to comment.