﻿namespace Markify.Document

open System
open System.IO

open Markify.Models.Documents
open Markify.Models.Definitions

module DocumentHelper =
    let convertNameToPath (fullname : string) =
        let parts = fullname.Split ('.')
        match parts.Length with
        | 1 -> String.Empty
        | _ -> sprintf @"%s\" <| String.Join (@"\", parts, 0, parts.Length - 1)

    let cleanExtension (ext : string) = 
        match ext with
        | ext when ext.StartsWith(".") -> ext.Substring(1)
        | _ -> ext

    let createPage project ext definition =
        let path = Path.Combine (project, convertNameToPath definition.Identity.Name)
        let cleanExt = cleanExtension ext
        let page = {
            Name = sprintf "%s.%s" definition.Identity.Name cleanExt
            Folder = Uri (path, UriKind.Relative)
            Content = definition }
        page
﻿namespace Markify.Document

open System
open System.IO

open Markify.Models.Documents
open Markify.Models.Definitions

module DocumentHelper =
    let convertIdentityToPath identity =
        let mergedName =
            match (identity.Namespace, identity.Parents) with
            | Some x, Some w -> sprintf "%s.%s" x w
            | Some x, None -> x
            | None, Some x -> x
            | _ -> ""
        match mergedName with
        | "" -> ""
        | _ -> sprintf @"%s\" <| mergedName.Replace ('.', '\\')

    let cleanExtension (ext : string) = 
        match ext with
        | ext when ext.StartsWith(".") -> ext.Substring(1)
        | _ -> ext

    let createPage project ext definition =
        let path = Path.Combine (project, convertIdentityToPath definition.Identity)
        let cleanedExt = cleanExtension ext
        {   Name = sprintf "%s.%s" definition.Identity.Name cleanedExt
            Folder = Uri (path, UriKind.Relative)
            Content = definition }
Update document helper to use identity to create page path
Update document helper to use identity to create page path
