Skip to content

Commit dd985ca

Browse files
authored
Add "view as standalone webpage" link; improvements for external samples (#473)
1 parent 372c617 commit dd985ca

File tree

10 files changed

+52
-43
lines changed

10 files changed

+52
-43
lines changed

index.html

+2-1
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,8 @@ <h1>
5656
<div id="sample" style="display: none;">
5757
<div class="sampleInfo">
5858
<h1 id="title"></h1>
59-
<a id="src" target="_blank" rel="noreferrer" href="">See it on Github!</a>
59+
<a id="src" target="_blank" rel="noreferrer" href="">View source!</a>
60+
&mdash; <a id="standalone" target="_blank" rel="noreferrer" href="">View as standalone webpage</a>
6061
<p id="description"></p>
6162
</div>
6263
<div class="sampleContainer"></div>

public/css/styles.css

+7-3
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,13 @@ body {
2121

2222
a {
2323
text-decoration: none;
24-
color: var(--link)
24+
color: var(--link);
25+
}
26+
a:not([href]), a[href=""] {
27+
/* link is missing href */
28+
text-decoration: wavy underline;
29+
color: #f00;
2530
}
26-
2731
a:hover {
2832
text-decoration: underline;
2933
}
@@ -49,4 +53,4 @@ main {
4953

5054
.cm-editor {
5155
max-height: 100vh;
52-
}
56+
}

sample/bundleCulling/meta.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default {
22
name: 'Bundle Culling',
3-
description: `A demonstration of using frustum culling with render bundles through indirect instanced draw calls.
4-
5-
Source at <https://github.com/toji/webgpu-bundle-culling/>
6-
`,
3+
description: `A demonstration of using frustum culling with render bundles through indirect instanced draw calls.`,
74
filename: __DIRNAME__,
8-
url: 'https://toji.github.io/webgpu-bundle-culling/',
5+
external: {
6+
url: 'https://toji.github.io/webgpu-bundle-culling/',
7+
sourceURL: 'https://github.com/toji/webgpu-bundle-culling',
8+
},
99
sources: [],
1010
};

sample/clusteredShading/meta.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default {
22
name: 'Clustered Shading',
3-
description: `Shows a simple clustered forward shading renderer.
4-
5-
Source at <https://github.com/toji/webgpu-clustered-shading/>
6-
`,
3+
description: `Shows a simple clustered forward shading renderer.`,
74
filename: __DIRNAME__,
8-
url: 'https://toji.github.io/webgpu-clustered-shading/',
5+
external: {
6+
url: 'https://toji.github.io/webgpu-clustered-shading/',
7+
sourceURL: 'https://github.com/toji/webgpu-clustered-shading',
8+
},
99
sources: [],
1010
};

sample/marchingCubes/meta.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default {
22
name: 'Marching Cubes',
3-
description: `This example demonstrates how to dynamically generate procedural meshes using a signed distance field and a multi-pass marching cubes algorithm on the GPU.
4-
5-
Source at <https://github.com/tcoppex/webgpu-marchingcubes>
6-
`,
3+
description: `This example demonstrates how to dynamically generate procedural meshes using a signed distance field and a multi-pass marching cubes algorithm on the GPU.`,
74
filename: __DIRNAME__,
8-
url: 'https://tcoppex.github.io/webgpu-marchingcubes/',
5+
external: {
6+
url: 'https://tcoppex.github.io/webgpu-marchingcubes/',
7+
sourceURL: 'https://github.com/tcoppex/webgpu-marchingcubes',
8+
},
99
sources: [],
1010
};

sample/metaballs/meta.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default {
22
name: 'Metaballs',
3-
description: `This example shows an implementation of metaballs with WebGPU.
4-
5-
Source at https://github.com/toji/webgpu-metaballs/
6-
`,
3+
description: `This example shows an implementation of metaballs with WebGPU.`,
74
filename: __DIRNAME__,
8-
url: 'https://toji.github.io/webgpu-metaballs/',
5+
external: {
6+
url: 'https://toji.github.io/webgpu-metaballs/',
7+
sourceURL: 'https://github.com/toji/webgpu-metaballs',
8+
},
99
sources: [],
1010
};

sample/pristineGrid/meta.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default {
22
name: 'Pristine Grid',
3-
description: `A simple WebGPU implementation of the "Pristine Grid" technique described in this wonderful little blog post: <https://bgolus.medium.com/the-best-darn-grid-shader-yet-727f9278b9d8>
4-
5-
Source at <https://github.com/toji/pristine-grid-webgpu/>
6-
`,
3+
description: `A simple WebGPU implementation of the "Pristine Grid" technique described in this wonderful little blog post: <https://bgolus.medium.com/the-best-darn-grid-shader-yet-727f9278b9d8>`,
74
filename: __DIRNAME__,
8-
url: 'https://toji.github.io/pristine-grid-webgpu/',
5+
external: {
6+
url: 'https://toji.github.io/pristine-grid-webgpu/',
7+
sourceURL: 'https://github.com/toji/pristine-grid-webgpu',
8+
},
99
sources: [],
1010
};

sample/spookyball/meta.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
export default {
22
name: 'Spookyball',
3-
description: `This example shows a simple game made with WebGPU.
4-
5-
Source at <https://github.com/toji/spookyball>
6-
`,
3+
description: `This example shows a simple game made with WebGPU.`,
74
filename: __DIRNAME__,
8-
url: 'https://spookyball.com',
5+
external: {
6+
url: 'https://spookyball.com',
7+
sourceURL: 'https://github.com/toji/spookyball',
8+
},
99
sources: [],
1010
};

src/main.ts

+12-8
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@ function getElem(
2727
const sampleListElem = getElem('#samplelist');
2828
const sampleElem = getElem('#sample');
2929
const githubElem = getElem('#src') as HTMLAnchorElement;
30+
const standaloneElem = getElem('#standalone') as HTMLAnchorElement;
3031
const introElem = getElem('#intro');
3132
const codeTabsElem = getElem('#codeTabs');
3233
const sourcesElem = getElem('#sources');
@@ -183,7 +184,7 @@ function setSampleIFrame(
183184
descriptionElem.innerHTML = '';
184185

185186
currentSampleInfo = sampleInfo;
186-
const { name, description, filename, url, sources } = sampleInfo || {
187+
const { name, description, filename, external, sources } = sampleInfo || {
187188
name: '',
188189
description: '',
189190
filename: '',
@@ -197,17 +198,18 @@ function setSampleIFrame(
197198
// Replace the iframe because changing src adds to the user's history.
198199
sampleContainerElem.innerHTML = '';
199200
if (filename) {
200-
const src = url || `${filename}${search}`;
201+
const src = external ? external.url : `${filename}${search}`;
201202
sampleContainerElem.appendChild(el('iframe', { src }));
202203
sampleContainerElem.style.height = sources.length > 0 ? '600px' : '100%';
203204

204-
if (url) {
205-
// If it's remote example, hide the github link and assume it's in the description.
206-
githubElem.style.display = 'none';
205+
if (external) {
206+
// For remote samples, get the source URL from the metadata.
207+
githubElem.href = external.sourceURL;
208+
standaloneElem.href = external.url;
207209
} else {
208-
// It's a local sample so show the github link.
209-
githubElem.style.display = '';
210+
// For local samples, generate a link to the source in this repo.
210211
githubElem.href = `https://github.com/webgpu/webgpu-samples/tree/main/${filename}`;
212+
standaloneElem.href = filename;
211213
}
212214

213215
// hide intro and show sample
@@ -294,7 +296,9 @@ for (const { title, description, samples } of pageCategories) {
294296
...Object.entries(samples).map(([key, sampleInfo]) =>
295297
el('li', {}, [
296298
el('a', {
297-
href: sampleInfo.filename,
299+
href: sampleInfo.external
300+
? sampleInfo.external.url
301+
: sampleInfo.filename,
298302
...(!sampleInfo.openInNewTab && {
299303
onClick: (e: PointerEvent) => {
300304
setSampleIFrameURL(e, sampleInfo);

src/samples.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export type SampleInfo = {
5252
description: string;
5353
openInNewTab?: boolean;
5454
filename: string; // used if sample is local
55-
url?: string; // used if sample is remote
55+
external?: { url: string; sourceURL: string }; // used if sample is remote
5656
sources: SourceInfo[];
5757
};
5858

0 commit comments

Comments
 (0)