examples: Improve webpage generation in various ways, add thumbnails, etc.
|
@ -71,17 +71,41 @@ sub build_latest {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub get_category_description {
|
||||||
|
my $category = shift;
|
||||||
|
my $retval = ucfirst($category);
|
||||||
|
|
||||||
|
if (open(my $fh, '<', "$examples_dir/$category/description.txt")) {
|
||||||
|
$retval = <$fh>;
|
||||||
|
chomp($retval);
|
||||||
|
close($fh);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $retval;
|
||||||
|
}
|
||||||
|
|
||||||
sub get_categories {
|
sub get_categories {
|
||||||
my @categories = ();
|
my @categories = ();
|
||||||
|
|
||||||
opendir(my $dh, $examples_dir) or die("Couldn't opendir '$examples_dir': $!\n");
|
if (open(my $fh, '<', "$examples_dir/categories.txt")) {
|
||||||
foreach my $dir (sort readdir $dh) {
|
while (<$fh>) {
|
||||||
next if ($dir eq '.') || ($dir eq '..'); # obviously skip current and parent entries.
|
chomp;
|
||||||
next if not -d "$examples_dir/$dir"; # only care about subdirectories.
|
s/\A\s+//;
|
||||||
|
s/\s+\Z//;
|
||||||
push @categories, $dir;
|
next if $_ eq '';
|
||||||
|
next if /\A\#/;
|
||||||
|
push @categories, $_;
|
||||||
|
}
|
||||||
|
close($fh);
|
||||||
|
} else {
|
||||||
|
opendir(my $dh, $examples_dir) or die("Couldn't opendir '$examples_dir': $!\n");
|
||||||
|
foreach my $dir (sort readdir $dh) {
|
||||||
|
next if ($dir eq '.') || ($dir eq '..'); # obviously skip current and parent entries.
|
||||||
|
next if not -d "$examples_dir/$dir"; # only care about subdirectories.
|
||||||
|
push @categories, $dir;
|
||||||
|
}
|
||||||
|
closedir($dh);
|
||||||
}
|
}
|
||||||
closedir($dh);
|
|
||||||
|
|
||||||
return @categories;
|
return @categories;
|
||||||
}
|
}
|
||||||
|
@ -131,10 +155,16 @@ sub handle_example_dir {
|
||||||
$basefname = "$category-$basefname";
|
$basefname = "$category-$basefname";
|
||||||
my $jsfname = "$basefname.js";
|
my $jsfname = "$basefname.js";
|
||||||
my $wasmfname = "$basefname.wasm";
|
my $wasmfname = "$basefname.wasm";
|
||||||
|
my $thumbnailfname = 'thumbnail.png';
|
||||||
|
my $onmouseoverfname = 'onmouseover.webp';
|
||||||
my $jssrc = "$compile_dir/examples/$jsfname";
|
my $jssrc = "$compile_dir/examples/$jsfname";
|
||||||
my $wasmsrc = "$compile_dir/examples/$wasmfname";
|
my $wasmsrc = "$compile_dir/examples/$wasmfname";
|
||||||
|
my $thumbnailsrc = "$examples_dir/$category/$example/$thumbnailfname";
|
||||||
|
my $onmouseoversrc = "$examples_dir/$category/$example/$onmouseoverfname";
|
||||||
my $jsdst = "$dst/$jsfname";
|
my $jsdst = "$dst/$jsfname";
|
||||||
my $wasmdst = "$dst/$wasmfname";
|
my $wasmdst = "$dst/$wasmfname";
|
||||||
|
my $thumbnaildst = "$dst/$thumbnailfname";
|
||||||
|
my $onmouseoverdst = "$dst/$onmouseoverfname";
|
||||||
|
|
||||||
my $description = '';
|
my $description = '';
|
||||||
if (open(my $readmetxth, '<', "$examples_dir/$category/$example/README.txt")) {
|
if (open(my $readmetxth, '<', "$examples_dir/$category/$example/README.txt")) {
|
||||||
|
@ -150,6 +180,8 @@ sub handle_example_dir {
|
||||||
do_mkdir($dst);
|
do_mkdir($dst);
|
||||||
do_copy($jssrc, $jsdst);
|
do_copy($jssrc, $jsdst);
|
||||||
do_copy($wasmsrc, $wasmdst);
|
do_copy($wasmsrc, $wasmdst);
|
||||||
|
do_copy($thumbnailsrc, $thumbnaildst) if ( -f $thumbnailsrc );
|
||||||
|
do_copy($onmouseoversrc, $onmouseoverdst) if ( -f $onmouseoversrc );
|
||||||
|
|
||||||
my $highlight_cmd = "highlight '--outdir=$dst' --style-outfile=highlight.css --fragment --enclose-pre --stdout --syntax=c '--plug-in=$examples_dir/highlight-plugin.lua'";
|
my $highlight_cmd = "highlight '--outdir=$dst' --style-outfile=highlight.css --fragment --enclose-pre --stdout --syntax=c '--plug-in=$examples_dir/highlight-plugin.lua'";
|
||||||
print("$highlight_cmd\n");
|
print("$highlight_cmd\n");
|
||||||
|
@ -184,11 +216,14 @@ sub handle_example_dir {
|
||||||
}
|
}
|
||||||
$other_examples_html .= "</ul>";
|
$other_examples_html .= "</ul>";
|
||||||
|
|
||||||
|
my $category_description = get_category_description($category);
|
||||||
|
|
||||||
my $html = '';
|
my $html = '';
|
||||||
open my $htmltemplate, '<', "$examples_dir/template.html" or die("Couldn't open '$examples_dir/template.html': $!\n");
|
open my $htmltemplate, '<', "$examples_dir/template.html" or die("Couldn't open '$examples_dir/template.html': $!\n");
|
||||||
while (<$htmltemplate>) {
|
while (<$htmltemplate>) {
|
||||||
s/\@project_name\@/$project/g;
|
s/\@project_name\@/$project/g;
|
||||||
s/\@category_name\@/$category/g;
|
s/\@category_name\@/$category/g;
|
||||||
|
s/\@category_description\@/$category_description/g;
|
||||||
s/\@example_name\@/$example/g;
|
s/\@example_name\@/$example/g;
|
||||||
s/\@javascript_file\@/$jsfname/g;
|
s/\@javascript_file\@/$jsfname/g;
|
||||||
s/\@htmlified_source_code\@/$htmlified_source_code/g;
|
s/\@htmlified_source_code\@/$htmlified_source_code/g;
|
||||||
|
@ -203,6 +238,51 @@ sub handle_example_dir {
|
||||||
close($htmloutput);
|
close($htmloutput);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sub generate_example_thumbnail {
|
||||||
|
my $project = shift;
|
||||||
|
my $category = shift;
|
||||||
|
my $example = shift;
|
||||||
|
|
||||||
|
my $example_no_num = "$example";
|
||||||
|
$example_no_num =~ s/\A\d+\-//;
|
||||||
|
|
||||||
|
my $example_image_url;
|
||||||
|
if ( -f "$examples_dir/$category/$example/thumbnail.png" ) {
|
||||||
|
$example_image_url = "/$project/$category/$example/thumbnail.png";
|
||||||
|
} elsif ( -f "$examples_dir/$category/thumbnail.png" ) {
|
||||||
|
$example_image_url = "/$project/$category/thumbnail.png";
|
||||||
|
} else {
|
||||||
|
$example_image_url = "/$project/thumbnail.png";
|
||||||
|
}
|
||||||
|
|
||||||
|
my $example_mouseover_html = '';
|
||||||
|
if ( -f "$examples_dir/$category/$example/onmouseover.webp" ) {
|
||||||
|
$example_mouseover_html = "onmouseover=\"this.src='/$project/$category/$example/onmouseover.webp'\" onmouseout=\"this.src='$example_image_url'\";";
|
||||||
|
} elsif ( -f "$examples_dir/$category/onmouseover.webp" ) {
|
||||||
|
$example_mouseover_html = "onmouseover=\"this.src='/$project/$category/onmouseover.webp'\" onmouseout=\"this.src='$example_image_url'\";";
|
||||||
|
}
|
||||||
|
|
||||||
|
return "
|
||||||
|
<a href='/$project/$category/$example'>
|
||||||
|
<div>
|
||||||
|
<img src='$example_image_url' $example_mouseover_html />
|
||||||
|
<div>$example_no_num</div>
|
||||||
|
</div>
|
||||||
|
</a>"
|
||||||
|
;
|
||||||
|
}
|
||||||
|
|
||||||
|
sub generate_example_thumbnails_for_category {
|
||||||
|
my $project = shift;
|
||||||
|
my $category = shift;
|
||||||
|
my @examples = get_examples_for_category($category);
|
||||||
|
my $retval = '';
|
||||||
|
foreach my $example (@examples) {
|
||||||
|
$retval .= generate_example_thumbnail($project, $category, $example);
|
||||||
|
}
|
||||||
|
return $retval;
|
||||||
|
}
|
||||||
|
|
||||||
sub handle_category_dir {
|
sub handle_category_dir {
|
||||||
my $category = shift;
|
my $category = shift;
|
||||||
|
|
||||||
|
@ -220,26 +300,22 @@ sub handle_category_dir {
|
||||||
|
|
||||||
closedir($dh);
|
closedir($dh);
|
||||||
|
|
||||||
my $examples_list_html = "";
|
my $examples_list_html = generate_example_thumbnails_for_category($project, $category);
|
||||||
foreach my $example (get_examples_for_category($category)) {
|
|
||||||
# !!! FIXME: image
|
my $dst = "$output_dir/$category";
|
||||||
my $example_image_url = "/$project/placeholder.png";
|
|
||||||
$examples_list_html .= "
|
do_copy("$examples_dir/$category/thumbnail.png", "$dst/thumbnail.png") if ( -f "$examples_dir/$category/thumbnail.png" );
|
||||||
<a href='/$project/$category/$example'>
|
do_copy("$examples_dir/$category/onmouseover.webp", "$dst/onmouseover.webp") if ( -f "$examples_dir/$category/onmouseover.webp" );
|
||||||
<div>
|
|
||||||
<img src='$example_image_url' />
|
my $category_description = get_category_description($category);
|
||||||
<div>$category/$example</div>
|
|
||||||
</div>
|
|
||||||
</a>";
|
|
||||||
}
|
|
||||||
|
|
||||||
# write category page
|
# write category page
|
||||||
my $dst = "$output_dir/$category";
|
|
||||||
my $html = '';
|
my $html = '';
|
||||||
open my $htmltemplate, '<', "$examples_dir/template-category.html" or die("Couldn't open '$examples_dir/template-category.html': $!\n");
|
open my $htmltemplate, '<', "$examples_dir/template-category.html" or die("Couldn't open '$examples_dir/template-category.html': $!\n");
|
||||||
while (<$htmltemplate>) {
|
while (<$htmltemplate>) {
|
||||||
s/\@project_name\@/$project/g;
|
s/\@project_name\@/$project/g;
|
||||||
s/\@category_name\@/$category/g;
|
s/\@category_name\@/$category/g;
|
||||||
|
s/\@category_description\@/$category_description/g;
|
||||||
s/\@examples_list_html\@/$examples_list_html/g;
|
s/\@examples_list_html\@/$examples_list_html/g;
|
||||||
$html .= $_;
|
$html .= $_;
|
||||||
}
|
}
|
||||||
|
@ -276,7 +352,7 @@ do_mkdir($output_dir);
|
||||||
build_latest();
|
build_latest();
|
||||||
|
|
||||||
do_copy("$examples_dir/template.css", "$output_dir/examples.css");
|
do_copy("$examples_dir/template.css", "$output_dir/examples.css");
|
||||||
do_copy("$examples_dir/template-placeholder.png", "$output_dir/placeholder.png");
|
do_copy("$examples_dir/template-placeholder.png", "$output_dir/thumbnail.png");
|
||||||
|
|
||||||
opendir(my $dh, $examples_dir) or die("Couldn't opendir '$examples_dir': $!\n");
|
opendir(my $dh, $examples_dir) or die("Couldn't opendir '$examples_dir': $!\n");
|
||||||
|
|
||||||
|
@ -292,19 +368,10 @@ closedir($dh);
|
||||||
# write homepage
|
# write homepage
|
||||||
my $homepage_list_html = "";
|
my $homepage_list_html = "";
|
||||||
foreach my $category (get_categories()) {
|
foreach my $category (get_categories()) {
|
||||||
$homepage_list_html .= "<h2>$category</h2>";
|
my $category_description = get_category_description($category);
|
||||||
|
$homepage_list_html .= "<h2>$category_description</h2>";
|
||||||
$homepage_list_html .= "<div class='list'>";
|
$homepage_list_html .= "<div class='list'>";
|
||||||
foreach my $example (get_examples_for_category($category)) {
|
$homepage_list_html .= generate_example_thumbnails_for_category($project, $category);
|
||||||
# !!! FIXME: image
|
|
||||||
my $example_image_url = "/$project/placeholder.png";
|
|
||||||
$homepage_list_html .= "
|
|
||||||
<a href='/$project/$category/$example'>
|
|
||||||
<div>
|
|
||||||
<img src='$example_image_url' />
|
|
||||||
<div>$category/$example</div>
|
|
||||||
</div>
|
|
||||||
</a>";
|
|
||||||
}
|
|
||||||
$homepage_list_html .= "</div>";
|
$homepage_list_html .= "</div>";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
BIN
examples/asyncio/01-load-bitmaps/thumbnail.png
Normal file
After Width: | Height: | Size: 74 KiB |
1
examples/asyncio/description.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Asynchronous I/O
|
BIN
examples/audio/onmouseover.webp
Normal file
After Width: | Height: | Size: 172 KiB |
BIN
examples/audio/thumbnail.png
Normal file
After Width: | Height: | Size: 14 KiB |
BIN
examples/camera/01-read-and-draw/onmouseover.webp
Normal file
After Width: | Height: | Size: 339 KiB |
BIN
examples/camera/01-read-and-draw/thumbnail.png
Normal file
After Width: | Height: | Size: 234 KiB |
13
examples/categories.txt
Normal file
|
@ -0,0 +1,13 @@
|
||||||
|
# Blank lines and lines that start with '#' in this file are ignored.
|
||||||
|
|
||||||
|
# Categories, by directory name, go in here, in the order they should be
|
||||||
|
# listed on the main page. If this file is missing, it'll assume any
|
||||||
|
# subdirectory is a category and sort them alphabetically.
|
||||||
|
|
||||||
|
renderer
|
||||||
|
input
|
||||||
|
audio
|
||||||
|
camera
|
||||||
|
asyncio
|
||||||
|
pen
|
||||||
|
demo
|
BIN
examples/demo/01-snake/onmouseover.webp
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
examples/demo/01-snake/thumbnail.png
Normal file
After Width: | Height: | Size: 2.9 KiB |
BIN
examples/demo/02-woodeneye-008/onmouseover.webp
Normal file
After Width: | Height: | Size: 457 KiB |
BIN
examples/demo/02-woodeneye-008/thumbnail.png
Normal file
After Width: | Height: | Size: 25 KiB |
BIN
examples/demo/03-infinite-monkeys/onmouseover.webp
Normal file
After Width: | Height: | Size: 93 KiB |
BIN
examples/demo/03-infinite-monkeys/thumbnail.png
Normal file
After Width: | Height: | Size: 7.6 KiB |
BIN
examples/demo/04-bytepusher/onmouseover.webp
Normal file
After Width: | Height: | Size: 420 KiB |
BIN
examples/demo/04-bytepusher/thumbnail.png
Normal file
After Width: | Height: | Size: 23 KiB |
1
examples/demo/description.txt
Normal file
|
@ -0,0 +1 @@
|
||||||
|
Full game and app demos
|
BIN
examples/input/01-joystick-polling/onmouseover.webp
Normal file
After Width: | Height: | Size: 47 KiB |
BIN
examples/input/01-joystick-polling/thumbnail.png
Normal file
After Width: | Height: | Size: 5.8 KiB |
BIN
examples/input/02-joystick-events/onmouseover.webp
Normal file
After Width: | Height: | Size: 2.2 MiB |
BIN
examples/input/02-joystick-events/thumbnail.png
Normal file
After Width: | Height: | Size: 30 KiB |
BIN
examples/pen/01-drawing-lines/onmouseover.webp
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
examples/pen/01-drawing-lines/thumbnail.png
Normal file
After Width: | Height: | Size: 2 KiB |
BIN
examples/renderer/01-clear/onmouseover.webp
Normal file
After Width: | Height: | Size: 68 KiB |
BIN
examples/renderer/01-clear/thumbnail.png
Normal file
After Width: | Height: | Size: 2 KiB |
BIN
examples/renderer/02-primitives/thumbnail.png
Normal file
After Width: | Height: | Size: 8.6 KiB |
BIN
examples/renderer/03-lines/onmouseover.webp
Normal file
After Width: | Height: | Size: 64 KiB |
BIN
examples/renderer/03-lines/thumbnail.png
Normal file
After Width: | Height: | Size: 28 KiB |
BIN
examples/renderer/04-points/onmouseover.webp
Normal file
After Width: | Height: | Size: 152 KiB |
BIN
examples/renderer/04-points/thumbnail.png
Normal file
After Width: | Height: | Size: 7.9 KiB |
BIN
examples/renderer/05-rectangles/onmouseover.webp
Normal file
After Width: | Height: | Size: 74 KiB |
BIN
examples/renderer/05-rectangles/thumbnail.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
examples/renderer/06-textures/onmouseover.webp
Normal file
After Width: | Height: | Size: 592 KiB |
BIN
examples/renderer/06-textures/thumbnail.png
Normal file
After Width: | Height: | Size: 233 KiB |
BIN
examples/renderer/07-streaming-textures/onmouseover.webp
Normal file
After Width: | Height: | Size: 17 KiB |
BIN
examples/renderer/07-streaming-textures/thumbnail.png
Normal file
After Width: | Height: | Size: 3.5 KiB |
BIN
examples/renderer/08-rotating-textures/onmouseover.webp
Normal file
After Width: | Height: | Size: 306 KiB |
BIN
examples/renderer/08-rotating-textures/thumbnail.png
Normal file
After Width: | Height: | Size: 89 KiB |
BIN
examples/renderer/09-scaling-textures/onmouseover.webp
Normal file
After Width: | Height: | Size: 311 KiB |
BIN
examples/renderer/09-scaling-textures/thumbnail.png
Normal file
After Width: | Height: | Size: 82 KiB |
BIN
examples/renderer/10-geometry/onmouseover.webp
Normal file
After Width: | Height: | Size: 116 KiB |
BIN
examples/renderer/10-geometry/thumbnail.png
Normal file
After Width: | Height: | Size: 56 KiB |
BIN
examples/renderer/11-color-mods/onmouseover.webp
Normal file
After Width: | Height: | Size: 272 KiB |
BIN
examples/renderer/11-color-mods/thumbnail.png
Normal file
After Width: | Height: | Size: 120 KiB |
BIN
examples/renderer/14-viewport/thumbnail.png
Normal file
After Width: | Height: | Size: 143 KiB |
BIN
examples/renderer/15-cliprect/onmouseover.webp
Normal file
After Width: | Height: | Size: 254 KiB |
BIN
examples/renderer/15-cliprect/thumbnail.png
Normal file
After Width: | Height: | Size: 85 KiB |
BIN
examples/renderer/17-read-pixels/onmouseover.webp
Normal file
After Width: | Height: | Size: 471 KiB |
BIN
examples/renderer/17-read-pixels/thumbnail.png
Normal file
After Width: | Height: | Size: 100 KiB |
BIN
examples/renderer/18-debug-text/thumbnail.png
Normal file
After Width: | Height: | Size: 4.2 KiB |
|
@ -4,7 +4,7 @@
|
||||||
<meta charset="utf-8" />
|
<meta charset="utf-8" />
|
||||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
<meta name="viewport" content="width=device-width, initial-scale=1" />
|
||||||
<title>@project_name@ Examples: @category_name@</title>
|
<title>@project_name@ Examples: @category_description@</title>
|
||||||
<link
|
<link
|
||||||
rel="stylesheet"
|
rel="stylesheet"
|
||||||
type="text/css"
|
type="text/css"
|
||||||
|
@ -18,7 +18,7 @@
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
<header>
|
<header>
|
||||||
<a href="/">SDL Examples</a>
|
<a href="/">@project_name@ Examples</a>
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<nav class="breadcrumb">
|
<nav class="breadcrumb">
|
||||||
|
@ -27,7 +27,7 @@
|
||||||
<li><a href="/@project_name@/@category_name@">@category_name@</a></li>
|
<li><a href="/@project_name@/@category_name@">@category_name@</a></li>
|
||||||
</ul>
|
</ul>
|
||||||
</nav>
|
</nav>
|
||||||
<h1>@project_name@ examples: @category_name@</h1>
|
<h1>@project_name@ examples: @category_description@</h1>
|
||||||
<div class="list">@examples_list_html@</div>
|
<div class="list">@examples_list_html@</div>
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
|
@ -28,8 +28,6 @@
|
||||||
</nav>
|
</nav>
|
||||||
<h1>@project_name@ examples</h1>
|
<h1>@project_name@ examples</h1>
|
||||||
|
|
||||||
<p>Check out the @project_name@ examples here!</p>
|
|
||||||
|
|
||||||
@homepage_list_html@
|
@homepage_list_html@
|
||||||
</main>
|
</main>
|
||||||
</body>
|
</body>
|
||||||
|
|
Before Width: | Height: | Size: 123 B After Width: | Height: | Size: 34 KiB |