mirror of
https://github.com/samsonjs/samhuri.net.git
synced 2026-04-27 14:57:40 +00:00
Factor out a method
This commit is contained in:
parent
0091566f00
commit
cc1c97b4a1
1 changed files with 18 additions and 16 deletions
|
|
@ -53,25 +53,27 @@ public final class Generator {
|
||||||
// Make sure this path exists so we can write to it.
|
// Make sure this path exists so we can write to it.
|
||||||
try fileManager.createDirectory(at: targetURL, withIntermediateDirectories: true, attributes: nil)
|
try fileManager.createDirectory(at: targetURL, withIntermediateDirectories: true, attributes: nil)
|
||||||
|
|
||||||
// Handle the file, transforming it if necessary.
|
// Processes the file, transforming it if necessary.
|
||||||
let ext = filename.split(separator: ".").last!
|
try renderOrCopyFile(url: fileURL, targetDir: targetURL)
|
||||||
switch ext {
|
}
|
||||||
|
}
|
||||||
|
|
||||||
case "less":
|
func renderOrCopyFile(url fileURL: URL, targetDir: URL) throws {
|
||||||
let cssURL = targetURL.appendingPathComponent(filename.replacingOccurrences(of: ".less", with: ".css"))
|
let filename = fileURL.lastPathComponent
|
||||||
try renderLess(from: fileURL, to: cssURL)
|
let ext = filename.split(separator: ".").last!
|
||||||
|
switch ext {
|
||||||
|
case "less":
|
||||||
|
let cssURL = targetDir.appendingPathComponent(filename.replacingOccurrences(of: ".less", with: ".css"))
|
||||||
|
try renderLess(from: fileURL, to: cssURL)
|
||||||
|
|
||||||
case "md":
|
case "md":
|
||||||
let htmlURL = targetURL.appendingPathComponent(filename.replacingOccurrences(of: ".md", with: ".html"))
|
let htmlURL = targetDir.appendingPathComponent(filename.replacingOccurrences(of: ".md", with: ".html"))
|
||||||
try renderMarkdown(from: fileURL, to: htmlURL)
|
try renderMarkdown(from: fileURL, to: htmlURL)
|
||||||
|
|
||||||
default:
|
|
||||||
// Who knows. Copy the file unchanged.
|
|
||||||
let src = URL(fileURLWithPath: path).appendingPathComponent(filename)
|
|
||||||
let dest = targetURL.appendingPathComponent(filename)
|
|
||||||
try fileManager.copyItem(at: src, to: dest)
|
|
||||||
}
|
|
||||||
|
|
||||||
|
default:
|
||||||
|
// Who knows. Copy the file unchanged.
|
||||||
|
let dest = targetDir.appendingPathComponent(filename)
|
||||||
|
try fileManager.copyItem(at: fileURL, to: dest)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue