Skip to content

Commit 0f228de

Browse files
committed
examples: Add some metadata to the generated webpages.
1 parent ffb9b30 commit 0f228de

File tree

4 files changed

+48
-10
lines changed

4 files changed

+48
-10
lines changed

build-scripts/build-web-examples.pl

+27-10
Original file line numberDiff line numberDiff line change
@@ -221,6 +221,7 @@ sub handle_example_dir {
221221
$other_examples_html .= "</ul>";
222222

223223
my $category_description = get_category_description($category);
224+
my $preview_image = get_example_thumbnail($project, $category, $example);
224225

225226
my $html = '';
226227
open my $htmltemplate, '<', "$examples_dir/template.html" or die("Couldn't open '$examples_dir/template.html': $!\n");
@@ -232,6 +233,7 @@ sub handle_example_dir {
232233
s/\@javascript_file\@/$jsfname/g;
233234
s/\@htmlified_source_code\@/$htmlified_source_code/g;
234235
s/\@description\@/$description/g;
236+
s/\@preview_image\@/$preview_image/g;
235237
s/\@other_examples_html\@/$other_examples_html/g;
236238
$html .= $_;
237239
}
@@ -242,6 +244,20 @@ sub handle_example_dir {
242244
close($htmloutput);
243245
}
244246

247+
sub get_example_thumbnail {
248+
my $project = shift;
249+
my $category = shift;
250+
my $example = shift;
251+
252+
if ( -f "$examples_dir/$category/$example/thumbnail.png" ) {
253+
return "/$project/$category/$example/thumbnail.png";
254+
} elsif ( -f "$examples_dir/$category/thumbnail.png" ) {
255+
return "/$project/$category/thumbnail.png";
256+
}
257+
258+
return "/$project/thumbnail.png";
259+
}
260+
245261
sub generate_example_thumbnail {
246262
my $project = shift;
247263
my $category = shift;
@@ -250,20 +266,13 @@ sub generate_example_thumbnail {
250266
my $example_no_num = "$example";
251267
$example_no_num =~ s/\A\d+\-//;
252268

253-
my $example_image_url;
254-
if ( -f "$examples_dir/$category/$example/thumbnail.png" ) {
255-
$example_image_url = "/$project/$category/$example/thumbnail.png";
256-
} elsif ( -f "$examples_dir/$category/thumbnail.png" ) {
257-
$example_image_url = "/$project/$category/thumbnail.png";
258-
} else {
259-
$example_image_url = "/$project/thumbnail.png";
260-
}
269+
my $example_image_url = get_example_thumbnail($project, $category, $example);
261270

262271
my $example_mouseover_html = '';
263272
if ( -f "$examples_dir/$category/$example/onmouseover.webp" ) {
264-
$example_mouseover_html = "onmouseover=\"this.src='/$project/$category/$example/onmouseover.webp'\" onmouseout=\"this.src='$example_image_url'\";";
273+
$example_mouseover_html = "onmouseover=\"this.src='/$project/$category/$example/onmouseover.webp'\" onmouseout=\"this.src='$example_image_url';\"";
265274
} elsif ( -f "$examples_dir/$category/onmouseover.webp" ) {
266-
$example_mouseover_html = "onmouseover=\"this.src='/$project/$category/onmouseover.webp'\" onmouseout=\"this.src='$example_image_url'\";";
275+
$example_mouseover_html = "onmouseover=\"this.src='/$project/$category/onmouseover.webp'\" onmouseout=\"this.src='$example_image_url';\"";
267276
}
268277

269278
return "
@@ -312,6 +321,10 @@ sub handle_category_dir {
312321
do_copy("$examples_dir/$category/onmouseover.webp", "$dst/onmouseover.webp") if ( -f "$examples_dir/$category/onmouseover.webp" );
313322

314323
my $category_description = get_category_description($category);
324+
my $preview_image = "/$project/thumbnail.png";
325+
if ( -f "$examples_dir/$category/thumbnail.png" ) {
326+
$preview_image = "/$project/$category/thumbnail.png";
327+
}
315328

316329
# write category page
317330
my $html = '';
@@ -321,6 +334,7 @@ sub handle_category_dir {
321334
s/\@category_name\@/$category/g;
322335
s/\@category_description\@/$category_description/g;
323336
s/\@examples_list_html\@/$examples_list_html/g;
337+
s/\@preview_image\@/$preview_image/g;
324338
$html .= $_;
325339
}
326340
close($htmltemplate);
@@ -379,12 +393,15 @@ sub handle_category_dir {
379393
$homepage_list_html .= "</div>";
380394
}
381395

396+
my $preview_image = "/$project/thumbnail.png";
397+
382398
my $dst = "$output_dir/";
383399
my $html = '';
384400
open my $htmltemplate, '<', "$examples_dir/template-homepage.html" or die("Couldn't open '$examples_dir/template-category.html': $!\n");
385401
while (<$htmltemplate>) {
386402
s/\@project_name\@/$project/g;
387403
s/\@homepage_list_html\@/$homepage_list_html/g;
404+
s/\@preview_image\@/$preview_image/g;
388405
$html .= $_;
389406
}
390407
close($htmltemplate);

examples/template-category.html

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<title>@project_name@ Examples: @category_description@</title>
8+
<link rel="icon" href="/@project_name@/thumbnail.png" type="image/png" />
89
<link
910
rel="stylesheet"
1011
type="text/css"
@@ -15,6 +16,12 @@
1516
margin-top: 0;
1617
}
1718
</style>
19+
20+
<meta property="og:type" content="website">
21+
<meta property="og:title" content="@project_name@ Examples: @category_description@">
22+
<meta property="og:description" content="@project_name@ Examples: @category_description@">
23+
<meta property="og:image" content="@preview_image@" />
24+
1825
</head>
1926
<body>
2027
<header>

examples/template-homepage.html

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<title>@project_name@ Examples</title>
8+
<link rel="icon" href="/@project_name@/thumbnail.png" type="image/png" />
89
<link
910
rel="stylesheet"
1011
type="text/css"
@@ -15,6 +16,12 @@
1516
margin-top: 0;
1617
}
1718
</style>
19+
20+
<meta property="og:type" content="website">
21+
<meta property="og:title" content="@project_name@ Examples">
22+
<meta property="og:description" content="@project_name@ Examples">
23+
<meta property="og:image" content="@preview_image@" />
24+
1825
</head>
1926
<body>
2027
<header>

examples/template.html

+7
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,13 @@
55
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
66
<meta name="viewport" content="width=device-width, initial-scale=1" />
77
<title>@project_name@ Example: @category_name@/@example_name@</title>
8+
<link rel="icon" href="/@project_name@/thumbnail.png" type="image/png" />
9+
10+
<meta property="og:type" content="website">
11+
<meta property="og:title" content="@project_name@ Example: @category_name@/@example_name@">
12+
<meta property="og:description" content="@description@">
13+
<meta property="og:image" content="@preview_image@" />
14+
815
<link rel="stylesheet" type="text/css" href="/@project_name@/examples.css" />
916
<style>
1017
main {

0 commit comments

Comments
 (0)