Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add the new configuration option 'absolute-urls'.

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...
commit 0b6ea00d9edfbca534806624a2b01756076f361d 1 parent 72e0c6c
David authored committed
View
2  Network/Gitit/Config.hs
@@ -99,6 +99,7 @@ extractConfig cp = do
cfResetPasswordMessage <- get cp "DEFAULT" "reset-password-message"
cfUseFeed <- get cp "DEFAULT" "use-feed"
cfBaseUrl <- get cp "DEFAULT" "base-url"
+ cfAbsoluteUrls <- get cp "DEFAULT" "absolute-urls"
cfWikiTitle <- get cp "DEFAULT" "wiki-title"
cfFeedDays <- get cp "DEFAULT" "feed-days"
cfFeedRefreshTime <- get cp "DEFAULT" "feed-refresh-time"
@@ -186,6 +187,7 @@ extractConfig cp = do
, markupHelp = markupHelpText
, useFeed = cfUseFeed
, baseUrl = stripTrailingSlash cfBaseUrl
+ , useAbsoluteUrls = cfAbsoluteUrls
, wikiTitle = cfWikiTitle
, feedDays = readNumber "feed-days" cfFeedDays
, feedRefreshTime = readNumber "feed-refresh-time" cfFeedRefreshTime
View
13 Network/Gitit/ContentTransformer.hs
@@ -70,6 +70,7 @@ where
import Control.Exception (throwIO, catch)
import Control.Monad.State
+import Control.Monad.Reader (ask)
import Data.Maybe (isNothing, mapMaybe)
import Network.Gitit.Cache (lookupCache, cacheContents)
import Network.Gitit.Export (exportFormats)
@@ -499,13 +500,17 @@ readerFor pt lhs =
Textile -> readTextile defPS
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.
-convertWikiLinks :: Inline -> Inline
-convertWikiLinks (Link ref ("", "")) =
+convertWikiLinks :: Config -> Inline -> Inline
+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")
-convertWikiLinks x = x
+convertWikiLinks _cfg x = x
-- | Derives a URL from a list of Pandoc Inline elements.
inlinesToURL :: [Inline] -> String
View
2  Network/Gitit/Types.hs
@@ -132,6 +132,8 @@ data Config = Config {
-- | Base URL of wiki, for use in feed
baseUrl :: String,
-- | Title of wiki, used in feed
+ useAbsoluteUrls :: Bool,
+ -- | Should WikiLinks be absolute w.r.t. the base URL?
wikiTitle :: String,
-- | Number of days history to be included in feed
feedDays :: Integer,
View
7 data/default.conf
@@ -228,6 +228,13 @@ base-url:
# and RPX token_urls. Set this if use-feed is 'yes' or
# 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
# number of days to be included in feeds.
Please sign in to comment.
Something went wrong with that request. Please try again.