Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Network/Gitit2/Foundation.hs
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ data GititConfig = GititConfig{
, front_page :: Text -- ^ Front page of wiki
, help_page :: Text -- ^ Help page
, latex_engine :: Maybe FilePath -- ^ LaTeX engine to use for PDF export
, simple_title :: Bool -- ^ Hide directory structure for wikilinks? If True `[dir/subdir/mySubpage]()` rendered as mySubpage.
}

-- | A user.
Expand Down
6 changes: 4 additions & 2 deletions Network/Gitit2/Handler/View.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,10 +144,12 @@ contentsToWikiPage page contents = do
conf <- getConfig
plugins' <- getPlugins
converter <- wikiLinksConverter (pageToPrefix page)
let title = pageToText page
let title = lastTextFromPage page
let defaultFormat = default_format conf
foldM applyPlugin (contentToWikiPage' title contents converter defaultFormat) plugins'
simpleTitle = simple_title conf
foldM applyPlugin (contentToWikiPage' title contents converter defaultFormat simpleTitle) plugins'
where
lastTextFromPage (Page ps) = last ps
-- | Convert links with no URL to wikilinks.
wikiLinksConverter :: Text -> GH master ([Inline] -> String)
wikiLinksConverter prefix = do
Expand Down
2 changes: 1 addition & 1 deletion Network/Gitit2/Page.hs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ textToPage :: Text -> Page
textToPage x = Page $ T.splitOn "/" x

instance ToMarkup Page where
toMarkup = toMarkup . pageToText
toMarkup (Page ps) = (toMarkup . last) ps

instance ToMessage Page where
toMessage = pageToText
Expand Down
10 changes: 6 additions & 4 deletions Network/Gitit2/WikiPage.hs
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ readPageFormat s =
where (s',rest) = T.break (=='+') s
lhs = rest == "+lhs"

contentToWikiPage' :: Text -> ByteString -> ([Inline] -> String) -> PageFormat -> WikiPage
contentToWikiPage' title contents converter defaultFormat =
contentToWikiPage' :: Text -> ByteString -> ([Inline] -> String) -> PageFormat -> Bool -> WikiPage
contentToWikiPage' title contents converter defaultFormat simpleTitle =
WikiPage {
wpName = title
, wpFormat = format
Expand Down Expand Up @@ -104,10 +104,13 @@ contentToWikiPage' title contents converter defaultFormat =
doc = reader $ toString b
Pandoc _ blocks = sanitizePandoc $ addWikiLinks doc
convertWikiLinks :: Inline -> Inline
convertWikiLinks (Link ref ("", "")) = Link ref (converter ref, "")
convertWikiLinks (Link ref ("", "")) = Link (linkTitle ref) (converter ref, "")
convertWikiLinks (Image ref ("", "")) = Image ref (converter ref, "")
convertWikiLinks x = x

linkTitle [Str refStr] | simpleTitle = [Str $ T.unpack $ last . T.splitOn "/" $ T.pack refStr]
linkTitle x = x

addWikiLinks :: Pandoc -> Pandoc
addWikiLinks = bottomUp (convertWikiLinks)

Expand Down Expand Up @@ -142,4 +145,3 @@ contentToWikiPage' title contents converter defaultFormat =
sanitizeAttr (x,y) = case sanitizeAttribute (T.pack x, T.pack y) of
Just (w,z) -> Just (T.unpack w, T.unpack z)
Nothing -> Nothing

3 changes: 3 additions & 0 deletions settings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,6 @@ front_page: Front Page
help_page: Help
max_upload_size: 1M
latex_engine: xelatex
# when simple_title is true it displays `myPage` for wikilinks like `[directory/bla/blo/mypage]()`
# defaults to True
# simple_title: False
4 changes: 3 additions & 1 deletion src/Config.hs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ data Conf = Conf { cfg_port :: Int
, cfg_help_page :: Text
, cfg_max_upload_size :: String
, cfg_latex_engine :: Maybe FilePath
, cfg_simple_title :: Bool
}

data FoundationSettings = FoundationSettings {
Expand Down Expand Up @@ -88,6 +89,7 @@ parseConfig os = Conf
<*> os `parseElem` "help_page" .!= "Help"
<*> os `parseElem` "max_upload_size" .!= "1M"
<*> os `parseElem` "latex_engine"
<*> os `parseElem` "simple_title" .!= True

-- | Ready collection of common mime types. (Copied from
-- Happstack.Server.HTTP.FileServe.)
Expand Down Expand Up @@ -128,7 +130,6 @@ readMimeTypesFile f = catch
warn $ "Could not parse mime types file.\n" ++ show e
return mimeTypes


gititConfigFromConf :: Conf -> IO GititConfig
gititConfigFromConf conf = do
mimes <- case cfg_mime_types_file conf of
Expand All @@ -154,5 +155,6 @@ gititConfigFromConf conf = do
, front_page = cfg_front_page conf
, help_page = cfg_help_page conf
, latex_engine = cfg_latex_engine conf
, simple_title = cfg_simple_title conf
}
return gconfig
6 changes: 3 additions & 3 deletions src/gitit2.hs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ instance Yesod Master where
});
|]
contents
giveUrlRenderer [hamlet|
withUrlRenderer [hamlet|
$doctype 5
<html>
<head>
Expand Down Expand Up @@ -113,7 +113,7 @@ instance HasGitit Master where
getUserR :: Handler Html
getUserR = do
maid <- maybeAuthId
giveUrlRenderer [hamlet|
withUrlRenderer [hamlet|
$maybe aid <- maid
<p><a href=@{AuthR LogoutR}>Logout #{aid}
$nothing
Expand All @@ -123,7 +123,7 @@ getUserR = do
getMessagesR :: Handler Html
getMessagesR = do
mmsg <- getMessage
giveUrlRenderer [hamlet|
withUrlRenderer [hamlet|
$maybe msg <- mmsg
<p.message>#{msg}
|]
Expand Down