Removed use of virtualpath contexts

Now because all URLs are now valid urls, and no special treatment of
pages is required the following changes were made:

* Removed rel attribute from navigation anchor tags in
  "templates/partials/nav.html"
* Removed use of virtualpath context and associated pagination code
  associated with virtual paths in "src/site.hs"
* Removed unneeded bloat from "templates/paritals/paginate.html" because
  irtualPaginateContext is now no longer needed

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
This commit is contained in:
Collin J. Doering 2015-08-13 01:09:24 -04:00
parent bc1cfaabeb
commit 0902730137
4 changed files with 25 additions and 80 deletions

View File

@ -58,7 +58,7 @@ _paq.push(['enableLinkTracking']);
ajaxCallbacks: {
beforeSend: function () {
$('#nav-menu li.active').removeClass('active');
$('#nav-menu li a[rel="address:/blog.html"]').parent('li').addClass('active');
$('#nav-menu li a[href="./blog.html"]').parent('li').addClass('active');
}
}
},
@ -81,7 +81,7 @@ _paq.push(['enableLinkTracking']);
ajaxCallbacks: {
beforeSend: function () {
$('#nav-menu li.active').removeClass('active');
$('#nav-menu li a[rel="address:/blog.html"]').parent('li').addClass('active');
$('#nav-menu li a[href="./blog.html"]').parent('li').addClass('active');
}
}
},
@ -102,8 +102,8 @@ _paq.push(['enableLinkTracking']);
ajaxCallbacks: {
beforeSend: function () {
// Set the blog menuitem as active
$('a.menuitem[rel="address:/blog.html"]').closest('ul').find('li.active').removeClass('active');
$('a.menuitem[rel="address:/blog.html"]').closest('li').addClass('active');
$('a.menuitem[href="./blog.html"]').closest('ul').find('li.active').removeClass('active');
$('a.menuitem[href="./blog.html"]').closest('li').addClass('active');
}
}
},
@ -128,8 +128,8 @@ _paq.push(['enableLinkTracking']);
}
// Initially set the active menuitem in the nav
$('a.menuitem[rel="address:' + virt_url + '"]').closest('ul').find('li.active').removeClass('active');
$('a.menuitem[rel="address:' + virt_url + '"]').closest('li').addClass('active');
$('a.menuitem[href="' + virt_url + '"]').closest('ul').find('li.active').removeClass('active');
$('a.menuitem[href="' + virt_url + '"]').closest('li').addClass('active');
}
}
}],

View File

