dillonkearns/elm-pages/4.0.0

NOTE: the latest version is 12.3.0

Pages.Directory

The Directory type can be used to get the children of a given directory, check if a PagePath is within a Directory, or get the index page corresponding to the directory (if it is a Directory pathKey WithIndex).

type Directory key hasIndex

Represents a known Directory within your content folder of your elm-pages site.

includes : Directory key hasIndex -> PagePath key -> Bool

Check if the Directory contains the PagePath. This can be useful for styling a link in the navbar if you are in that folder. Note that the view function gets passed the currentPage (Pages.application from your generated Pages.elm module).

import Element exposing (Element)
import Element.Font as Font
import Pages.Directory as Directory exposing (Directory)


navbar : PagePath Pages.PathKey -> Element msg
navbar currentPage =
    Element.row [ Element.spacing 15 ]
        [ navbarLink currentPath pages.docs.directory "Docs"
        , navbarLink currentPath pages.blog.directory "Blog"
        ]


navbarLink :
    PagePath Pages.PathKey
    -> Directory Pages.PathKey Directory.WithIndex
    -> String
    -> Element msg
navbarLink currentPath linkDirectory displayName =
    let
        isHighlighted =
            currentPath |> Directory.includes linkDirectory
    in
    Element.link
        (if isHighlighted then
            [ Font.underline
            , Font.color Palette.color.primary
            ]


         else
            []
        )
        { url = linkDirectory |> Directory.indexPath |> PagePath.toString
        , label = Element.text displayName
        }

Getting a Directory's corresponding index page

Get the PagePath for the given Directory.

import Pages
import Pages.Directory as Directory exposing (Directory)


blogDirectory : Directory Pages.PathKey Directory.WithIndex
blogDirectory =
    Pages.pages.blog.directory


-- blogDirectory |> Directory.indexPath |> PagePath.toString
-- => "/blog"

See Directory.includes for an example of this in action.

Used for a Directory that has an index path directly at that path. See Directory.indexPath.

Used for a Directory that does not have an index path directly at that path. See WithIndex and Directory.indexPath.

Functions for use by generated code

withIndex : key -> List (PagePath key) -> List String -> Directory key WithIndex

Used by the generated Pages.elm module. There's no need to use this outside of the generated code.

key
-> List (PagePath key)
-> List String

Used by the generated Pages.elm module. There's no need to use this outside of the generated code.