Class
Item
class Item<M> where M : MetadataA model representing an item.
An item can be any text file (like a Markdown or RestructedText file). Readers will turn the file into an Item, and Writers will turn the Item into a String (for example HTML or RSS) to be written to disk.
Mentioned In
Initializers
init(
absoluteSource: Path,
relativeSource: Path,
relativeDestination: Path,
title: String,
body: String,
date: Date,
created: Date,
lastModified: Date,
metadata: M
)init(from decoder: any Decoder) throwsCreates a new instance by decoding from the given decoder.
This initializer throws an error if reading from the decoder fails, or if the data read is corrupted or otherwise invalid.
- Parameter decoder: The decoder to read data from.
convenience init(
title: String,
body: String = "",
date: Date = Date(),
relativeDestination: Path? = nil,
metadata: M
)Create an Item programmatically (without reading from a file).
Parameters
titleThe title of the item.
bodyThe body content. Defaults to an empty string.
dateThe date of the item. Defaults to the current date.
relativeDestinationThe output path relative to the site's output folder. Defaults to
title-slug/index.html.metadataThe parsed metadata.
Instance Properties
let absoluteSource: PathThe absolute path of the file
var body: StringThe body of the file, without the metadata header, and without the first title.
var children: [any AnyItem]Type-erased children. Populated automatically by nested registrations.
let created: DateThe creation date of the item. Please note that this value can be inconsistent when cloning or pulling from git, see https://github.com/loopwerk/Saga/issues/21.
var date: DateThe date of the item. Will be taken from the metadata if available, defaults to the creation date otherwise. Please note that the creation date value can be inconsistent when cloning or pulling from git, see https://github.com/loopwerk/Saga/issues/21.
var filenameWithoutExtension: String { get }let lastModified: DateThe last modified date of the item. Please note that this value can be inconsistent when cloning or pulling from git, see https://github.com/loopwerk/Saga/issues/21.
var locale: SagaLocale?The locale of this item, or nil when i18n is not configured.
var metadata: MThe parsed metadata. Metadata can be any Codable object.
weak var parent: (any AnyItem)?Type-erased parent. Populated automatically by nested registrations.
var relativeDestination: PathThe destination, where the Writer will write it to disk.
let relativeSource: PathThe path of the file, relative to the site’s input.
var title: StringThe title of the item.
var translations: [SagaLocale : any AnyItem]Other language versions of this item, keyed by locale.
var url: String { get }Instance Methods
func children<C>(as type: C.Type) -> [Item<C>] where C : MetadataTyped accessor for children.
func parent<P>(as type: P.Type) -> Item<P> where P : MetadataTyped accessor for parent.
func translation(for locale: SagaLocale) -> Item<M>?Returns the translation for the given locale, if available.
Relationships
Conforms To
AnyItem , Swift.Decodable , Swift.Encodable , Swift.Sendable