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).
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
}Directory's corresponding index pageGet 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.
Used by the generated Pages.elm module. There's no need to use this
outside of the generated code.
Used by the generated Pages.elm module. There's no need to use this
outside of the generated code.
Represents a known Directory within your
contentfolder of yourelm-pagessite.