WebFormats, as used in gnorium.com
Structured data format builders for Swift, enabling declarative construction of JSON, JSON-LD, JSON import maps, and Web Application Manifest formats.
WebFormats provides type-safe builders for common web data formats, allowing you to construct structured data using Swift's result builder syntax.
- JSON Format: Type-safe JSON object and array construction
- JSON-LD Format: Linked Data and schema.org markup
- JSON Import Map Format: ES module import map generation
- WAM Format: Web Application Manifest format
Add WebFormats to your Package.swift:
dependencies: [
.package(url: "https://github.com/gnorium/web-formats", branch: "main")
]Then add it to your target dependencies:
.target(
name: "YourTarget",
dependencies: [
.product(name: "WebFormats", package: "web-formats")
]
)import JSONFormat
import JSONLDFormat
import JSONImportMapFormat
// Build JSON-LD for structured data
let jsonLD = script {
[
.context: "https://schema.org",
.type: "WebSite",
.name: "Gnorium",
.url: "https://gnorium.com"
] as JSONLD
}.type("application/ld+json")
// Build import map for ES modules
let importMap = script {
JSONImportMap(imports: [
"three": "https://cdn.jsdelivr.net/npm/three@0.160.0/build/three.module.js"
]).encodeJSON()
}.type("importmap")- Swift 6.2+
Apache License 2.0 - See LICENSE for details
Contributions welcome! Please open an issue or submit a pull request.
- design-tokens - Universal design tokens based on Apple HIG
- diff-engine - Platform-agnostic character-level diff engine
- embedded-swift-utilities - Utility functions for Embedded Swift environments
- artifact-core - IIIF Presentation API v3 types + deep zoom viewer
- markdown-utilities - Markdown rendering with media attribution support
- admin-core - Core admin functionalities for web applications
- web-apis - Web API implementations for Swift WebAssembly
- web-builders - HTML, CSS, JS, and SVG DSL builders
- web-components - Reusable UI components for web applications
- web-security - Portable security utilities for web applications
- web-types - Shared web types and design tokens