Copyright | (c) 2021-2022 Mirko Westermeier |
---|---|
License | MIT |
Stability | experimental |
Safe Haskell | None |
Language | Haskell2010 |
Minimal filesystem powered markdown content management system
Synopsis
- loadHTMell :: FilePath -> IO (Maybe (HTree MarkdownContent))
- loadHTMellContent :: HTMellContent c => FilePath -> IO (Maybe (HTree c))
- get :: HTMellContent c => HTree c -> String -> Maybe (HTree c)
- getHTML :: HTMellContent c => HTree c -> String -> Maybe Text
Loading a content tree from filesystem
A content tree can be built from any directory, given by a FilePath
. Each
file or subdirectory in that content directory can become a content node in
the resulting tree. Subdirectories can become inner nodes with children, but
they can also have content, that is loaded from their "index"
child, if it
exists. Directory or file names become the node's addresses in the content
tree. Leading numbers, followed by "_"
are used for sorting in listings,
and are stripped from the names, as well as extensions.
Example:
Filesystem: Content tree: content Content root node |--- 1_foo.md Content node "/foo" |--- index.md Content of the root node "/" '--- 2_bar Inner node "/bar", no content |--- 17_baz.md Content node "/bar/baz" |--- 42_quux.md Content node "/bar/quux" '--- xnorfzt.md Content node "/bar/xnorfzt"
Caveat: Don't use directories named "index"
!
In listings, the nodes below "/bar"
will appear in this order, defined by
their (optional) ordering numbers:
/bar/xnorfzt
- because it's loaded from
xnorfzt.md
and no number implies 0 /bar/baz
- because it's loaded from
17_baz.md
and 17 < 42 /bar/quux
- because it's loaded from
42_quux.md
and 42 > 17
The accepted file extensions are the responsibility of the HTMellContent
instance used. The default instance, MarkdownContent
, accepts .md
,
RawHTMLContent
reads .html
files only.
:: FilePath | The directory to read the content tree from. |
-> IO (Maybe (HTree MarkdownContent)) | The loaded content tree, if possible. |
Creates a markdown content tree
loadHTMellContent :: HTMellContent c => FilePath -> IO (Maybe (HTree c)) #
Creates a content tree just like loadHTMell
, but it works for any
HTMellContent
instance, for example RawHTMLContent
.
The type needs to be declared:
maybeTree <- loadHTMell "content" :: IO (Maybe (HTree RawHTMLContent)) let tree = fromJust maybeTree
Accessing single content nodes
:: HTMellContent c | |
=> HTree c | The content tree to search in |
-> String | A query string of the desired subtree or content node |
-> Maybe (HTree c) | The desired content node, if it exists |
Finds a subtree or leaf (content node) in a given content tree. The
query String
consists of child node names, separated with "/"
.
See loadHTMell
for details of node names.