Structure

Reader

struct Reader

Readers are responsible for turning text files into Item instances.

Every Reader can declare what kind of text files it supports, for example Markdown or RestructuredText. Readers are expected to support the parsing of Metadata contained within a document, such as this example article written in Markdown:

---
tags: article, news
summary: This is the summary
---
# Hello world
Hello there.
public extension Reader {
  static func myMarkdownReader() -> Self {
    Reader(supportedExtensions: ["md", "markdown"], convert: { absoluteSource in
      let content: String = try absoluteSource.read()

      // Parse `content` markdown
      // ...

      // and return the parts:
      return (title: "...", body: "...", frontmatter: [:])
    })
  }
}

Note Instead of constructing your own Reader from scratch for your website, you should probably install one such as SagaParsleyMarkdownReader, SagaPythonMarkdownReader, or SagaInkMarkdownReader.

Mentioned In

Initializers

init(
  supportedExtensions: [String],
  copySourceFiles: Bool = false,
  convert: @escaping Reader.Converter
)

Initialize a new Reader

Instance Properties

var convert: Reader.Converter

The function that will do the actual work of reading and converting a file path into an Item.

Relationships

Conforms To

Swift.Sendable