Skip to content

Latest commit

 

History

24 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

Overview

WebFormats provides type-safe builders for common web data formats, allowing you to construct structured data using Swift's result builder syntax.

Features

  • 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

Installation

Swift Package Manager

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")
    ]
)

Usage

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")

Requirements

  • Swift 6.2+

License

Apache License 2.0 - See LICENSE for details

Contributing

Contributions welcome! Please open an issue or submit a pull request.

Related Packages

About

WebFormats, as used in gnorium.com

Resources

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages