### Staticraft Execution Options Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md Methods for running the Staticraft development server via global installation, npx, or direct source execution. ```bash # 1. Global installation npm install -g staticraft staticraft dev # 2. On-demand execution with npx npx staticraft dev # 3. Direct execution from source repository ./staticraft dev ``` -------------------------------- ### Define root route data Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md Implement data fetching for the root route in src/app/server.js. This example fetches featured content without requiring path generation. ```js // src/app/server.js - colocated with src/app/page.html, the root route "/" export default { revalidate: 600, data: async () => { const res = await fetch('https://api.example.com/featured') return await res.json() } } ``` -------------------------------- ### Staticraft Command Reference Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md Common CLI commands for development, production builds, and server configuration. ```bash staticraft dev # Start dev server on http://localhost:4455 (live rebuild) staticraft dev --port 5000 # Custom port override staticraft dev --host # Bind dev server to 0.0.0.0 for local network access staticraft start # Run production background worker (NO HTTP server) staticraft build # One-shot build: compile all pages to .raft/ and exit ``` -------------------------------- ### Running the Test Suite Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md Executes the built-in test runner without external dependencies. ```bash npm test # node's built-in test runner - no test framework dependency ``` -------------------------------- ### Iterate Product Collection Source: https://github.com/abhay-vachhani/staticraft/blob/master/src/app/page.html Loops through the products array to render individual product cards with category, image, title, description, and price. ```handlebars {{#each products}}[ {{ category }} ![{{ title }}]({{ thumbnail }}) ### {{ title }} {{ description }} ${{ price }} Details ](/products/{{ id }}){{/each}} ``` -------------------------------- ### Configure Staticraft build settings Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md Define global build settings in staticraft.config.js. The siteUrl field is optional and required only if sitemap.xml generation is needed. ```js export default { outputDir: '.raft', defaultExpiry: '1y', siteUrl: 'https://example.com', // Optional - enables sitemap.xml generation } ``` -------------------------------- ### View Staticraft Build Summary Output Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md The build summary table displays route types, revalidation intervals, cache settings, and total page counts generated during the build process. ```text ┌──────────────────────────┬──────────────┬──────────────┬──────────┐ │ Route (Staticraft) │ Revalidate │ Cache Expiry │ Count │ ├──────────────────────────┼──────────────┼──────────────┼──────────┤ │ ○ / │ 600s │ 1 Year │ 1 │ │ ○ /products │ 300s │ 1 Year │ 1 │ │ ● /products/:id │ 3600s │ 1 Year │ 194 │ │ ○ /about │ - │ - │ 1 │ │ ○ 404 │ - │ - │ 1 │ └──────────────────────────┴──────────────┴──────────────┴──────────┘ ○ (Static) 4 pages ● (SSG Dynamic) 194 pages ✦ Total Pages: 198 static pages compiled into .raft/ (2604ms) ✦ Default Cache: max-age=31536000, immutable (1 Year CDN/Browser Expiry) ``` -------------------------------- ### Define Project Structure Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md The directory layout for a Staticraft project, highlighting the src/app directory for routes and the .raft directory for compiled output. ```text my-site/ ├── src/ │ └── app/ # All site content lives here │ ├── page.html # Home page template ("/") │ ├── server.js # Optional data/revalidate for "/" │ ├── products/ │ │ ├── page.html # Products listing template ("/products") │ │ ├── server.js # Optional data/revalidate for "/products" │ │ └── [id]/ │ │ ├── page.html # Dynamic product detail template ("/products/:id") │ │ └── server.js # generatePaths (or data) + revalidate │ ├── about.html # Flat = purely static page, no server.js needed │ ├── 404.html # Custom error page (system template, not a routable URL) │ ├── layouts/ │ │ └── base.html # Shared base layout │ └── components/ # Reusable partials │ └── navbar.html ├── staticraft.config.js # Global settings only (outputDir, defaultExpiry) └── .raft/ # Compiled static output (served by Nginx/Caddy) ├── index.html ├── products/ │ ├── index.html │ └── 42/ │ └── index.html └── 404.html # Compiled from src/app/404.html ``` -------------------------------- ### Configure Nginx for 404 Errors Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md Nginx configuration directive to serve the compiled 404 page. ```nginx error_page 404 /404.html; ``` -------------------------------- ### Apply Base Layout Source: https://github.com/abhay-vachhani/staticraft/blob/master/src/app/page.html Sets the base HTML layout for the page using the layout helper. ```handlebars {{ layout "layouts/base.html" }} ``` -------------------------------- ### Define dynamic route data and paths Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md Use server.js to handle dynamic route data fetching and path generation. The data function is preferred for on-demand rendering, while generatePaths is used for full pre-builds. ```js // src/app/products/[id]/server.js export default { revalidate: 3600, // Re-render every 3600 seconds (omit = permanent, never auto-invalidated) // On-demand rendering (dev lazy-compile, production on-demand): fetches // just the one requested item. Preferred over generatePaths() whenever // both are defined - return null/undefined to signal "not a real page" // (renders a 404 instead). data: async ({ params }) => { const res = await fetch(`https://api.example.com/products/${params.id}`) if (!res.ok) return null return { product: await res.json() } }, // Full/scheduled builds: enumerates every valid id so all pages can be // prebuilt ahead of time. Not used for on-demand requests when data() exists. generatePaths: async () => { const res = await fetch('https://api.example.com/products?limit=0') const { products } = await res.json() return products.map(p => ({ params: { id: String(p.id) }, data: { product: p } })) } } ``` -------------------------------- ### Create Custom 404 Page Source: https://github.com/abhay-vachhani/staticraft/blob/master/README.md Template for a custom 404 error page using the Staticraft layout engine. ```html {{ layout "layouts/base.html" }}

Page Not Found

The page you requested does not exist.

Return Home
``` -------------------------------- ### Base Layout Structure Source: https://github.com/abhay-vachhani/staticraft/blob/master/src/app/layouts/base.html The base template uses Handlebars syntax to inject page titles and include global components. ```html {{#if title}}{{ title }} | {{/if}}KRAFT Studio Objects {{ component "components/nav.html" }} {{ slot }} {{ component "components/footer.html" }} ``` -------------------------------- ### Highlight Active Navigation Link Source: https://github.com/abhay-vachhani/staticraft/blob/master/src/app/components/nav.html This script compares the current window path against navigation link href attributes to toggle an 'active' class. It handles trailing slashes and sub-path matching. ```javascript (function () { const path = window.location.pathname.replace(/\/$/, '') || '/' const links = document.querySelectorAll('.nav-links a') links.forEach((link) => { const href = link.getAttribute('href').replace(/\/$/, '') || '/' if (href === path || (href !== '/' && path.startsWith(href))) { link.classList.add('active') } }) })() ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.