From 1a3997b793ad1154faae03478522a4580b877110 Mon Sep 17 00:00:00 2001 From: Juan Cruz Viotti Date: Fri, 10 Jan 2025 14:44:38 -0400 Subject: [PATCH] Add support for custom HTML hero sections (#120) Signed-off-by: Juan Cruz Viotti --- schemas/configuration.json | 3 +++ src/enterprise/enterprise_index.h | 10 ++++++++++ src/html/include/sourcemeta/registry/html_safe.h | 5 +++++ test/sandbox/configuration.json | 1 + test/schemas/configuration/fail.test.json | 15 +++++++++++++++ test/schemas/configuration/pass.test.json | 15 +++++++++++++++ 6 files changed, 49 insertions(+) diff --git a/schemas/configuration.json b/schemas/configuration.json index 25c6109..5317adc 100644 --- a/schemas/configuration.json +++ b/schemas/configuration.json @@ -45,6 +45,9 @@ } } }, + "hero": { + "type": "string" + }, "pages": { "type": "object", "minProperties": 1, diff --git a/src/enterprise/enterprise_index.h b/src/enterprise/enterprise_index.h index cc8ca78..a687636 100644 --- a/src/enterprise/enterprise_index.h +++ b/src/enterprise/enterprise_index.h @@ -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"; diff --git a/src/html/include/sourcemeta/registry/html_safe.h b/src/html/include/sourcemeta/registry/html_safe.h index 2ab7619..bab42d8 100644 --- a/src/html/include/sourcemeta/registry/html_safe.h +++ b/src/html/include/sourcemeta/registry/html_safe.h @@ -38,6 +38,11 @@ template class SafeOutput { return *this; } + auto unsafe(const std::string_view content) -> SafeOutput & { + this->stream << content; + return *this; + } + private: T &stream; }; diff --git a/test/sandbox/configuration.json b/test/sandbox/configuration.json index b659770..803ad58 100644 --- a/test/sandbox/configuration.json +++ b/test/sandbox/configuration.json @@ -1,6 +1,7 @@ { "url": "http://localhost:8000", "port": 8000, + "hero": "

A sample schema registry sandbox for testing purposes

", "action": { "title": "Star on GitHub", "url": "https://github.com/sourcemeta/registry", diff --git a/test/schemas/configuration/fail.test.json b/test/schemas/configuration/fail.test.json index 966ca0e..48eecb7 100644 --- a/test/schemas/configuration/fail.test.json +++ b/test/schemas/configuration/fail.test.json @@ -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" + } + } + } } ] } diff --git a/test/schemas/configuration/pass.test.json b/test/schemas/configuration/pass.test.json index ace4e54..4583d24 100644 --- a/test/schemas/configuration/pass.test.json +++ b/test/schemas/configuration/pass.test.json @@ -178,6 +178,21 @@ } } } + }, + { + "description": "basic HTML hero", + "valid": true, + "data": { + "url": "https://www.example.com", + "port": 8000, + "hero": "

Hello

", + "schemas": { + "example": { + "base": "https://schemas.example.com", + "path": "./schemas" + } + } + } } ] }