diff --git a/Network/Gitit2/Foundation.hs b/Network/Gitit2/Foundation.hs index 5871df0..64c20ee 100644 --- a/Network/Gitit2/Foundation.hs +++ b/Network/Gitit2/Foundation.hs @@ -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. diff --git a/Network/Gitit2/Handler/View.hs b/Network/Gitit2/Handler/View.hs index 33982d1..42f93c2 100644 --- a/Network/Gitit2/Handler/View.hs +++ b/Network/Gitit2/Handler/View.hs @@ -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 diff --git a/Network/Gitit2/Page.hs b/Network/Gitit2/Page.hs index 5aa9fa4..9a18260 100644 --- a/Network/Gitit2/Page.hs +++ b/Network/Gitit2/Page.hs @@ -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 diff --git a/Network/Gitit2/WikiPage.hs b/Network/Gitit2/WikiPage.hs index 6cad8f4..609e81b 100644 --- a/Network/Gitit2/WikiPage.hs +++ b/Network/Gitit2/WikiPage.hs @@ -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 @@ -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) @@ -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 - diff --git a/settings.yaml b/settings.yaml index c7b8df1..53e04d3 100644 --- a/settings.yaml +++ b/settings.yaml @@ -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 diff --git a/src/Config.hs b/src/Config.hs index ee88ca6..246e779 100644 --- a/src/Config.hs +++ b/src/Config.hs @@ -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 { @@ -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.) @@ -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 @@ -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 diff --git a/src/gitit2.hs b/src/gitit2.hs index a86e02d..101820f 100644 --- a/src/gitit2.hs +++ b/src/gitit2.hs @@ -58,7 +58,7 @@ instance Yesod Master where }); |] contents - giveUrlRenderer [hamlet| + withUrlRenderer [hamlet| $doctype 5
@@ -113,7 +113,7 @@ instance HasGitit Master where getUserR :: Handler Html getUserR = do maid <- maybeAuthId - giveUrlRenderer [hamlet| + withUrlRenderer [hamlet| $maybe aid <- maid