generated from MaxGripe/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 38
/
Copy pathSkunkUtils.fs
64 lines (48 loc) · 2.2 KB
/
SkunkUtils.fs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
module SkunkUtils
module Config =
open System.IO
let sourceDir = __SOURCE_DIRECTORY__
let markdownDir = Path.Combine(sourceDir, "markdown-blog")
let htmlDir = Path.Combine(sourceDir, "html")
let outputDir = Path.Combine(sourceDir, "skunk-html-output")
let cssDir = Path.Combine(sourceDir, "css")
let outputCssDir = Path.Combine(outputDir, "css")
let fontsDir = Path.Combine(sourceDir, "fonts")
let outputFontsDir = Path.Combine(outputDir, "fonts")
let imagesDir = Path.Combine(markdownDir, "images")
let outputImagesDir = Path.Combine(outputDir, "images")
let assetsDir = Path.Combine(sourceDir, "assets")
let outputAssetsDir = Path.Combine(outputDir, "assets")
let scriptsDir = Path.Combine(sourceDir, "scripts")
let outputScriptsDir = Path.Combine(outputDir, "scripts")
let frontPageMarkdownFileName = "index.md"
module Disk =
open System.IO
let readFile (path: string) =
path
|> File.Exists
|> function
| true -> File.ReadAllText(path)
| false -> ""
let writeFile (path: string) (content: string) =
File.WriteAllText(path, content)
printfn $"Generated: {Path.GetFileName path} -> {path}\n"
let copyFolderToOutput (sourceFolder: string) (destinationFolder: string) =
if not (Directory.Exists(sourceFolder)) then
printfn $"Source folder does not exist: {sourceFolder}"
else
if not (Directory.Exists(destinationFolder)) then
Directory.CreateDirectory(destinationFolder)
|> ignore
Directory.GetFiles(sourceFolder)
|> Array.iter (fun file ->
let fileName = Path.GetFileName(file)
let destFile = Path.Combine(destinationFolder, fileName)
printfn $"Copying: {fileName} -> {destFile}"
File.Copy(file, destFile, true))
module Url =
open System.Text.RegularExpressions
let toUrlFriendly (input: string) =
input.ToLowerInvariant()
|> fun text -> Regex.Replace(text, @"[^\w\s]", "") // Remove all non-alphanumeric characters
|> fun text -> Regex.Replace(text, @"\s+", "-") // Replace spaces with hyphens