Skip to content

Commit

Permalink
Add support for custom HTML hero sections (#120)
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 10, 2025
1 parent 4ab7715 commit 1a3997b
Show file tree
Hide file tree
Showing 6 changed files with 49 additions and 0 deletions.
3 changes: 3 additions & 0 deletions schemas/configuration.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
}
}
},
"hero": {
"type": "string"
},
"pages": {
"type": "object",
"minProperties": 1,
Expand Down
10 changes: 10 additions & 0 deletions src/enterprise/enterprise_index.h
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,16 @@ auto generate_toc(
output_html, configuration,
configuration.at("title").to_string() + " Schemas",
configuration.at("description").to_string(), "");

if (configuration.defines("hero")) {
output_html.open("div", {{"class", "container-fluid px-4"}})
.open("div",
{{"class",
"bg-light border border-light-subtle mt-4 px-3 py-3"}});
output_html.unsafe(configuration.at("hero").to_string());
output_html.close("div").close("div");
}

sourcemeta::registry::enterprise::html_file_manager(html, meta);
sourcemeta::registry::enterprise::html_end(output_html);
html << "\n";
Expand Down
5 changes: 5 additions & 0 deletions src/html/include/sourcemeta/registry/html_safe.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ template <typename T> class SafeOutput {
return *this;
}

auto unsafe(const std::string_view content) -> SafeOutput & {
this->stream << content;
return *this;
}

private:
T &stream;
};
Expand Down
1 change: 1 addition & 0 deletions test/sandbox/configuration.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{
"url": "http://localhost:8000",
"port": 8000,
"hero": "<p class=\"mb-0\">A sample schema registry sandbox for testing purposes</p>",
"action": {
"title": "Star on GitHub",
"url": "https://github.com/sourcemeta/registry",
Expand Down
15 changes: 15 additions & 0 deletions test/schemas/configuration/fail.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -720,6 +720,21 @@
}
}
}
},
{
"description": "non-string hero",
"valid": false,
"data": {
"url": "https://www.example.com",
"port": 8000,
"hero": 1,
"schemas": {
"example": {
"base": "https://schemas.example.com",
"path": "./schemas"
}
}
}
}
]
}
15 changes: 15 additions & 0 deletions test/schemas/configuration/pass.test.json
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,21 @@
}
}
}
},
{
"description": "basic HTML hero",
"valid": true,
"data": {
"url": "https://www.example.com",
"port": 8000,
"hero": "<p>Hello</p>",
"schemas": {
"example": {
"base": "https://schemas.example.com",
"path": "./schemas"
}
}
}
}
]
}

0 comments on commit 1a3997b

Please sign in to comment.