Ignite Static Site Builder
repository·main·Indexed 25 days ago
https://github.com/twostraws/igniteA static site builder for Swift developers that uses a SwiftUI-like declarative syntax to create responsive websites. It includes a CLI for scaffolding, building, and previewing sites, and supports Markdown content rendering via the ArticlePage protocol and environment queries for adapting UI to device settings.
What's inside Ignite
- Ignite is a static site generator designed specifically for Swift developers. It provides an expressive, SwiftUI-like syntax for building websites, allowing developers to create high-quality, responsive sites without requiring deep knowledge of HTML or CSS. Instead of a direct mapping of HTML to Swift, Ignite uses a declarative approach to help you build beautiful websites that work across all devices.
Understand the Ignite folder structure
mainIgnite sites are Swift packages that follow a specific directory structure:
- Assets: Custom site assets (images, etc.). You can use any subfolder structure.
- Build: Automatically generated folder containing the final HTML files. Do not place important data here, as it is deleted on every build.
- Content (Optional): Markdown files for posts. Files here are rendered to HTML and placed in the
Buildfolder. - Includes (Optional): Custom HTML files you wish to include.
- Sources: All Swift source code for your site.
Use environment queries to adapt your UI
mainIgnite provides a set of specialized queries that allow you to detect and respond to the user's environment and device settings. These queries can be used to adjust layouts, colors, motion, and other UI properties based on real-time system state.
Available queries include:
BreakpointQuery: Detects screen size breakpoints.ColorSchemeQuery: Detects light or dark color schemes.ContrastQuery: Detects high contrast settings.DisplayModeQuery: Detects display modes.MotionQuery: Detects user motion preferences (e.g., reduced motion).OrientationQuery: Detects device orientation.ThemeQuery: Detects active themes.TransparencyQuery: Detects transparency/reduce transparency settings.
Create a new Ignite site
mainOnce the Ignite CLI is installed, you can scaffold a new website project using the
newcommand.ignite new ExampleSiteAfter creation, navigate to the project directory and open the
Package.swiftfile in Xcode to begin development:cd ExampleSite open Package.swiftCreate custom layouts for Markdown content
mainTo render Markdown files located in the Content folder, you must implement a layout that conforms to the
ArticlePageprotocol. This protocol provides anarticleproperty containing the content of the Markdown file.1. Define the Layout
Create a type conforming to
ArticlePageand use thearticleproperty to build your HTML structure:import Foundation import Ignite struct CustomArticleLayout: ArticlePage { var body: some HTML { Text(article.title) .font(.title1) if let image = article.image { Image(image, description: article.imageDescription) .resizable() .cornerRadius(20) .frame(maxHeight: 300) } Text(article.text) } }2. Register the Layout in your Site
Add the custom layout to the
articlePagesproperty of yourSiteimplementation:struct ExampleSite: Site { var name = "Hello World" var url = URL(static: "https://www.example.com") var homePage = Home() var layout = MyLayout() var articlePages: [any ArticlePage] { CustomArticleLayout() } }Build and preview your Ignite site
mainIgnite provides CLI commands to manage the build process and local development server.
Build the site
To convert your Swift code into HTML files, run the
buildcommand. This generates aBuildfolder containing the static site files.ignite buildPreview the site
To view your site locally, use the
run --previewcommand. This starts a local web server and opens your default web browser. This is the recommended way to preview your site to ensure stylesheets and JavaScript load correctly.ignite run --previewTip: If you are using Xcode, you can perform builds via the Xcode UI (Destination > My Mac) and then simply refresh your browser after running
ignite run --previewto see changes.ignite build ignite run --previewInstall the Ignite CLI
mainTo use the Ignite command-line tool for creating, building, and previewing sites, follow these steps to build and install it from the source repository:
- Clone the repository:
git clone https://github.com/twostraws/Ignite. - Enter the directory:
cd Ignite. - Build the tool:
make. - Install the tool to
/usr/local/bin:make install(usesudo make installif you encounter permission issues).
To install to a custom directory, use the
PREFIX_DIRvariable:make install PREFIX_DIR=/my/install/dirgit clone https://github.com/twostraws/Ignite cd Ignite make make install- Clone the repository:
Reference: Ignite CLI commands
mainThe Ignite command-line tool provides several subcommands for site management. Use
ignite helpfor general help orignite help <subcommand>for specific details.new <Name>: Creates a new Ignite site project.build: Converts Swift code into HTML files in theBuilddirectory.run --preview: Launches a local web server and opens the site in your browser.
Reference the Ignite server CLI arguments
mainThe following arguments are available when runningserver.pyvia the command line:Run the Ignite development server
mainTheserver.pyscript provides a built-in HTTP server for previewing your Ignite site. It supports serving a specific directory and can be configured to serve a subsite (a specific subdirectory) with automatic redirection from the root path. If a404.htmlfile exists in the base directory, the server will serve it instead of the default error page.