Skip to content

Commit

Permalink
Add og:url to the head section
Browse files Browse the repository at this point in the history
  • Loading branch information
danakj committed Dec 30, 2024
1 parent b81bab7 commit f69d8fd
Show file tree
Hide file tree
Showing 12 changed files with 41 additions and 5 deletions.
1 change: 1 addition & 0 deletions .github/workflows/subdoc.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
3 changes: 2 additions & 1 deletion subdoc/lib/gen/generate_concept.cc
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,8 @@ sus::Result<void, MarkdownToHtmlError> 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();
Expand Down
3 changes: 2 additions & 1 deletion subdoc/lib/gen/generate_function.cc
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,8 @@ sus::Result<void, MarkdownToHtmlError> 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();
Expand Down
11 changes: 11 additions & 0 deletions subdoc/lib/gen/generate_head.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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()) {
Expand Down
1 change: 1 addition & 0 deletions subdoc/lib/gen/generate_head.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

}
3 changes: 2 additions & 1 deletion subdoc/lib/gen/generate_macro.cc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ sus::Result<void, MarkdownToHtmlError> 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();
Expand Down
2 changes: 1 addition & 1 deletion subdoc/lib/gen/generate_namespace.cc
Original file line number Diff line number Diff line change
Expand Up @@ -665,7 +665,7 @@ sus::Result<void, MarkdownToHtmlError> 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<SortedNamespaceByName> sorted_namespaces;
for (const auto& [key, sub_element] : element.namespaces) {
Expand Down
3 changes: 2 additions & 1 deletion subdoc/lib/gen/generate_record.cc
Original file line number Diff line number Diff line change
Expand Up @@ -480,7 +480,8 @@ sus::Result<void, MarkdownToHtmlError> 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<SortedFieldByName> sorted_static_fields;
Expand Down
2 changes: 2 additions & 0 deletions subdoc/lib/gen/options.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> project_url;
/// The version string for the project. Typically a semver version such as
/// "1.2.3" or "0.2.0-beta-4".
Option<std::string> version_text;
Expand Down
15 changes: 15 additions & 0 deletions subdoc/subdoc_main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<std::string> 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<std::string> option_project_version(
"project-version",
llvm::cl::desc("A string representing the version of the project, "
Expand Down Expand Up @@ -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()));
Expand Down
1 change: 1 addition & 0 deletions tools/run_subdoc.bat
Original file line number Diff line number Diff line change
Expand Up @@ -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% ^
Expand Down
1 change: 1 addition & 0 deletions tools/run_subdoc.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down

0 comments on commit f69d8fd

Please sign in to comment.