Skip to content

Commit 3f548a1

Browse files
committed
Replace sandboxes with code blocks
1 parent 61f8309 commit 3f548a1

File tree

8 files changed

+135
-23
lines changed

8 files changed

+135
-23
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.docusaurus
99
.cache-loader
1010
/docs/js-sdk/api
11+
/docs/js-sdk/examples
1112
/docs/c2patool/*.md
1213
/docs/c2patool/docs/*.md
1314
/docs/c2pa-node/*.md

docs/js-sdk/getting-started/quick-start.mdx

Lines changed: 23 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ title: Quick start
55

66
import Tabs from '@theme/Tabs';
77
import TabItem from '@theme/TabItem';
8-
import Sandbox from '../../../src/components/Sandbox';
98

109
## Prerequisites
1110

@@ -37,19 +36,17 @@ The quickest way to get up and running is to use a CDN such as [jsDelivr](https:
3736
Static assets include the following, as seen in the config passed to [`createC2pa`](../../js-sdk/api/c2pa.createc2pa):
3837

3938
```js
39+
const version = '0.24.2';
4040
{
4141
wasmSrc: `https://cdn.jsdelivr.net/npm/c2pa@${version}/dist/assets/wasm/toolkit_bg.wasm`,
4242
workerSrc: `https://cdn.jsdelivr.net/npm/c2pa@${version}/dist/c2pa.worker.min.js`,
4343
}
4444
```
4545

4646
:::caution
47-
The version numbers provided in the CDN URLs _must_ match in all of the places you reference the
48-
library. To make it easy, use a variable that provides the version as shown in the example.
47+
The version numbers provided in the CDN URLs _must_ be the same in all of the places you reference the library. To make it easy, use a variable that provides the version as shown in the example.
4948
:::
5049

51-
<Sandbox file="/examples/cdn/main.ts" displayType="preview" />
52-
5350
### Using a package manager
5451

5552
You can also bring in the library with a package manager, such as `npm`, `pnpm`, or `yarn`. This way, all of the client side code is hosted with your app and there are no external dependencies. For example, using `npm`:
@@ -71,24 +68,33 @@ Be sure to configure your server to send proper `Content-Type` headers for these
7168

7269
Examples for common build systems are shown below. They are also available in the [c2pa-js-examples repository](https://github.com/contentauth/c2pa-js-examples).
7370

74-
export const ExampleLink = ({ example }) => {
75-
const linkText = `examples/${example}`;
76-
const link = `https://github.com/contentauth/c2pa-js/tree/main/${linkText}`;
77-
return (
78-
<div className="example-link">
79-
An example project is available here: <a href={link}>{linkText}</a>
80-
</div>
81-
);
82-
};
71+
import CodeBlock from '@theme/CodeBlock';
72+
import ViteExample from '!!raw-loader!../examples/quickstart/vite-main.ts';
73+
import RollupExample from '!!raw-loader!../examples/quickstart/rollup-main.ts';
74+
import WebPackExample from '!!raw-loader!../examples/quickstart/webpack-main.ts';
8375

8476
<Tabs lazy>
8577
<TabItem value="vite" label="Vite" default>
86-
<Sandbox file="/examples/quick-start/main.ts" />
78+
79+
This example is from [c2pa-js-examples/minimal-ts-vite/](https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/).
80+
81+
<CodeBlock language="ts">{ViteExample}</CodeBlock>
82+
8783
</TabItem>
84+
8885
<TabItem value="rollup" label="Rollup">
89-
<Sandbox example="minimal-ts-rollup" file="/src/main.ts" browserPath="/" />
86+
87+
This example is from [c2pa-js-examples/minimal-ts-rollup/](https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-rollup/).
88+
89+
<CodeBlock language="ts">{RollupExample}</CodeBlock>
90+
9091
</TabItem>
92+
9193
<TabItem value="webpack" label="Webpack">
92-
<Sandbox example="minimal-ts-webpack" file="/src/main.ts" browserPath="/" />
94+
95+
This example is from [c2pa-js-examples/minimal-ts-webpack/](https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-webpack/).
96+
97+
<CodeBlock language="ts">{WebPackExample}</CodeBlock>
98+
9399
</TabItem>
94100
</Tabs>
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
id: sandbox-rollup
3+
title: 'Code Sandbox: Rollup example'
4+
hide_table_of_contents: true
5+
---
6+
7+
import Sandbox from '../../../src/components/Sandbox';
8+
9+
The source code for this example is in the [c2pa-js-examples repo](https://github.com/contentauth/c2pa-js-examples/tree/main/minimal-ts-rollup).
10+
11+
<Sandbox file="../examples/quickstart/rollup-main.ts" browserPath="/" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
id: sandbox-vite
3+
title: 'Code Sandbox: Vite example'
4+
hide_table_of_contents: true
5+
---
6+
7+
import Sandbox from '../../../src/components/Sandbox';
8+
9+
The source code for this example is in the [c2pa-js-examples repo](https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/).
10+
11+
<Sandbox file="../examples/quickstart/vite-main.ts" browserPath="/" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
id: sandbox-webpack
3+
title: 'Code Sandbox: Webpack example'
4+
hide_table_of_contents: true
5+
---
6+
7+
import Sandbox from '../../../src/components/Sandbox';
8+
9+
The source code for this example is in the [c2pa-js-examples repo](https://github.com/contentauth/c2pa-js-examples/tree/main/minimal-ts-webpack).
10+
11+
<Sandbox file="../examples/quickstart/webpack-main.ts" browserPath="/" />
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
---
2+
id: sandbox-viewing-manifest
3+
title: 'Code Sandbox: Viewing manifest data'
4+
hide_table_of_contents: true
5+
---
6+
7+
import Sandbox from '../../../src/components/Sandbox';
8+
9+
The source code for this example is in the [c2pa-js-examples repo](https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/examples/active-manifest/main.ts).
10+
11+
<Sandbox file="/examples/active-manifest/main.ts" displayType="preview" />

docs/js-sdk/guides/viewing-provenance.mdx

Lines changed: 28 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
---
22
id: viewing-manifest-data
33
title: Viewing manifest data
4-
hide_table_of_contents: true
54
---
65

7-
import Sandbox from '../../../src/components/Sandbox';
8-
96
## Initializing the library
107

118
The way that you import `wasmSrc` and `workerSrc` varies depending on the build system you use. For more information, see [Quick start](../getting-started/quick-start#bringing-in-the-library).
@@ -20,10 +17,35 @@ The [`manifestStore`](../../js-sdk/api/c2pa.c2pareadresult.manifeststore) object
2017
- **activeManifest**: A pointer to the latest [`manifest`](../../js-sdk/api/c2pa.manifest) in the manifest store. Effectively the "parent" manifest, this is the likely starting point when inspecting an asset's C2PA data.
2118
- **validationStatus**: A list of any validation errors the library generated when processing an asset. See [Validation](./validation) for more information.
2219

23-
[`Manifest`](../../js-sdk/api/c2pa.manifest) objects contain properties pertaining to an asset's provenance, along with convenient interfaces for [accessing assertion data](../../js-sdk/api/c2pa.assertionaccessor) and [generating a thumbnail](../../js-sdk/api/c2pa.thumbnail). The example in this sandbox demonstrates a basic workflow: reading a sample image, checking for the presence of a manifest store, and displaying the data in the active manifest:
20+
[`Manifest`](../../js-sdk/api/c2pa.manifest) objects contain properties pertaining to an asset's provenance, along with convenient interfaces for [accessing assertion data](../../js-sdk/api/c2pa.assertionaccessor) and [generating a thumbnail](../../js-sdk/api/c2pa.thumbnail).
21+
22+
## Example
2423

25-
<Sandbox file="/examples/active-manifest/main.ts" displayType="preview" />
24+
This example from the [c2pa-js-examples repo](https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/examples/active-manifest/) demonstrates a basic workflow:
2625

27-
The source code for this example is in the [c2pa-js-examples repo](https://github.com/contentauth/c2pa-js-examples/blob/main/minimal-ts-vite/examples/active-manifest/main.ts).
26+
- Reading an image.
27+
- Checking for the presence of a manifest store.
28+
- Displaying the data in the active manifest.
2829

2930
This example also features the use of the [`selectProducer`](../../js-sdk/api/c2pa.selectproducer) selector function. See [Selectors](./selectors) for more information.
31+
32+
To view and execute this example in a live [code sandbox](https://codesandbox.io/docs/learn/legacy-sandboxes/overview), see [Sandbox: Viewing manifest data](./sandbox-viewing-manifest).
33+
34+
import Tabs from '@theme/Tabs';
35+
import TabItem from '@theme/TabItem';
36+
37+
import CodeBlock from '@theme/CodeBlock';
38+
import ViewManifestExampleTS from '!!raw-loader!../examples/view-manifest/main.ts';
39+
import ViewManifestExampleHTML from '!!raw-loader!../examples/view-manifest/index.html';
40+
41+
<Tabs lazy>
42+
<TabItem value="ts" label="main.ts" default>
43+
<CodeBlock language="ts">{ViewManifestExampleTS}</CodeBlock>
44+
</TabItem>
45+
46+
{' '}
47+
<TabItem value="html" label="index.html">
48+
<CodeBlock language="html">{ViewManifestExampleHTML}</CodeBlock>
49+
</TabItem>
50+
51+
</Tabs>

scripts/fetch-readme.js

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,45 @@ $ touch .gitkeep
1919
*/
2020

