• Townie
    AI
  • Blog
  • Docs
  • Pricing
  • We’re hiring!
Log inSign up
dhvanil

dhvanil

untitled-421

Public
Like
untitled-421
Home
Code
5
components
1
templates
1
utils
1
README.md
H
main.tsx
Branches
1
Pull requests
Remixes
History
Environment variables
Val Town is a collaborative website to build and scale JavaScript apps.
Deploy APIs, crons, & store data – all from the browser, and deployed in milliseconds.
Sign up now
Code
/
Code
/
Search
main.tsx
https://dhvanil--d70a565e3bb911f090db9e149126039e.web.val.run
README.md

HTML Export System

A comprehensive HTML generation and export system for Val Town with multiple approaches for different use cases.

Features

  • 🎨 Template-based HTML generation with variable substitution
  • 🧩 Component-based HTML building for programmatic generation
  • πŸ“± Responsive design with TailwindCSS integration
  • βš›οΈ React app export support
  • πŸ“¦ Minification for optimized output
  • πŸ’Ύ Direct download functionality
  • 🎯 Custom styling and scripting options

Quick Start

Visit the main endpoint to see available export options:

  • / - Main dashboard with export options
  • /export/simple - Download a simple HTML page
  • /export/react - Download a React application
  • /export/custom - Form to create custom HTML exports

Usage Examples

Template-Based Generation

import { renderTemplate, generatePage } from "./utils/html.ts"; // Using templates const html = await renderTemplate("/templates/base.html", { title: "My Page", content: "<h1>Hello World</h1>", scripts: "<script>console.log('loaded');</script>" }); // Using the page generator const page = await generatePage({ title: "My App", content: "<div>Content here</div>", includeReact: true, customCSS: "body { background: #f0f0f0; }" });

Component-Based Generation

import { HTML, renderComponent, createDocument } from "./components/html.ts"; // Build components const header = HTML.h1("Welcome", { class: "text-3xl font-bold" }); const paragraph = HTML.p("This is a paragraph", { class: "text-gray-600" }); const button = HTML.button("Click me", { class: "bg-blue-500 text-white px-4 py-2 rounded", onclick: "alert('Hello!')" }); // Create complete document const html = createDocument({ title: "Component Example", body: [ HTML.div({ class: "container mx-auto p-8" }, [ header, paragraph, button ]) ] });

Export with Download

import { createHTMLDownload, minifyHTML } from "./utils/html.ts"; // Create downloadable response const html = await generatePage({ title: "Export Example", content: "<h1>Downloaded Content</h1>" }); return createHTMLDownload(minifyHTML(html), "my-export.html");

File Structure

β”œβ”€β”€ main.tsx              # HTTP val with export endpoints
β”œβ”€β”€ templates/
β”‚   └── base.html         # Base HTML template
β”œβ”€β”€ utils/
β”‚   └── html.ts          # Template utilities
β”œβ”€β”€ components/
β”‚   └── html.ts          # Component-based HTML generation
└── README.md            # This file

API Endpoints

GET /

Main dashboard showing available export options.

GET /export/simple

Downloads a simple HTML page with current timestamp.

GET /export/react

Downloads a React counter application as a standalone HTML file.

GET /export/custom

Shows a form for creating custom HTML exports.

POST /export/custom

Processes form data and generates custom HTML download.

Form Parameters:

  • title - Page title
  • content - HTML content
  • includeStyles - Whether to include custom CSS

Template Variables

The base template supports these variables:

  • {{title}} - Page title
  • {{head}} - Additional head content
  • {{content}} - Main page content
  • {{scripts}} - JavaScript content

Customization

Adding New Templates

  1. Create a new HTML file in /templates/
  2. Use {{variable}} syntax for dynamic content
  3. Load with renderTemplate()

Custom Components

Extend the HTML object in /components/html.ts:

export const HTML = { // ... existing components customCard: (title: string, content: string): HTMLComponent => ({ tag: "div", attributes: { class: "bg-white p-6 rounded-lg shadow" }, children: [ HTML.h3(title, { class: "text-lg font-semibold mb-2" }), HTML.p(content, { class: "text-gray-600" }) ] }) };

Best Practices

  1. Use templates for consistent layouts
  2. Minify HTML for production exports
  3. Pin React versions when including React
  4. Validate user input in custom exports
  5. Use semantic HTML for accessibility
  6. Include meta tags for proper rendering

Troubleshooting

  • Template not found: Ensure template files exist in /templates/
  • React not loading: Check that versions are pinned to 18.2.0
  • Styles not applying: Verify TailwindCSS script is included
  • Download not working: Check Content-Disposition headers
HTTP
  • main.tsx
    dhvanil--d7…9e.web.val.run
Code
componentstemplatesutilsREADME.md
H
main.tsx
FeaturesVersion controlCode intelligenceCLI
Use cases
TeamsAI agentsSlackGTM
DocsShowcaseTemplatesNewestTrendingAPI examplesNPM packages
PricingNewsletterBlogAboutCareers
We’re hiring!
Brandhi@val.townStatus
X (Twitter)
Discord community
GitHub discussions
YouTube channel
Bluesky
Terms of usePrivacy policyAbuse contact
Β© 2025 Val Town, Inc.