From b28b52d75d0d3f6014fcfbadc0c3d4867106c69a Mon Sep 17 00:00:00 2001 From: Sami Samhuri Date: Sun, 22 Dec 2019 13:46:29 -0800 Subject: [PATCH] Make everything else work on Linux --- .../Sources/SiteGenerator/Posts/Feeds/JSONFeedWriter.swift | 4 ++++ SiteGenerator/Sources/SiteGenerator/Posts/PostRepo.swift | 2 +- SiteGenerator/Sources/SiteGenerator/SiteGenerator.swift | 2 +- bin/build-gensite | 2 ++ gensite/Sources/gensite/main.swift | 1 - 5 files changed, 8 insertions(+), 3 deletions(-) diff --git a/SiteGenerator/Sources/SiteGenerator/Posts/Feeds/JSONFeedWriter.swift b/SiteGenerator/Sources/SiteGenerator/Posts/Feeds/JSONFeedWriter.swift index 943dc2c..f6268b8 100644 --- a/SiteGenerator/Sources/SiteGenerator/Posts/Feeds/JSONFeedWriter.swift +++ b/SiteGenerator/Sources/SiteGenerator/Posts/Feeds/JSONFeedWriter.swift @@ -72,7 +72,11 @@ final class JSONFeedWriter { ) let encoder = JSONEncoder() encoder.dateEncodingStrategy = .iso8601 +#if os(Linux) + encoder.outputFormatting = [.prettyPrinted] +#else encoder.outputFormatting = [.prettyPrinted, .withoutEscapingSlashes] +#endif let feedJSON = try encoder.encode(feed) let feedURL = targetURL.appendingPathComponent(jsonFeed.path) try feedJSON.write(to: feedURL, options: [.atomic]) diff --git a/SiteGenerator/Sources/SiteGenerator/Posts/PostRepo.swift b/SiteGenerator/Sources/SiteGenerator/Posts/PostRepo.swift index 1a21ad2..2e7b292 100644 --- a/SiteGenerator/Sources/SiteGenerator/Posts/PostRepo.swift +++ b/SiteGenerator/Sources/SiteGenerator/Posts/PostRepo.swift @@ -79,7 +79,7 @@ final class PostRepo { return try fileManager.contentsOfDirectory(atPath: directory.path).flatMap { (filename: String) -> [URL] in let fileURL = directory.appendingPathComponent(filename) var isDir: ObjCBool = false - fileManager.fileExists(atPath: fileURL.path, isDirectory: &isDir) + _ = fileManager.fileExists(atPath: fileURL.path, isDirectory: &isDir) if isDir.boolValue { return try enumerateMarkdownFiles(directory: fileURL) } diff --git a/SiteGenerator/Sources/SiteGenerator/SiteGenerator.swift b/SiteGenerator/Sources/SiteGenerator/SiteGenerator.swift index b94ab56..6ef37a7 100644 --- a/SiteGenerator/Sources/SiteGenerator/SiteGenerator.swift +++ b/SiteGenerator/Sources/SiteGenerator/SiteGenerator.swift @@ -49,7 +49,7 @@ public final class SiteGenerator { // Recurse into subdirectories, updating the target directory as well. let fileURL = URL(fileURLWithPath: path).appendingPathComponent(filename) var isDir: ObjCBool = false - fileManager.fileExists(atPath: fileURL.path, isDirectory: &isDir) + _ = fileManager.fileExists(atPath: fileURL.path, isDirectory: &isDir) guard !isDir.boolValue else { try renderPath(fileURL.path, to: targetURL.appendingPathComponent(filename)) continue diff --git a/bin/build-gensite b/bin/build-gensite index e321f33..9ed0da6 100755 --- a/bin/build-gensite +++ b/bin/build-gensite @@ -1,5 +1,7 @@ #!/bin/bash +set -euo pipefail + if [[ $(uname) = "Linux" ]]; then build_platform_dir="x86_64-unknown-linux" else diff --git a/gensite/Sources/gensite/main.swift b/gensite/Sources/gensite/main.swift index a07dfae..8b8e6b5 100644 --- a/gensite/Sources/gensite/main.swift +++ b/gensite/Sources/gensite/main.swift @@ -5,7 +5,6 @@ // Created by Sami Samhuri on 2019-12-01. // -import Darwin import Foundation import samhuri_net