~askonomm/farm

c51c9c3583e08b12a83fe723536abcbaaaa6553e — Asko Nõmm a month ago f698fff
Add license, readme and remove broken tests
3 files changed, 102 insertions(+), 13 deletions(-)

A LICENSE.txt
M README.md
M Tests/FarmTests/StaticContentTests.swift
A LICENSE.txt => LICENSE.txt +21 -0
@@ 0,0 1,21 @@
MIT License

Copyright (c) 2020 Asko Nõmm

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

M README.md => README.md +79 -1
@@ 1,3 1,81 @@
# Farm

tl;dr
**Farm** is a static content engine written in Swift, for Swift projects. It powers my [personal site](https://askonomm.com) and is meant to be used for sites with static content, such as blogs or websites, either as a complimentary addition or the sole thing driving it - that's for you to decide.

### Example content file

All of the content files in **Farm** are Markdown files. That means they have a file name of `example.md`. They can be in any directory you want (you can specify it) and they contain YAML metadata. An example of a Farm file is the following (probably a familiar format if you've used Jekyll before):

```
---
date: 2019-02-18
status: public
slug: example-url-slug
title: Example page
---

Example content in **Markdown** goes here.
```

This would create the following `FarmItem` struct: 

```Swift
public struct FarmItem: Codable {
  public var meta: [String: String]
  public var entry: String
}
```

### Installation

To install Farm, simply require it in your Package.swift file like this:

```Swift
dependencies: [
    .package(name: "Farm", url: "https://git.sr.ht/~askonomm/farm", from: "1.0.1"),
]
```

### Changelog

To be written.

### Usage

#### Retrieving all content in a directory

To retrieve all of the content in a directory, simply initialize Farm with your provided directory and call `getAll()` on it, like this:

```Swift
import Farm

let content = Farm(directory: "./Blog/")
let items = content.getAll()
```

This will return you an array of `FarmItem` objects.

#### Retreving a specific item in a directory

To retrieve a specific content item in a directory, initialize Farm and call `get(key: "yamlKey", value: "yamlValue")` on it (where key and value is corresponding with the YAML key and value in the file), like this:

```Swift
import Farm

let content = Farm(directory: "./Blog/")
let item = content.get(key: "slug", value: "hello-world")
```

This will return you a `FarmItem` object.

#### Ordering content

You can order content by any meta key in descending or ascending order. For example; if we want to order content by the meta key `date` in a descending order, we would do the following

```Swift
import Farm

let content = Farm(directory: "./Blog/", orderBy: "date", order: "desc")
```

Likewise if you want it to be in ascending order, simply change `order` to `asc`. 

M Tests/FarmTests/StaticContentTests.swift => Tests/FarmTests/StaticContentTests.swift +2 -12
@@ 1,15 1,5 @@
import XCTest
@testable import StaticContent
@testable import Farm

final class StaticContentTests: XCTestCase {
    func testExample() {
        // This is an example of a functional test case.
        // Use XCTAssert and related functions to verify your tests produce the correct
        // results.
        XCTAssertEqual(StaticContent().text, "Hello, World!")
    }

    static var allTests = [
        ("testExample", testExample),
    ]
final class FarmTests: XCTestCase {
}