Paginate tag pages
Paginate tag pages, allowing maximum 2 pages per tag to be app cached. Setup virtual paths for tag pages such that /tags/tagname.html loads /tags/tagname1.html similar to how pages are handed. This is similar to how pages are handled in that /pagename.html loads /pages/pagename.html. Dry up blog page's pagination and create a dry template for pagination because it is also used on the tag pages. Signed-off-by: Collin J. Doering <rekahsoft@gmail.com>
This commit is contained in:
parent
5a23b9c90a
commit
891fadf3a2
@ -77,7 +77,7 @@
|
||||
|
||||
function loadPageContent(page_href) {
|
||||
var post_regexp = /posts\/.*/;
|
||||
var tag_regexp = /tags\/.*/;
|
||||
var tag_regexp = /tags\/.*(\d*).html/;
|
||||
var blog_page_regexp = /blog\d*.html/;
|
||||
|
||||
// Check whether the requested url is a post
|
||||
@ -89,6 +89,10 @@
|
||||
// Handle tag pages
|
||||
$('#nav-menu li.active').removeClass('active');
|
||||
$('#nav-menu li a[href="./pages/blog.html"]').parent('li').addClass('active');
|
||||
|
||||
var tag_not_regexp = /(tags\/.*[^\d]+)(.html)/;
|
||||
if (tag_not_regexp.test(page_href))
|
||||
page_href = page_href.replace(tag_not_regexp, "$11$2" );
|
||||
} else { // otherwise assume its a page
|
||||
// Check if the page_href is empty or / and if so goto home
|
||||
if (page_href === '/') {
|
||||
|
39
src/site.hs
39
src/site.hs
@ -110,7 +110,7 @@ main = do
|
||||
tags <- buildTags ("posts/**" .&&. hasNoVersion) (fromCapture "tags/*.html")
|
||||
|
||||
paginatedPosts <- buildPaginateWith
|
||||
(fmap (paginateEvery 6) . sortRecentFirst)
|
||||
(fmap (paginateEvery numPaginatePages) . sortRecentFirst)
|
||||
("posts/**" .&&. hasNoVersion)
|
||||
(\n -> fromCapture "pages/blog*.html" (show n))
|
||||
|
||||
@ -147,7 +147,7 @@ main = do
|
||||
manifestCacheSingles = [ "/index.html"
|
||||
, "/default.css" ]
|
||||
paginatedPostsCache = take 2 $ map (\(n,_) -> "/pages/blog" ++ (show n) ++ ".html") $ toList $ paginateMap paginatedPosts
|
||||
tagsCache = map (\(t,_) -> "/tags/" ++ t ++ ".html") $ tagsMap tags
|
||||
tagsCache = concatMap (\(t,ids) -> take 2 $ ["/tags/" ++ t ++ show n ++ ".html" | n <- [1..length $ paginateEvery numPaginatePages ids]]) $ tagsMap tags
|
||||
manifestCacheFromIds = filter (not . null) $ fmap (maybe "" ("/"++)) manifestCacheRoutesMaybe
|
||||
manifestCache = manifestCacheFromIds ++ tagsCache ++ paginatedPostsCache
|
||||
manifestFallback = [""
|
||||
@ -185,7 +185,7 @@ main = do
|
||||
---------------------------------------------------------------------------------------------------------
|
||||
-- Default Version --------------------------------------------------------------------------------------
|
||||
-- Generate tag pages
|
||||
tagsRules tags $ genTagRules tags
|
||||
paginateTagsRules tags
|
||||
|
||||
paginateRules paginatedPosts $ \pageNum pattern -> do
|
||||
route idRoute
|
||||
@ -377,6 +377,39 @@ feedConfiguration title = FeedConfiguration
|
||||
} where title' = maybe defaultTitle ((defaultTitle ++ "; Specifically on the topic of ") ++) title
|
||||
defaultTitle = "Technical Musings of a Minimalist"
|
||||
|
||||
numPaginatePages :: Int
|
||||
numPaginatePages = 6
|
||||
|
||||
--paginateTagsRules :: Tags -> (String -> Pattern -> Rules ()) -> Rules ()
|
||||
paginateTagsRules tags =
|
||||
forM_ (tagsMap tags) $ \(tag, identifiers) -> do
|
||||
paginatedTaggedPosts <- buildPaginateWith
|
||||
(fmap (paginateEvery numPaginatePages) . sortRecentFirst)
|
||||
(fromList identifiers)
|
||||
(\n -> fromCapture (fromGlob $ "tags/" ++ tag ++ "*.html") (show n))
|
||||
|
||||
paginateRules paginatedTaggedPosts $ \pageNum pattern -> do
|
||||
route idRoute
|
||||
compile $ do
|
||||
posts <- recentFirst =<< loadAllSnapshots pattern "content"
|
||||
let ctx = taggedPostCtx tags <>
|
||||
paginateContext paginatedTaggedPosts pageNum <>
|
||||
constField "tag" tag <>
|
||||
listField "posts" (taggedPostCtx tags) (return posts)
|
||||
makeItem ""
|
||||
>>= loadAndApplyTemplate "templates/tag-page.haml" ctx
|
||||
|
||||
rulesExtraDependencies [tagsDependency tags] $ do
|
||||
create [tagsMakeId tags tag] $ do
|
||||
route $ gsubRoute " " (const "-")
|
||||
compile $ makeItem ("" :: String)
|
||||
|
||||
version "rss" $ do
|
||||
route $ gsubRoute " " (const "-") `composeRoutes` setExtension "xml"
|
||||
compile $ loadAllSnapshots (fromList identifiers) "content"
|
||||
>>= fmap (take 10) . recentFirst
|
||||
>>= renderAtom (feedConfiguration $ Just tag) (bodyField "description" <> defaultContext)
|
||||
|
||||
genTagRules :: Tags -> String -> Pattern -> Rules ()
|
||||
genTagRules tags tag pattern = do
|
||||
route $ gsubRoute " " (const "-")
|
||||
|
@ -1,19 +1,3 @@
|
||||
#blog-page
|
||||
$partial("templates/partials/post-teaser-list.haml")$
|
||||
#pagination.container
|
||||
.four.columns.alpha
|
||||
$if(firstPageUrl)$
|
||||
%a.firstPage(rel="address:$firstPageUrlVirtualPath$" href="$firstPageUrl$") First Page
|
||||
$endif$
|
||||
.four.columns
|
||||
$if(previousPageUrl)$
|
||||
%a.previousPage(rel="address:$previousPageUrlVirtualPath$" href="$previousPageUrl$") Previous Page
|
||||
$endif$
|
||||
.four.columns
|
||||
$if(nextPageUrl)$
|
||||
%a.nextPage(rel="address:$nextPageUrlVirtualPath$" href="$nextPageUrl$") Next Page
|
||||
$endif$
|
||||
.four.colums.omega
|
||||
$if(lastPageUrl)$
|
||||
%a.lastPage(rel="address:$lastPageUrlVirtualPath$" href="$lastPageUrl$") Last Page
|
||||
$endif$
|
||||
$partial("templates/partials/pagination.haml")$
|
||||
|
33
templates/partials/pagination.haml
Normal file
33
templates/partials/pagination.haml
Normal file
@ -0,0 +1,33 @@
|
||||
#pagination.container
|
||||
.four.columns.alpha
|
||||
$if(firstPageUrl)$
|
||||
$if(firstPageUrlVirtualPath)$
|
||||
%a.firstPage(rel="address:$firstPageUrlVirtualPath$" href="$firstPageUrl$") First Page
|
||||
$else$
|
||||
%a.firstPage(href="$firstPageUrl$") First Page
|
||||
$endif$
|
||||
$endif$
|
||||
.four.columns
|
||||
$if(previousPageUrl)$
|
||||
$if(previousPageUrlVirtualPath)$
|
||||
%a.previousPage(rel="address:$previousPageUrlVirtualPath$" href="$previousPageUrl$") Previous Page
|
||||
$else$
|
||||
%a.previousPage(href="$previousPageUrl$") Previous Page
|
||||
$endif$
|
||||
$endif$
|
||||
.four.columns
|
||||
$if(nextPageUrl)$
|
||||
$if(nextPageUrlVirtualPath)$
|
||||
%a.nextPage(rel="address:$nextPageUrlVirtualPath$" href="$nextPageUrl$") Next Page
|
||||
$else$
|
||||
%a.nextPage(href="$nextPageUrl$") Next Page
|
||||
$endif$
|
||||
$endif$
|
||||
.four.colums.omega
|
||||
$if(lastPageUrl)$
|
||||
$if(lastPageUrlVirtualPath)$
|
||||
%a.lastPage(rel="address:$lastPageUrlVirtualPath$" href="$lastPageUrl$") Last Page
|
||||
$else$
|
||||
%a.lastPage(href="$lastPageUrl$") Last Page
|
||||
$endif$
|
||||
$endif$
|
@ -1,3 +1,4 @@
|
||||
#tag-page
|
||||
%h1#tag.container $tag$
|
||||
$partial("templates/partials/post-teaser-list.haml")$
|
||||
$partial("templates/partials/pagination.haml")$
|
||||
|
Loading…
Reference in New Issue
Block a user