From f69d8fd100169210e30ea1f797e1d000863a2031 Mon Sep 17 00:00:00 2001 From: Dana Jansens Date: Sun, 29 Dec 2024 20:43:41 -0500 Subject: [PATCH] Add og:url to the head section --- .github/workflows/subdoc.yml | 1 + subdoc/lib/gen/generate_concept.cc | 3 ++- subdoc/lib/gen/generate_function.cc | 3 ++- subdoc/lib/gen/generate_head.cc | 11 +++++++++++ subdoc/lib/gen/generate_head.h | 1 + subdoc/lib/gen/generate_macro.cc | 3 ++- subdoc/lib/gen/generate_namespace.cc | 2 +- subdoc/lib/gen/generate_record.cc | 3 ++- subdoc/lib/gen/options.h | 2 ++ subdoc/subdoc_main.cc | 15 +++++++++++++++ tools/run_subdoc.bat | 1 + tools/run_subdoc.sh | 1 + 12 files changed, 41 insertions(+), 5 deletions(-) diff --git a/.github/workflows/subdoc.yml b/.github/workflows/subdoc.yml index 518e1a1ff..10989b347 100644 --- a/.github/workflows/subdoc.yml +++ b/.github/workflows/subdoc.yml @@ -192,6 +192,7 @@ jobs: --project-md sus/project.md \ --project-name Subspace \ --project-version 0.0.0 \ + --project-url https://suslib.cc \ --remove-source-path-prefix $PWD \ --add-source-path-prefix ${source_url} \ --source-path-line-prefix L \ diff --git a/subdoc/lib/gen/generate_concept.cc b/subdoc/lib/gen/generate_concept.cc index b8c183708..03a278027 100644 --- a/subdoc/lib/gen/generate_concept.cc +++ b/subdoc/lib/gen/generate_concept.cc @@ -192,7 +192,8 @@ sus::Result generate_concept( } } title << element.name; - generate_head(html, sus::move(title).str(), md_html.summary_text, options); + generate_head(html, sus::move(title).str(), md_html.summary_text, + path.filename(), options); } auto body = html.open_body(); diff --git a/subdoc/lib/gen/generate_function.cc b/subdoc/lib/gen/generate_function.cc index 8ac837ef8..87a6038b6 100644 --- a/subdoc/lib/gen/generate_function.cc +++ b/subdoc/lib/gen/generate_function.cc @@ -267,7 +267,8 @@ sus::Result generate_function( } } title << element.name; - generate_head(html, sus::move(title).str(), md_html.summary_text, options); + generate_head(html, sus::move(title).str(), md_html.summary_text, + path.filename(), options); } auto body = html.open_body(); diff --git a/subdoc/lib/gen/generate_head.cc b/subdoc/lib/gen/generate_head.cc index e6a09a365..04e8e220b 100644 --- a/subdoc/lib/gen/generate_head.cc +++ b/subdoc/lib/gen/generate_head.cc @@ -18,6 +18,7 @@ namespace subdoc::gen { void generate_head(HtmlWriter& html, std::string_view title, std::string_view description, + const std::filesystem::path& file_path, const Options& options) noexcept { { auto head = html.open_head(); @@ -46,6 +47,16 @@ void generate_head(HtmlWriter& html, std::string_view title, meta.add_property("og:site_name"); meta.add_content(options.project_name); } + { + auto meta = head.open_meta(); + meta.add_property("og:url"); + if (options.project_url.is_some()) { + std::string url = options.project_url.as_value(); + url += '/'; + url += file_path.string(); + meta.add_content(url); + } + } auto page_title = std::string(title); if (!page_title.empty()) { diff --git a/subdoc/lib/gen/generate_head.h b/subdoc/lib/gen/generate_head.h index f56c67b59..17595763d 100644 --- a/subdoc/lib/gen/generate_head.h +++ b/subdoc/lib/gen/generate_head.h @@ -23,6 +23,7 @@ namespace subdoc::gen { void generate_head(HtmlWriter& html, std::string_view title, std::string_view description, + const std::filesystem::path& file_path, const Options& options) noexcept; } diff --git a/subdoc/lib/gen/generate_macro.cc b/subdoc/lib/gen/generate_macro.cc index 3eaeab877..68e2ce44c 100644 --- a/subdoc/lib/gen/generate_macro.cc +++ b/subdoc/lib/gen/generate_macro.cc @@ -98,7 +98,8 @@ sus::Result generate_macro( } } title << element.name; - generate_head(html, sus::move(title).str(), md_html.summary_text, options); + generate_head(html, sus::move(title).str(), md_html.summary_text, + path.filename(), options); } auto body = html.open_body(); diff --git a/subdoc/lib/gen/generate_namespace.cc b/subdoc/lib/gen/generate_namespace.cc index 09d2609cf..4863a2d9a 100644 --- a/subdoc/lib/gen/generate_namespace.cc +++ b/subdoc/lib/gen/generate_namespace.cc @@ -665,7 +665,7 @@ sus::Result generate_namespace( construct_html_file_path_for_namespace(options.output_root, element); auto html = HtmlWriter(open_file_for_writing(path).unwrap()); generate_head(html, namespace_display_name(element, ancestors, options), - md_html.summary_text, options); + md_html.summary_text, path.filename(), options); Vec sorted_namespaces; for (const auto& [key, sub_element] : element.namespaces) { diff --git a/subdoc/lib/gen/generate_record.cc b/subdoc/lib/gen/generate_record.cc index 706c20a30..89f4ff0e3 100644 --- a/subdoc/lib/gen/generate_record.cc +++ b/subdoc/lib/gen/generate_record.cc @@ -480,7 +480,8 @@ sus::Result generate_record( title << "::"; } title << element.name; - generate_head(html, sus::move(title).str(), md_html.summary_text, options); + generate_head(html, sus::move(title).str(), md_html.summary_text, + path.filename(), options); } Vec sorted_static_fields; diff --git a/subdoc/lib/gen/options.h b/subdoc/lib/gen/options.h index 3c7bed3f4..eeb6808f0 100644 --- a/subdoc/lib/gen/options.h +++ b/subdoc/lib/gen/options.h @@ -54,6 +54,8 @@ struct FavIcon { struct Options { std::string project_name = "PROJECT NAME"; std::string project_logo = "PROJECT LOGO.png"; + /// The base url where the site will be published. + Option project_url; /// The version string for the project. Typically a semver version such as /// "1.2.3" or "0.2.0-beta-4". Option version_text; diff --git a/subdoc/subdoc_main.cc b/subdoc/subdoc_main.cc index ff5d1b10a..706681ac0 100644 --- a/subdoc/subdoc_main.cc +++ b/subdoc/subdoc_main.cc @@ -47,6 +47,13 @@ int main(int argc, const char** argv) { "to insert into the project root"), llvm::cl::cat(option_category)); + llvm::cl::opt option_project_url( + "project-url", + llvm::cl::desc("The base URL where the site will be hosted, " + "such as https://website.abc/here. The index page would " + "be at https://website.abc/here/index.html."), + llvm::cl::cat(option_category)); + llvm::cl::opt option_project_version( "project-version", llvm::cl::desc("A string representing the version of the project, " @@ -276,6 +283,14 @@ int main(int argc, const char** argv) { if (option_project_logo.getNumOccurrences() > 0) { gen_options.project_logo = option_project_logo.getValue(); } + if (option_project_url.getNumOccurrences() > 0) { + gen_options.project_url = + sus::some(sus::clone(option_project_url.getValue())); + } else { + fmt::println(stderr, + "Warning: Missing --project-url. Without this, the og:url tag " + "will be left empty."); + } if (option_project_version.getNumOccurrences() > 0) { gen_options.version_text = sus::some(sus::clone(option_project_version.getValue())); diff --git a/tools/run_subdoc.bat b/tools/run_subdoc.bat index 1ac22db8c..785133343 100644 --- a/tools/run_subdoc.bat +++ b/tools/run_subdoc.bat @@ -12,6 +12,7 @@ out\subdoc\subdoc -p out --out docs ^ --project-md sus/project.md ^ --project-logo logo.png ^ --project-name Subspace ^ + --project-url https://suslib.cc ^ --project-version 0.1.2 ^ --ignore-bad-code-links ^ --remove-source-path-prefix %cd% ^ diff --git a/tools/run_subdoc.sh b/tools/run_subdoc.sh index b01252833..0a92d9222 100755 --- a/tools/run_subdoc.sh +++ b/tools/run_subdoc.sh @@ -14,6 +14,7 @@ out/subdoc/subdoc -p out --out docs \ --project-md sus/project.md \ --project-logo logo.png \ --project-name Subspace \ + --project-url https://suslib.cc \ --project-version 0.1.2 \ --ignore-bad-code-links \ --remove-source-path-prefix $PWD \