From 0902730137201191f139c48a48abdf0fe9535c38 Mon Sep 17 00:00:00 2001 From: "Collin J. Doering" Date: Thu, 13 Aug 2015 01:09:24 -0400 Subject: [PATCH] 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 --- js/default.js | 12 +++--- src/site.hs | 63 ++++++------------------------ templates/partials/nav.html | 6 +-- templates/partials/pagination.html | 24 ++---------- 4 files changed, 25 insertions(+), 80 deletions(-) diff --git a/js/default.js b/js/default.js index 05aba7b..4f89cd9 100644 --- a/js/default.js +++ b/js/default.js @@ -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'); } } }], diff --git a/src/site.hs b/src/site.hs index 5ffca4e..e240100 100644 --- a/src/site.hs +++ b/src/site.hs @@ -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 --------------------------------------------------------------------------------------------------------- diff --git a/templates/partials/nav.html b/templates/partials/nav.html index 3d5fb71..5140415 100644 --- a/templates/partials/nav.html +++ b/templates/partials/nav.html @@ -2,17 +2,17 @@