|
1 | | -import { html } from 'uhtml-isomorphic' |
| 1 | +import { html } from 'htm/preact' |
| 2 | +import { render } from 'preact-render-to-string' |
2 | 3 |
|
3 | 4 | export default async function JSPage ({ |
4 | 5 | vars: { |
5 | 6 | siteName, |
6 | 7 | title, |
7 | 8 | } |
8 | 9 | }) { |
9 | | - return html` |
10 | | - <p>The js page is the only page type that can render the body with the set variables.</p> |
| 10 | + return render(html` |
| 11 | + <div class="js-page-example"> |
| 12 | + <h1>JavaScript Page Example</h1> |
| 13 | + |
| 14 | + <section class="explanation"> |
| 15 | + <h2>What is a JavaScript Page?</h2> |
| 16 | + <p> |
| 17 | + The JavaScript page type is the most powerful and flexible option in DOMStack. |
| 18 | + It allows you to: |
| 19 | + </p> |
| 20 | + <ul> |
| 21 | + <li>Access and use variables directly in your rendering logic</li> |
| 22 | + <li>Generate dynamic content based on data or conditions</li> |
| 23 | + <li>Use component-based architecture with Preact or other libraries</li> |
| 24 | + <li>Return either HTML strings or component objects</li> |
| 25 | + </ul> |
| 26 | + </section> |
11 | 27 |
|
12 | | - <p> |
13 | | - All you have to do is export a default function (async or sync) that returns a string, or any |
14 | | - type that your layout can handle. |
15 | | - In this case, we are using <a href="https://ghub.io/uhtml-isomorphic"><pre>uhtml-isomorphic</pre></a>. |
16 | | - </p> |
| 28 | + <section class="implementation"> |
| 29 | + <h2>How to Implement</h2> |
| 30 | + <p> |
| 31 | + Export a default function (async or sync) that returns a string or any |
| 32 | + type that your layout can handle. In this example, we're using |
| 33 | + <a href="https://github.com/developit/htm"><code>htm/preact</code></a> for JSX-like syntax. |
| 34 | + </p> |
| 35 | + <div class="code-example"> |
| 36 | + <pre><code>export default async function MyPage({ vars }) { |
| 37 | + return render(html\`<div>Content here</div>\`) |
| 38 | +}</code></pre> |
| 39 | + </div> |
| 40 | + </section> |
17 | 41 |
|
18 | | - <p>Here we access the <pre>siteName</pre> and <pre>title</pre> variables inside the page</p> |
| 42 | + <section class="variables-demo"> |
| 43 | + <h2>Using Variables</h2> |
| 44 | + <p>Here we access the <code>siteName</code> and <code>title</code> variables inside the page:</p> |
| 45 | + <div class="variable-display"> |
| 46 | + <div><strong>Site Name:</strong> ${siteName}</div> |
| 47 | + <div><strong>Page Title:</strong> ${title}</div> |
| 48 | + </div> |
| 49 | + </section> |
19 | 50 |
|
20 | | - <p>${siteName}</p> |
21 | | - <p>${title}</p> |
| 51 | + <section class="additional-features"> |
| 52 | + <h2>Additional Features</h2> |
| 53 | + <p>JavaScript pages support:</p> |
| 54 | + <ul> |
| 55 | + <li>Page-scoped <code>client.js</code> for browser interactions</li> |
| 56 | + <li>Page-scoped <code>style.css</code> for component styling</li> |
| 57 | + <li>Page-specific variables via <code>export const vars</code></li> |
| 58 | + <li>Async data fetching before rendering</li> |
| 59 | + </ul> |
| 60 | + </section> |
22 | 61 |
|
23 | | - <p>JS pages can also have a page scoped <pre>client.js</pre> and <pre>style.css</pre>. It |
24 | | - is an incredibly flexible page type. |
25 | | - </p> |
26 | | - ` |
| 62 | + <a href="../" class="back-link">← Back to Home</a> |
| 63 | + </div> |
| 64 | + `) |
27 | 65 | } |
28 | 66 |
|
| 67 | +// Define page-specific variables |
29 | 68 | export const vars = { |
30 | | - title: 'JS Page', |
| 69 | + title: 'JavaScript Page Example', |
| 70 | + description: 'Learn how to use JavaScript pages in DOMStack for dynamic content generation' |
31 | 71 | } |
0 commit comments