Structure

Writer

struct Writer<M> where M : Metadata

Writers turn an Item into a String using a “renderer”, and write the resulting String to a file on disk.

To turn an Item into a String, a Writer uses a “renderer”; a function that knows how to turn a rendering context such as ItemRenderingContext into a String.

Note Saga does not come bundled with any renderers out of the box, instead you should install one such as SagaSwimRenderer or SagaStencilRenderer.

Mentioned In

Type Methods

@preconcurrency
static func groupedWriter<T>(
  _ renderer: @escaping (PartitionedRenderingContext<T, M>) async throws -> String,
  by keyPath: @escaping (Item<M>) -> T,
  output: Path = "[key]/index.html",
  paginate: Int? = nil,
  paginatedOutput: Path = "[key]/page/[page]/index.html"
) -> Writer<M> where T : Comparable, T : CustomStringConvertible, T : Hashable, T : Sendable

A convenience version of partitionedWriter that groups items by a key path.

@preconcurrency
static func itemWriter(
  _ renderer: @escaping (ItemRenderingContext<M>) async throws -> String
) -> Writer<M>

Writes a single Item to a single output file, using Item.relativeDestination as the destination path.

@preconcurrency
static func listWriter(
  _ renderer: @escaping (ItemsRenderingContext<M>) async throws -> String,
  output: Path = "index.html",
  paginate: Int? = nil,
  paginatedOutput: Path = "page/[page]/index.html"
) -> Writer<M>

Writes an array of items into a single output file.

@preconcurrency
static func partitionedWriter<T>(
  _ renderer: @escaping (PartitionedRenderingContext<T, M>) async throws -> String,
  output: Path = "[key]/index.html",
  paginate: Int? = nil,
  paginatedOutput: Path = "[key]/page/[page]/index.html",
  partitioner: @escaping ([Item<M>]) -> [T : [Item<M>]]
) -> Writer<M> where T : Comparable, T : CustomStringConvertible, T : Hashable, T : Sendable

Writes an array of items into multiple output files.

Use this to partition an array of items into a dictionary of Items, with a custom key.

The output path is a template where [key] will be replaced with the key used for the partition. Example: articles/[key]/index.html

@preconcurrency
static func tagWriter(
  _ renderer: @escaping (PartitionedRenderingContext<String, M>) async throws -> String,
  output: Path = "tag/[key]/index.html",
  paginate: Int? = nil,
  paginatedOutput: Path = "tag/[key]/page/[page]/index.html",
  tags: @escaping (Item<M>) -> [String]
) -> Writer<M>

A convenience version of partitionedWriter that splits items based on tags.

Tags can be any [String] array.

@preconcurrency
static func yearWriter(
  _ renderer: @escaping (PartitionedRenderingContext<Int, M>) async throws -> String,
  output: Path = "[key]/index.html",
  paginate: Int? = nil,
  paginatedOutput: Path = "[key]/page/[page]/index.html"
) -> Writer<M>

A convenience version of groupedWriter that splits items based on year.

Relationships

Conforms To

Swift.Sendable