### Clone and Run Transclude Examples
Source: https://transclude.dev/docs/examples
Commands to clone the repository and start specific example projects on their respective ports.
```bash
git clone https://github.com/transclude-dev/transclude.git
cd transclude && npm install
npm run showcase # http://localhost:1961
npm run todomvc # http://localhost:1962
npm run blog # http://localhost:1963
npm run search # http://localhost:1964
npm run htmx # http://localhost:1965
npm run includes # http://localhost:1966
npm run auth # http://localhost:1967
npm run live # http://localhost:1968
npm run elements # http://localhost:1969
npm run markdown # http://localhost:1970
```
--------------------------------
### Install Transclude core
Source: https://transclude.dev/docs/getting-started
Manual installation command for adding Transclude to an existing project.
```bash
npm install @transclude/core
```
--------------------------------
### Clone and run the project
Source: https://transclude.dev/docs/contributing
Commands to clone the repository, install dependencies, and execute the test suite.
```bash
git clone https://github.com/transclude-dev/transclude.git
cd transclude
npm install
npm test
```
--------------------------------
### Start Transclude Application Across Runtimes
Source: https://transclude.dev/docs/runtimes
Commands to initiate the application server in various runtime environments.
```bash
npm start # Node
bun node_modules/@transclude/core/bin/serve.bun.js # Bun
deno run -A node_modules/@transclude/core/bin/serve.deno.js # Deno
wrangler dev # Cloudflare
```
--------------------------------
### Usage examples for svg-icon
Source: https://transclude.dev/docs/icons
Demonstrates various ways to use the svg-icon element in markup.
```html
Saved
```
--------------------------------
### Define a full transclude configuration
Source: https://transclude.dev/docs/config
Example of a complete configuration object defining directory paths, server settings, and build options.
```javascript
export default {
appDir: 'app',
routesDir: 'routes',
elementsDir: 'elements',
iconsDir: 'icons',
publicDir: 'public',
stylesheet: 'app/styles/global.css',
strict: false,
fragmentParam: 'fragment',
lang: 'en',
watchElements: false,
fragmentHeader: null,
csrf: true,
trailingSlash: 'never',
cookieSecret: globalThis.process?.env?.COOKIE_SECRET ?? null,
port: 1960,
proxy: false,
outDir: 'dist',
typesFile: 'app/transclude-env.d.ts',
};
```
--------------------------------
### Route path mapping
Source: https://transclude.dev/docs/endpoints
Examples of how file paths in the routes directory map to URL patterns.
```text
routes/api/people.js /api/people
routes/api/people/[id].js /api/people/:id
routes/api/[...rest].js /api/*
routes/api/_shared.js not a route
```
--------------------------------
### Create POST Response with Cookies
Source: https://transclude.dev/docs/endpoints
Example of handling form data, setting a cookie, and returning a custom response with status and headers.
```javascript
export const POST = async ({ cookies, request }) => {
const form = await request.formData();
cookies.set('seen', '1', { maxAge: 604800 });
return new Response('made', {
status: 201,
headers: { location: '/api/people/' + form.get('id') },
});
};
```
--------------------------------
### Define a route page
Source: https://transclude.dev/docs/getting-started
Example of a route file using a server-side script block to provide data to the template.
```html
${title}
${title}
${item}
```
--------------------------------
### Fragment response example
Source: https://transclude.dev/docs/fragments
The server returns only the requested fragment element when the fragment query parameter matches the element's id.
```html
Ada Lovelace
```
--------------------------------
### Anchor and Heading Structure
Source: https://transclude.dev/docs/includes
Uses an empty anchor tag as a bookmark to define the start of a section.
```html
Installing
Run the thing.
```
--------------------------------
### HTTP request and response mapping
Source: https://transclude.dev/docs/endpoints
Example of how HTTP methods map to status codes and responses for the people API.
```text
GET /api/people -> 200 [{ "name": "Ada" }]
POST /api/people -> 201 { "name": "Grace" }
PUT /api/people -> 405 Allow: GET, POST
```
--------------------------------
### Create a JSON API endpoint
Source: https://transclude.dev/docs/recipes
Defines GET and POST handlers for a JSON API route using standard Response objects.
```javascript
// app/routes/api/people.js -> /api/people
import { people } from '../../data/people.js';
export const GET = () => Response.json(people);
export const POST = async ({ request }) => {
const body = await request.json();
people.push(body);
return Response.json(body, { status: 201 });
};
```
--------------------------------
### Unsafe Script and Style Injection
Source: https://transclude.dev/docs/security
Examples of insecure template expressions within script and style tags that can lead to syntax errors or injection vulnerabilities.
```html
```
--------------------------------
### GET /api/people
Source: https://transclude.dev/docs/endpoints
Retrieves the list of all people.
```APIDOC
## GET /api/people
### Description
Retrieves a list of all people from the data source.
### Method
GET
### Endpoint
/api/people
### Response
#### Success Response (200)
- **people** (array) - A list of person objects.
```
--------------------------------
### GET /api/people/:id
Source: https://transclude.dev/docs/endpoints
Retrieves a specific person by their ID.
```APIDOC
## GET /api/people/:id
### Description
Retrieves details for a specific person identified by the provided ID.
### Method
GET
### Endpoint
/api/people/:id
### Parameters
#### Path Parameters
- **id** (string) - Required - The unique identifier of the person.
### Response
#### Success Response (200)
- **person** (object) - The requested person object.
#### Error Response (404)
- **error** (string) - Returned when the person is not found.
```
--------------------------------
### Build the project
Source: https://transclude.dev/docs/colophon
Execute the build process to generate static files for the site.
```bash
npm run build
```
--------------------------------
### GET /_transclude/proxy
Source: https://transclude.dev/docs/includes
Fetches a document fragment or an outline from a specified URL.
```APIDOC
## GET /_transclude/proxy
### Description
Retrieves a fragment of an allowed document or the document's outline if no ID is provided. The response is sanitized and links are rewritten.
### Method
GET
### Endpoint
/_transclude/proxy
### Parameters
#### Query Parameters
- **url** (string) - Required - The URL of the document to fetch.
- **id** (string) - Optional - The ID of the specific fragment to retrieve. If omitted, returns the document outline.
### Response
#### Success Response (200)
- **fragments** (array) - List of fragments (if no ID provided)
- **url** (string) - The source URL
- **HTML content** (string) - The requested fragment (if ID provided)
```
--------------------------------
### Build and Serve Production Site
Source: https://transclude.dev/docs/production
Commands to generate the production build and serve the resulting files.
```bash
npm run build
npm start # serves dist/ on 1960
```
--------------------------------
### Common Compilation Errors
Source: https://transclude.dev/docs/routing
Examples of invalid directive usage that result in compile-time errors.
```html
…
A
B
…
Nobody here.
${person.name}
```
--------------------------------
### Initialize a new Transclude project
Source: https://transclude.dev/docs/getting-started
Commands to scaffold a new project with default or blank templates.
```bash
npm create @transclude my-app
cd my-app
npm install
npm run dev
```
```bash
npm create @transclude my-app -- --template blank
```
--------------------------------
### Transclusion Compile Errors
Source: https://transclude.dev/docs/includes
Examples of invalid transclusion patterns that result in compile-time errors.
```html
```
--------------------------------
### Define a basic layout
Source: https://transclude.dev/docs/layouts
A _layout.html file wraps routes in its directory and below, using a to render nested content.
```html
```
--------------------------------
### Create a dynamic route
Source: https://transclude.dev/docs/recipes
Use bracketed file names to define URL parameters, which are accessible via the context params object.
```html
${person.name}
```
--------------------------------
### Mutation Redirect Pattern
Source: https://transclude.dev/docs/forms
Redirecting after a successful mutation to ensure the browser lands on a GET request.
```javascript
export const POST = async ({ request, url, fragment }) => {
const result = await save(request);
if (result.error) return result;
if (fragment !== null) return result;
return Response.redirect(new URL(url), 303);
};
```
--------------------------------
### Enable Content-Security-Policy
Source: https://transclude.dev/docs/security
Enable the Content-Security-Policy by setting the csp key to true in the configuration file.
```javascript
// transclude.config.js
export default {
csp: true,
};
```
--------------------------------
### Diagnostic Error Reporting
Source: https://transclude.dev/docs/markdown
Example of a diagnostic message pointing to a line number in the converted HTML output.
```text
app/routes/notes.md (converted HTML, line 21) error TS2551
Property 'cuont' does not exist on type '__Shape<{ title: string; count: number; }>'.
```
--------------------------------
### Configure basic sitemap
Source: https://transclude.dev/docs/feeds
Define the hostname for sitemap generation in the default export.
```javascript
export default {
sitemap: { hostname: 'https://acme.com' },
};
```
--------------------------------
### Configure icon directory
Source: https://transclude.dev/docs/icons
Set the icons directory path in the project configuration.
```javascript
export default {
iconsDir: 'icons',
};
```
--------------------------------
### Configure vite.config.js
Source: https://transclude.dev/docs/getting-started
Optional configuration file for adding custom Vite plugins.
```javascript
// vite.config.js, only if you want one
import { defineConfig } from 'vite';
import tailwind from '@tailwindcss/vite';
export default defineConfig({
plugins: [tailwind()],
});
```
--------------------------------
### Configure worker.js for Transclude
Source: https://transclude.dev/docs/runtimes
Standard worker entry point configuration using workerFrom to integrate application assets, manifest, and configuration.
```javascript
// worker.js
import { workerFrom } from '@transclude/core/worker';
import * as bundle from './dist/server/assets.js';
import * as entry from './dist/server/entry.js';
import manifest from './dist/routes.json';
import config from './transclude.config.js';
export default workerFrom({ config, manifest, entry, bundle });
```
--------------------------------
### Inline SVG Definition
Source: https://transclude.dev/blog/svg-already-does-transclusion
An example of inlining an SVG shape directly, which leads to duplication and maintenance issues compared to using