From 1537aaab018001082331c01e62fa47dbdc70c227 Mon Sep 17 00:00:00 2001 From: Christoph Hagen Date: Wed, 31 Aug 2022 08:46:23 +0200 Subject: [PATCH] Hide language buttons again if page is empty --- WebsiteGenerator/Content/Element.swift | 2 +- WebsiteGenerator/Extensions/URL+Extensions.swift | 5 +++++ 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/WebsiteGenerator/Content/Element.swift b/WebsiteGenerator/Content/Element.swift index e7b93e8..d91ceac 100644 --- a/WebsiteGenerator/Content/Element.swift +++ b/WebsiteGenerator/Content/Element.swift @@ -473,7 +473,7 @@ extension Element { */ private func existingContentUrl(for language: String) -> URL? { let url = contentUrl(for: language) - guard url.exists else { + guard url.exists, let size = url.size, size > 0 else { return nil } return url diff --git a/WebsiteGenerator/Extensions/URL+Extensions.swift b/WebsiteGenerator/Extensions/URL+Extensions.swift index 9422312..f88a55f 100644 --- a/WebsiteGenerator/Extensions/URL+Extensions.swift +++ b/WebsiteGenerator/Extensions/URL+Extensions.swift @@ -35,4 +35,9 @@ extension URL { try url.ensureParentFolderExistence() try FileManager.default.copyItem(at: self, to: url) } + + var size: Int? { + let attributes = try? FileManager.default.attributesOfItem(atPath: path) + return (attributes?[.size] as? NSNumber)?.intValue + } }