2121
const readmes = [
22+
// js-sdk examples - View manifest
23+
{
24+
dest: resolve(
25+
__dirname,
26+
'../docs/js-sdk/examples/view-manifest/index.html',
27+
),
28+
repo: 'contentauth/c2pa-js',
29+
path: 'examples/minimal-ts-vite/examples/active-manifest/index.html',
30+
},
31+
{
32+
dest: resolve(__dirname, '../docs/js-sdk/examples/view-manifest/main.ts'),
33+
repo: 'contentauth/c2pa-js',
34+
path: 'examples/minimal-ts-vite/examples/active-manifest/main.ts',
35+
},
36+
// Vite Quickstart
37+
{
38+
dest: resolve(__dirname, '../docs/js-sdk/examples/quickstart/vite-main.ts'),
39+
repo: 'contentauth/c2pa-js',
40+
path: 'examples/minimal-ts-vite/examples/cdn/main.ts',
41+
},
42+
// Rollup Quickstart
43+
{
44+
dest: resolve(
45+
__dirname,
46+
'../docs/js-sdk/examples/quickstart/rollup-main.ts',
47+
),
48+
repo: 'contentauth/c2pa-js',
49+
path: 'examples/minimal-ts-rollup/src/main.ts',
50+
},
51+
// WebPack Quickstart
52+
{
53+
dest: resolve(
54+
__dirname,
55+
'../docs/js-sdk/examples/quickstart/webpack-main.ts',
56+
),
57+
repo: 'contentauth/c2pa-js',
58+
path: 'examples/minimal-ts-webpack/src/index.ts',
59+
},
60+
2261
// c2patool
2362
{
2463
dest: resolve(__dirname, '../docs/c2patool/readme.md'),

0 commit comments

Comments
 (0)