Skip to content

Commit

Permalink
Add the new configuration option 'absolute-urls'.
Browse files Browse the repository at this point in the history
When turned on, this makes wikilinks absolute w.r.t. the base-url.
By default, they are relative.

So, for example, in a wiki served at the path 'wiki', on a page
Sub/Page, the wikilink

[Cactus]()

will produce a link to '/wiki/Cactus' if absolute-urls is on,
and otherwise the relative link 'Cactus'.

Patch due to lemmih.
  • Loading branch information
David authored and jgm committed Jul 9, 2011
1 parent 72e0c6c commit 0b6ea00
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 4 deletions.
2 changes: 2 additions & 0 deletions Network/Gitit/Config.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ extractConfig cp = do
cfResetPasswordMessage <- get cp "DEFAULT" "reset-password-message" cfResetPasswordMessage <- get cp "DEFAULT" "reset-password-message"
cfUseFeed <- get cp "DEFAULT" "use-feed" cfUseFeed <- get cp "DEFAULT" "use-feed"
cfBaseUrl <- get cp "DEFAULT" "base-url" cfBaseUrl <- get cp "DEFAULT" "base-url"
cfAbsoluteUrls <- get cp "DEFAULT" "absolute-urls"
cfWikiTitle <- get cp "DEFAULT" "wiki-title" cfWikiTitle <- get cp "DEFAULT" "wiki-title"
cfFeedDays <- get cp "DEFAULT" "feed-days" cfFeedDays <- get cp "DEFAULT" "feed-days"
cfFeedRefreshTime <- get cp "DEFAULT" "feed-refresh-time" cfFeedRefreshTime <- get cp "DEFAULT" "feed-refresh-time"
Expand Down Expand Up @@ -186,6 +187,7 @@ extractConfig cp = do
, markupHelp = markupHelpText , markupHelp = markupHelpText
, useFeed = cfUseFeed , useFeed = cfUseFeed
, baseUrl = stripTrailingSlash cfBaseUrl , baseUrl = stripTrailingSlash cfBaseUrl
, useAbsoluteUrls = cfAbsoluteUrls
, wikiTitle = cfWikiTitle , wikiTitle = cfWikiTitle
, feedDays = readNumber "feed-days" cfFeedDays , feedDays = readNumber "feed-days" cfFeedDays
, feedRefreshTime = readNumber "feed-refresh-time" cfFeedRefreshTime , feedRefreshTime = readNumber "feed-refresh-time" cfFeedRefreshTime
Expand Down
13 changes: 9 additions & 4 deletions Network/Gitit/ContentTransformer.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ where


import Control.Exception (throwIO, catch) import Control.Exception (throwIO, catch)
import Control.Monad.State import Control.Monad.State
import Control.Monad.Reader (ask)
import Data.Maybe (isNothing, mapMaybe) import Data.Maybe (isNothing, mapMaybe)
import Network.Gitit.Cache (lookupCache, cacheContents) import Network.Gitit.Cache (lookupCache, cacheContents)
import Network.Gitit.Export (exportFormats) import Network.Gitit.Export (exportFormats)
Expand Down Expand Up @@ -499,13 +500,17 @@ readerFor pt lhs =
Textile -> readTextile defPS Textile -> readTextile defPS


wikiLinksTransform :: Pandoc -> PluginM Pandoc wikiLinksTransform :: Pandoc -> PluginM Pandoc
wikiLinksTransform = return . bottomUp convertWikiLinks wikiLinksTransform pandoc
= do cfg <- liftM pluginConfig ask -- Can't use askConfig from Interface due to circular dependencies.
return (bottomUp (convertWikiLinks cfg) pandoc)


-- | Convert links with no URL to wikilinks. -- | Convert links with no URL to wikilinks.
convertWikiLinks :: Inline -> Inline convertWikiLinks :: Config -> Inline -> Inline
convertWikiLinks (Link ref ("", "")) = convertWikiLinks cfg (Link ref ("", "")) | useAbsoluteUrls cfg =
Link ref (baseUrl cfg </> inlinesToURL ref, "Go to wiki page")
convertWikiLinks _cfg (Link ref ("", "")) =
Link ref (inlinesToURL ref, "Go to wiki page") Link ref (inlinesToURL ref, "Go to wiki page")
convertWikiLinks x = x convertWikiLinks _cfg x = x


-- | Derives a URL from a list of Pandoc Inline elements. -- | Derives a URL from a list of Pandoc Inline elements.
inlinesToURL :: [Inline] -> String inlinesToURL :: [Inline] -> String
Expand Down
2 changes: 2 additions & 0 deletions Network/Gitit/Types.hs
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -132,6 +132,8 @@ data Config = Config {
-- | Base URL of wiki, for use in feed -- | Base URL of wiki, for use in feed
baseUrl :: String, baseUrl :: String,
-- | Title of wiki, used in feed -- | Title of wiki, used in feed
useAbsoluteUrls :: Bool,
-- | Should WikiLinks be absolute w.r.t. the base URL?
wikiTitle :: String, wikiTitle :: String,
-- | Number of days history to be included in feed -- | Number of days history to be included in feed
feedDays :: Integer, feedDays :: Integer,
Expand Down
7 changes: 7 additions & 0 deletions data/default.conf
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -228,6 +228,13 @@ base-url:
# and RPX token_urls. Set this if use-feed is 'yes' or # and RPX token_urls. Set this if use-feed is 'yes' or
# authentication-method is 'rpx'. # authentication-method is 'rpx'.


absolute-urls: no
# make wikilinks absolute with respect to the base-url.
# So, for example, in a wiki served at the base URL '/wiki', on a page
# Sub/Page, the wikilink '[Cactus]()' will produce a link to
# '/wiki/Cactus' if absolute-urls is 'yes', and a relative link to 'Cactus'
# (referring to '/wiki/Sub/Cactus') if absolute-urls is 'no'.

feed-days: 14 feed-days: 14
# number of days to be included in feeds. # number of days to be included in feeds.


Expand Down

0 comments on commit 0b6ea00

Please sign in to comment.