diff --git a/js/default.js b/js/default.js index 6cfb8ea..e334f5e 100644 --- a/js/default.js +++ b/js/default.js @@ -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 === '/') { diff --git a/src/site.hs b/src/site.hs index cc095dc..6cdcb73 100644 --- a/src/site.hs +++ b/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 "-") diff --git a/templates/pages/blog.haml b/templates/pages/blog.haml index 516d1a9..e419513 100644 --- a/templates/pages/blog.haml +++ b/templates/pages/blog.haml @@ -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")$ diff --git a/templates/partials/pagination.haml b/templates/partials/pagination.haml new file mode 100644 index 0000000..63638e0 --- /dev/null +++ b/templates/partials/pagination.haml @@ -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$ diff --git a/templates/tag-page.haml b/templates/tag-page.haml index 67a9f58..4f53c31 100644 --- a/templates/tag-page.haml +++ b/templates/tag-page.haml @@ -1,3 +1,4 @@ #tag-page %h1#tag.container $tag$ $partial("templates/partials/post-teaser-list.haml")$ + $partial("templates/partials/pagination.haml")$