From e5c6bd1708e4d2471cc95a28543361cdea1f85fa Mon Sep 17 00:00:00 2001 From: doup Date: Sat, 30 Nov 2024 18:10:51 +0100 Subject: [PATCH 1/3] Move common parts of the example pages to a layout --- templates/example-webgpu.html | 130 ++----------------------------- templates/example.html | 131 ++------------------------------ templates/examples-webgpu.html | 50 +++--------- templates/examples.html | 49 ++---------- templates/layouts/example.html | 123 ++++++++++++++++++++++++++++++ templates/layouts/examples.html | 34 +++++++++ 6 files changed, 191 insertions(+), 326 deletions(-) create mode 100644 templates/layouts/example.html create mode 100644 templates/layouts/examples.html diff --git a/templates/example-webgpu.html b/templates/example-webgpu.html index 3a9341f013..505da44411 100644 --- a/templates/example-webgpu.html +++ b/templates/example-webgpu.html @@ -1,124 +1,10 @@ -{% extends "layouts/base.html" %} -{% block content %} -
-
- {% set total_ancestors = page.ancestors | length %} - {% set parent_idx = total_ancestors - 1 %} - {% set category = get_section(path=page.ancestors | nth(n=parent_idx)) %} -

{{ category.title }} / {{ page.title }}

- Back to examples - - View in GitHub - -
-
-

Support Warning

- WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. If they don't work on - your configuration, you can check the WebGL2 examples here. -
-
-
-
-
-
-
-
-
- -
-
- {% set filename = page.extra.code_path | split(pat="/") | last %} - {{ filename }}: - - {% set code = load_data(path=page.extra.code_path) %} - {% set code_md = "```rust" ~ newline ~ code ~ "```" %} - {{ code_md | markdown(inline=true) | safe }} -
- {% for shader in page.extra.shader_code_paths %} -
- {{ shader }}: +{% extends "layouts/example.html" %} - {% set code = load_data(path="static/assets/examples/" ~ shader) %} - {% set code_md = "```rust" ~ newline ~ code ~ "```" %} - {{ code_md | markdown(inline=true) | safe }} -
- {% endfor %} -
- -{% endblock content %} diff --git a/templates/example.html b/templates/example.html index 554fb7e681..a68b221e19 100644 --- a/templates/example.html +++ b/templates/example.html @@ -1,123 +1,8 @@ -{% extends "layouts/base.html" %} -{% block content %} -
-
- {% set total_ancestors = page.ancestors | length %} - {% set parent_idx = total_ancestors - 1 %} - {% set category = get_section(path=page.ancestors | nth(n=parent_idx)) %} -

{{ category.title }} / {{ page.title }}

- Back to examples - - View in GitHub - -
-
- This example is running in WebGL2 and should work in most browsers. You can check the WebGPU examples here. -
-
-
-
-
-
-
-
-
- -
- -
- {% set filename = page.extra.code_path | split(pat="/") | last %} - {{ filename }}: - - {% set code = load_data(path=page.extra.code_path) %} - {% set code_md = "```rust" ~ newline ~ code ~ "```" %} - {{ code_md | markdown(inline=true) | safe }} -
- {% for shader in page.extra.shader_code_paths %} -
- {{ shader }}: - - {% set code = load_data(path="static/assets/examples/" ~ shader) %} - {% set code_md = "```rust" ~ newline ~ code ~ "```" %} - {{ code_md | markdown(inline=true) | safe }} -
- {% endfor %} -
- -{% endblock content %} +{% extends "layouts/example.html" %} + +{% block examples_url %}/examples{% endblock examples_url %} +{% block wasm_base_url %}https://bevy-webgl2-examples.pages.dev{% endblock wasm_base_url %} +{% block intro %} +This example is running in WebGL2 and should work in most browsers. +You can check the WebGPU examples here. +{% endblock intro %} \ No newline at end of file diff --git a/templates/examples-webgpu.html b/templates/examples-webgpu.html index e964e14633..03f08f6949 100644 --- a/templates/examples-webgpu.html +++ b/templates/examples-webgpu.html @@ -1,40 +1,10 @@ -{% extends "layouts/page-with-menu.html" %} -{% import "macros/assets.html" as assets_macros %} -{% block page_name %}Examples{% endblock page_name %} -{% block mobile_page_menu %}{{ assets_macros::assets_menu(prefix="page-menu", root=section) }}{% endblock mobile_page_menu %} -{% block page_menu %}{{ assets_macros::assets_menu(prefix="page-menu", root=section) }}{% endblock page_menu %} -{% block page_content %} -
-
- These examples demonstrate how to use Bevy's features in a minimal, easy to understand way. Click an example below - to run it in - your browser (using WASM + WebGPU) and view the source code. You can also view these examples (and others) in the - Bevy repo. -