@ -212,14 +212,13 @@ main = do
pageMid = [head pagesLast']
pagesLast = if not . null $ pagesLast' then tail pagesLast' else []
indexCtx = listField "pagesFirst" pagesCtx (return pagesFirst) <>
listField "pageMid" pagesCtx (return pageMid) <>
listField "pagesLast" pagesCtx (return pagesLast) <>
indexCtx = listField "pagesFirst" defaultContext (return pagesFirst) <>
listField "pageMid" defaultContext (return pageMid) <>
listField "pagesLast" defaultContext (return pagesLast) <>
defaultContext
ctx = taggedPostCtx tags <>
paginateContext paginatedPosts pageNum <>
virtualPaginateContext paginatedPosts pageNum <>
constField "weight" "0" <>
listField "posts" (taggedPostCtx tags) (return posts)
makeItem ""
@ -256,9 +255,9 @@ main = do
defaultContext
indexCtx =
listField "pagesFirst" pagesCtx (return pagesFirst) <>
listField "pageMid" pagesCtx (return pageMid) <>
listField "pagesLast" pagesCtx (return pagesLast) <>
listField "pagesFirst" defaultContext (return pagesFirst) <>
listField "pageMid" defaultContext (return pageMid) <>
listField "pagesLast" defaultContext (return pagesLast) <>
defaultContext
sectionCtx <- getResourceBody >>= genSectionContext
@ -280,9 +279,9 @@ main = do
pagesLast = if not . null $ pagesLast' then tail pagesLast' else []
indexCtx =
listField "pagesFirst" pagesCtx (return pagesFirst) <>
listField "pageMid" pagesCtx (return pageMid) <>
listField "pagesLast" pagesCtx (return pagesLast) <>
listField "pagesFirst" defaultContext (return pagesFirst) <>
listField "pageMid" defaultContext (return pageMid) <>
listField "pagesLast" defaultContext (return pagesLast) <>
defaultContext
pandocCompilerWith pandocReaderOptions pandocWriterOptions
@ -341,9 +340,9 @@ paginateTagsRules loc tags =
pageMid = [head pagesLast']
pagesLast = if not . null $ pagesLast' then tail pagesLast' else []
indexCtx = listField "pagesFirst" pagesCtx (return pagesFirst) <>
listField "pageMid" pagesCtx (return pageMid) <>
listField "pagesLast" pagesCtx (return pagesLast) <>
indexCtx = listField "pagesFirst" defaultContext (return pagesFirst) <>
listField "pageMid" defaultContext (return pageMid) <>
listField "pagesLast" defaultContext (return pagesLast) <>
defaultContext
ctx = taggedPostCtx tags <>
@ -370,16 +369,11 @@ paginateTagsRules loc tags =
postCtx :: Context String
postCtx = dateField "date" "%B %e, %Y" <>
teaserField "teaser" "content" <>
field "virtualpath" (fmap (drop 6 . maybe "" toUrl) . getRoute . itemIdentifier) <>
defaultContext
taggedPostCtx :: Tags -> Context String
taggedPostCtx tags = tagsField "tags" tags <> postCtx
pagesCtx :: Context String
pagesCtx = field "virtualpath" (fmap (maybe "" toUrl) . getRoute . itemIdentifier) <>
defaultContext
pageWeight :: (Functor f, MonadMetadata f) => Item a -> f Int
pageWeight i = fmap (maybe 0 read) $ getMetadataField (itemIdentifier i) "weight"
@ -387,39 +381,6 @@ sortByM :: (Monad m, Ord k) => (a -> m k) -> [a] -> m [a]
sortByM f xs = liftM (map fst . sortBy (comparing snd)) $
mapM (\x -> liftM (x,) (f x)) xs
-- This is copied verbatim from Web/Paginate.hs as it isn't exported
-- Get the identifier for a certain page by passing in the page number.
paginatePage :: Paginate -> PageNumber -> Maybe Identifier
paginatePage pag pageNumber
| pageNumber < 1 = Nothing
| pageNumber > (paginateNumPages pag) = Nothing
| otherwise = Just $ paginateMakeId pag pageNumber
-- This is copied verbatim from Web/Paginate.hs as it isn't exported
paginateNumPages :: Paginate -> Int
paginateNumPages = size . paginateMap
virtualPaginateContext :: Paginate -> PageNumber -> Context a
virtualPaginateContext pag currentPage = mconcat
[ field "firstPageUrlVirtualPath" $ \_ -> otherPage 1 >>= url
, field "previousPageUrlVirtualPath" $ \_ -> otherPage (currentPage - 1) >>= url
, field "nextPageUrlVirtualPath" $ \_ -> otherPage (currentPage + 1) >>= url
, field "lastPageUrlVirtualPath" $ \_ -> otherPage lastPage >>= url
]
where
lastPage = paginateNumPages pag
otherPage n
| n == currentPage = fail $ "This is the current page: " ++ show n
| otherwise = case paginatePage pag n of
Nothing -> fail $ "No such page: " ++ show n
Just i -> return (n, i)
url :: (Int, Identifier) -> Compiler String
url (n, i) = getRoute i >>= \mbR -> case mbR of
Just r -> return . toUrl $ r
Nothing -> fail $ "No URL for page: " ++ show n
---------------------------------------------------------------------------------------------------------
-- Page section parser
---------------------------------------------------------------------------------------------------------

View File

@ -2,17 +2,17 @@
<ul class="container" id="nav-menu">
$for(pagesFirst)$
<li>
<a class="menuitem" href="$url$" rel="address:$virtualpath$">$title$</a>
<a class="menuitem" href="$url$">$title$</a>
</li>
$endfor$
$for(pageMid)$
<li class="active">
<a class="menuitem" href="$url$" rel="address:$virtualpath$">$title$</a>
<a class="menuitem" href="$url$">$title$</a>
</li>
$endfor$
$for(pagesLast)$
<li>
<a class="menuitem" href="$url$" rel="address:$virtualpath$">$title$</a>
<a class="menuitem" href="$url$">$title$</a>
</li>
$endfor$
<a class="rss-icon" href="atom.xml"></a>

View File

@ -1,38 +1,22 @@
<div class="container" id="pagination">
$if(firstPageUrl)$
$if(firstPageUrlVirtualPath)$
<a class="firstPage" href="$firstPageUrlVirtualPath$">First Page</a>
$else$
<a class="firstPage" href="$firstPageUrl$">First Page</a>
$endif$
<a class="firstPage" href="$firstPageUrl$">First Page</a>
$else$
<span class="on-first-page">First Page</span>
$endif$
$if(previousPageUrl)$
$if(previousPageUrlVirtualPath)$
<a class="previousPage" href="$previousPageUrlVirtualPath$">Previous Page</a>
$else$
<a class="previousPage" href="$previousPageUrl$">Previous Page</a>
$endif$
<a class="previousPage" href="$previousPageUrl$">Previous Page</a>
$else$
<span class="no-previous-page">Previous Page</span>
$endif$
$if(nextPageUrl)$
$if(nextPageUrlVirtualPath)$
<a class="nextPage" href="$nextPageUrlVirtualPath$">Next Page</a>
$else$
<a class="nextPage" href="$nextPageUrl$">Next Page</a>
$endif$
<a class="nextPage" href="$nextPageUrl$">Next Page</a>
$else$
<span class="no-next-page">Next Page</span>
$endif$
$if(lastPageUrl)$
$if(lastPageUrlVirtualPath)$
<a class="lastPage" href="$lastPageUrlVirtualPath$">Last Page</a>
$else$
<a class="lastPage" href="$lastPageUrl$">Last Page</a>
$endif$
<a class="lastPage" href="$lastPageUrl$">Last Page</a>
$else$
<span class="on-last-page">Last Page</span>
$endif$