diff --git a/README.md b/README.md index ad1e10b..221c18a 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,16 @@ You can view the sample pages on this site. - [x] Dev server - [x] Color scheme +## Constraints + +The filename for pages should follow the pattern below. + +`^[a-zA-Z0-9-.\s]+\.md$` + +The filename for posts should follow the pattern below. + +`^\d{4}-\d{2}-\d{2}-[a-zA-Z0-9-.\s]+\.md$` + ## Building and running the app - Install dependencies: `npm install` diff --git a/src/Common.fs b/src/Common.fs index 79e08f4..62966fa 100644 --- a/src/Common.fs +++ b/src/Common.fs @@ -233,6 +233,12 @@ module Misc = | _ -> Page | _ -> Page + let isInvalidMarkdownFilenamePattern (s: string) = + Regex.IsMatch (s, @"^[a-zA-Z0-9-.\s]+\.md$") |> not + + let isInvalidPostsFilenamePattern (s: string) = + Regex.IsMatch (s, @"^\d{4}-\d{2}-\d{2}-[a-zA-Z0-9-.\s]+\.md$") |> not + type Meta = { frontMatter: Parser.FrontMatter option content: ReactElement diff --git a/src/Generator.fs b/src/Generator.fs index 903e055..c6807e5 100644 --- a/src/Generator.fs +++ b/src/Generator.fs @@ -312,9 +312,38 @@ module Rendering = do! IO.writeFile dest page } + let private checkFilenamePattern (files: string list) = + files + |> List.map IO.leaf + |> List.filter isInvalidMarkdownFilenamePattern + |> function + | [] -> () + | x -> + x + |> String.concat " " + |> failwithf "Invalid filename patterns: %s" + + let private checkPostsFilenamePattern (postRoot: string) (files: string list) = + // TODO: dirty path manipulation. + let postRoot = postRoot.Replace("\\", "/") + files + |> List.filter (fun s -> s.Replace("\\", "/").Contains(postRoot)) + |> List.map IO.leaf + |> List.filter isInvalidPostsFilenamePattern + |> function + | [] -> () + | x -> + x + |> String.concat " " + |> failwithf "Invalid posts filename patterns: %s" + let renderMarkdowns (conf: FrameConfiguration) (site: PathConfiguration) sourceDir destDir = promise { let! files = getMarkdownFiles sourceDir + + files |> checkFilenamePattern + files |> checkPostsFilenamePattern site.postRoot + let! metas = files |> List.map readSource |> Promise.all let metas = metas |> Array.filter _.publish