Support Warning

- WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. If they don't work on - your configuration, you can check the WebGL2 examples here. -
- - {% for subsection in section.subsections %} - {% set section = get_section(path=subsection) %} -

- {{ section.title }}# -

- {% if section.pages %} -
- {% set pages = section.pages %} - {% if section.extra.sort_order_reversed %} - {% set pages = section.pages | reverse %} - {% endif %} - {% for post in pages %}{{ assets_macros::card(post=post) }}{% endfor %} -
- {% endif %} - {% endfor %} -
- -{% endblock page_content %} +{% extends "layouts/examples.html" %} + +{% block intro %} +These examples demonstrate how to use Bevy's features in a minimal, easy to understand way. +Click an example below to run it in your browser (using WASM + WebGPU) and view the source code. +You can also view these examples (and others) in the Bevy repo. +

Support Warning

+WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. +If they don't work on your configuration, you can check the WebGL2 examples here. +{% endblock intro %} diff --git a/templates/examples.html b/templates/examples.html index c9fd891742..0f24a30c5c 100644 --- a/templates/examples.html +++ b/templates/examples.html @@ -1,41 +1,8 @@ -{% extends "layouts/page-with-menu.html" %} -{% import "macros/assets.html" as assets_macros %} -{% block page_name %}Examples{% endblock page_name %} -{% block mobile_page_menu %}{{ assets_macros::assets_menu(prefix="page-menu", root=section) }}{% endblock mobile_page_menu %} -{% block page_menu %}{{ assets_macros::assets_menu(prefix="page-menu", root=section) }}{% endblock page_menu %} -{% block page_content %} -
-
- These examples demonstrate how to use Bevy's features in a minimal, easy to understand way. Click an example below - to run it in - your browser (using WASM + WebGL) and view the source code. You can also view these examples (and others) in the - Bevy repo. -

- If you would like to try WASM + WebGPU, you can explore our live WebGPU examples - page. -

-
- - {% for subsection in section.subsections %} - {% set section = get_section(path=subsection) %} -

- {{ section.title }}# -

- {% if section.pages %} -
- {% set pages = section.pages %} - {% if section.extra.sort_order_reversed %} - {% set pages = section.pages | reverse %} - {% endif %} - {% for post in pages %}{{ assets_macros::card(post=post) }}{% endfor %} -
- {% endif %} - {% endfor %} -
- -{% endblock page_content %} +{% extends "layouts/examples.html" %} + +{% block intro %} +These examples demonstrate how to use Bevy's features in a minimal, easy to understand way. +Click an example below to run it in your browser (using WASM + WebGL) and view the source code. +You can also view these examples (and others) in the Bevy repo. +

If you would like to try WASM + WebGPU, you can explore our live WebGPU examples page.

+{% endblock intro %} diff --git a/templates/layouts/example.html b/templates/layouts/example.html new file mode 100644 index 0000000000..6970cf86aa --- /dev/null +++ b/templates/layouts/example.html @@ -0,0 +1,123 @@ +{% extends "layouts/base.html" %} +{% block content %} +
+
+ {% set total_ancestors = page.ancestors | length %} + {% set parent_idx = total_ancestors - 1 %} + {% set category = get_section(path=page.ancestors | nth(n=parent_idx)) %} +

{{ category.title }} / {{ page.title }}

