Skip to content

Commit f69d8fd

Browse files
committed
Add og:url to the head section
1 parent b81bab7 commit f69d8fd

12 files changed

+41
-5
lines changed

.github/workflows/subdoc.yml

+1
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,7 @@ jobs:
192192
--project-md sus/project.md \
193193
--project-name Subspace \
194194
--project-version 0.0.0 \
195+
--project-url https://suslib.cc \
195196
--remove-source-path-prefix $PWD \
196197
--add-source-path-prefix ${source_url} \
197198
--source-path-line-prefix L \

subdoc/lib/gen/generate_concept.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,8 @@ sus::Result<void, MarkdownToHtmlError> generate_concept(
192192
}
193193
}
194194
title << element.name;
195-
generate_head(html, sus::move(title).str(), md_html.summary_text, options);
195+
generate_head(html, sus::move(title).str(), md_html.summary_text,
196+
path.filename(), options);
196197
}
197198

198199
auto body = html.open_body();

subdoc/lib/gen/generate_function.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,8 @@ sus::Result<void, MarkdownToHtmlError> generate_function(
267267
}
268268
}
269269
title << element.name;
270-
generate_head(html, sus::move(title).str(), md_html.summary_text, options);
270+
generate_head(html, sus::move(title).str(), md_html.summary_text,
271+
path.filename(), options);
271272
}
272273

273274
auto body = html.open_body();

subdoc/lib/gen/generate_head.cc

+11
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace subdoc::gen {
1818

1919
void generate_head(HtmlWriter& html, std::string_view title,
2020
std::string_view description,
21+
const std::filesystem::path& file_path,
2122
const Options& options) noexcept {
2223
{
2324
auto head = html.open_head();
@@ -46,6 +47,16 @@ void generate_head(HtmlWriter& html, std::string_view title,
4647
meta.add_property("og:site_name");
4748
meta.add_content(options.project_name);
4849
}
50+
{
51+
auto meta = head.open_meta();
52+
meta.add_property("og:url");
53+
if (options.project_url.is_some()) {
54+
std::string url = options.project_url.as_value();
55+
url += '/';
56+
url += file_path.string();
57+
meta.add_content(url);
58+
}
59+
}
4960

5061
auto page_title = std::string(title);
5162
if (!page_title.empty()) {

subdoc/lib/gen/generate_head.h

+1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace subdoc::gen {
2323

2424
void generate_head(HtmlWriter& html, std::string_view title,
2525
std::string_view description,
26+
const std::filesystem::path& file_path,
2627
const Options& options) noexcept;
2728

2829
}

subdoc/lib/gen/generate_macro.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ sus::Result<void, MarkdownToHtmlError> generate_macro(
9898
}
9999
}
100100
title << element.name;
101-
generate_head(html, sus::move(title).str(), md_html.summary_text, options);
101+
generate_head(html, sus::move(title).str(), md_html.summary_text,
102+
path.filename(), options);
102103
}
103104

104105
auto body = html.open_body();

subdoc/lib/gen/generate_namespace.cc

+1-1
Original file line numberDiff line numberDiff line change
@@ -665,7 +665,7 @@ sus::Result<void, MarkdownToHtmlError> generate_namespace(
665665
construct_html_file_path_for_namespace(options.output_root, element);
666666
auto html = HtmlWriter(open_file_for_writing(path).unwrap());
667667
generate_head(html, namespace_display_name(element, ancestors, options),
668-
md_html.summary_text, options);
668+
md_html.summary_text, path.filename(), options);
669669

670670
Vec<SortedNamespaceByName> sorted_namespaces;
671671
for (const auto& [key, sub_element] : element.namespaces) {

subdoc/lib/gen/generate_record.cc

+2-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,8 @@ sus::Result<void, MarkdownToHtmlError> generate_record(
480480
title << "::";
481481
}
482482
title << element.name;
483-
generate_head(html, sus::move(title).str(), md_html.summary_text, options);
483+
generate_head(html, sus::move(title).str(), md_html.summary_text,
484+
path.filename(), options);
484485
}
485486

486487
Vec<SortedFieldByName> sorted_static_fields;

subdoc/lib/gen/options.h

+2
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ struct FavIcon {
5454
struct Options {
5555
std::string project_name = "PROJECT NAME";
5656
std::string project_logo = "PROJECT LOGO.png";
57+
/// The base url where the site will be published.
58+
Option<std::string> project_url;
5759
/// The version string for the project. Typically a semver version such as
5860
/// "1.2.3" or "0.2.0-beta-4".
5961
Option<std::string> version_text;

subdoc/subdoc_main.cc

+15
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,13 @@ int main(int argc, const char** argv) {
4747
"to insert into the project root"),
4848
llvm::cl::cat(option_category));
4949

50+
llvm::cl::opt<std::string> option_project_url(
51+
"project-url",
52+
llvm::cl::desc("The base URL where the site will be hosted, "
53+
"such as https://website.abc/here. The index page would "
54+
"be at https://website.abc/here/index.html."),
55+
llvm::cl::cat(option_category));
56+
5057
llvm::cl::opt<std::string> option_project_version(
5158
"project-version",
5259
llvm::cl::desc("A string representing the version of the project, "
@@ -276,6 +283,14 @@ int main(int argc, const char** argv) {
276283
if (option_project_logo.getNumOccurrences() > 0) {
277284
gen_options.project_logo = option_project_logo.getValue();
278285
}
286+
if (option_project_url.getNumOccurrences() > 0) {
287+
gen_options.project_url =
288+
sus::some(sus::clone(option_project_url.getValue()));
289+
} else {
290+
fmt::println(stderr,
291+
"Warning: Missing --project-url. Without this, the og:url tag "
292+
"will be left empty.");
293+
}
279294
if (option_project_version.getNumOccurrences() > 0) {
280295
gen_options.version_text =
281296
sus::some(sus::clone(option_project_version.getValue()));

tools/run_subdoc.bat

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ out\subdoc\subdoc -p out --out docs ^
1212
--project-md sus/project.md ^
1313
--project-logo logo.png ^
1414
--project-name Subspace ^
15+
--project-url https://suslib.cc ^
1516
--project-version 0.1.2 ^
1617
--ignore-bad-code-links ^
1718
--remove-source-path-prefix %cd% ^

tools/run_subdoc.sh

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ out/subdoc/subdoc -p out --out docs \
1414
--project-md sus/project.md \
1515
--project-logo logo.png \
1616
--project-name Subspace \
17+
--project-url https://suslib.cc \
1718
--project-version 0.1.2 \
1819
--ignore-bad-code-links \
1920
--remove-source-path-prefix $PWD \

0 commit comments

Comments
 (0)