+ Back to examples + + View in GitHub + +
+
+ {% block intro %}{% endblock intro %} +
+
+
+
+
+
+
+
+
+ +
+ +
+ {% set filename = page.extra.code_path | split(pat="/") | last %} + {{ filename }}: + + {% set code = load_data(path=page.extra.code_path) %} + {% set code_md = "```rust" ~ newline ~ code ~ "```" %} + {{ code_md | markdown(inline=true) | safe }} +
+ {% for shader in page.extra.shader_code_paths %} +
+ {{ shader }}: + + {% set code = load_data(path="static/assets/examples/" ~ shader) %} + {% set code_md = "```rust" ~ newline ~ code ~ "```" %} + {{ code_md | markdown(inline=true) | safe }} +
+ {% endfor %} +
+ +{% endblock content %} diff --git a/templates/layouts/examples.html b/templates/layouts/examples.html new file mode 100644 index 0000000000..f865cf6a48 --- /dev/null +++ b/templates/layouts/examples.html @@ -0,0 +1,34 @@ +{% extends "layouts/page-with-menu.html" %} +{% import "macros/assets.html" as assets_macros %} +{% block page_name %}Examples{% endblock page_name %} +{% block mobile_page_menu %}{{ assets_macros::assets_menu(prefix="page-menu", root=section) }}{% endblock mobile_page_menu %} +{% block page_menu %}{{ assets_macros::assets_menu(prefix="page-menu", root=section) }}{% endblock page_menu %} +{% block page_content %} +
+
+ {% block intro %}{% endblock intro %} +
+ + {% for subsection in section.subsections %} + {% set section = get_section(path=subsection) %} +

+ {{ section.title }}# +

+ {% if section.pages %} +
+ {% set pages = section.pages %} + {% if section.extra.sort_order_reversed %} + {% set pages = section.pages | reverse %} + {% endif %} + {% for post in pages %}{{ assets_macros::card(post=post) }}{% endfor %} +
+ {% endif %} + {% endfor %} +
+ +{% endblock page_content %} From 034087d6f6689fc8dc0234263a58101c1c9cc523 Mon Sep 17 00:00:00 2001 From: doup Date: Sat, 30 Nov 2024 18:15:18 +0100 Subject: [PATCH 2/3] Fix indentation --- templates/layouts/example.html | 128 ++++++++++++++++----------------- 1 file changed, 64 insertions(+), 64 deletions(-) diff --git a/templates/layouts/example.html b/templates/layouts/example.html index 6970cf86aa..0b8b860020 100644 --- a/templates/layouts/example.html +++ b/templates/layouts/example.html @@ -45,79 +45,79 @@

{{ category.title }} / {{ page.title }}

{% endfor %} + window.bevyLoadingBarFetch = loadingBarFetch; + + {# + // The following .catch() is a simple filter to remove an exception thrown by winit in + // its normal control flow. This exception will always be thrown and is not an error. + // Details here: https://github.com/rust-windowing/winit/blob/master/src/platform_impl/web/event_loop/mod.rs + #} + init().catch((error) => { + if (!error.message.startsWith("Using exceptions for control flow, don't mind me. This isn't actually an error!")) { + throw error; + } + }); + {% endblock content %} From 0d7bad403bdb1426dffefba7020be5d8d235f98a Mon Sep 17 00:00:00 2001 From: doup Date: Sat, 30 Nov 2024 18:20:37 +0100 Subject: [PATCH 3/3] Fix file-end newlines --- templates/example-webgpu.html | 1 - templates/example.html | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/templates/example-webgpu.html b/templates/example-webgpu.html index 505da44411..ff63313fb8 100644 --- a/templates/example-webgpu.html +++ b/templates/example-webgpu.html @@ -7,4 +7,3 @@

Support Warning

WebGPU is currently only supported on Chrome starting with version 113, and only on desktop. If they don't work on your configuration, you can check the WebGL2 examples here. {% endblock intro %} - diff --git a/templates/example.html b/templates/example.html index a68b221e19..d73969e1ae 100644 --- a/templates/example.html +++ b/templates/example.html @@ -5,4 +5,4 @@ {% block intro %} This example is running in WebGL2 and should work in most browsers. You can check the WebGPU examples here. -{% endblock intro %} \ No newline at end of file +{% endblock intro %}