Don't appcache posts, tag and blog pages (>2)

Add context for appcache that can be detected in templates, which is
used to avoid appcaching post pages, as well as used to appcache only
the first two pages of the blog and for each tag.

Signed-off-by: Collin J. Doering <collin.doering@rekahsoft.ca>
This commit is contained in:
Collin J. Doering 2015-08-16 01:46:46 -04:00
parent 339126bfc7
commit 16a5e700cd
2 changed files with 15 additions and 4 deletions

View File

@ -194,12 +194,15 @@ main = do
compile $ do
posts <- recentFirst =<< loadAllSnapshots pattern "content"
indexCtx <- genNavContext "pages/blog.markdown"
navCtx <- genNavContext "pages/blog.markdown"
let ctx = taggedPostCtx tags <>
paginateContext paginatedTaggedPosts pageNum <>
constField "tag" tag <>
listField "posts" (taggedPostCtx tags) (return posts)
indexCtx = if pageNum <= 2
then appCacheCtx <> navCtx
else navCtx
makeItem ""
>>= loadAndApplyTemplate "templates/tag-page.html" ctx
@ -227,12 +230,16 @@ main = do
compile $ do
posts <- recentFirst =<< loadAllSnapshots pattern "content"
indexCtx <- genNavContext "pages/blog.markdown"
navCtx <- genNavContext "pages/blog.markdown"
let ctx = taggedPostCtx tags <>
paginateContext paginatedPosts pageNum <>
constField "weight" "0" <>
listField "posts" (taggedPostCtx tags) (return posts)
indexCtx = if pageNum <= 2
then appCacheCtx <> navCtx
else navCtx
makeItem ""
>>= loadAndApplyTemplate "templates/pages/blog.html" ctx
>>= loadAndApplyTemplate "templates/default.html" indexCtx
@ -251,13 +258,14 @@ main = do
pageTemplate = "templates/pages/" ++ pageName ++ ".html"
-- Generate navigation context
indexCtx <- genNavContext pageFilePath
navCtx <- genNavContext pageFilePath
let masterCtx =
listField "recentPosts" (taggedPostCtx tags) (return recentPosts) <>
listField "posts" (taggedPostCtx tags) (return posts) <>
tagCloudField "tagCloud" 65 135 tags <>
defaultContext
indexCtx = navCtx <> appCacheCtx
sectionCtx <- getResourceBody >>= genSectionContext
pg <- loadSnapshot (fromFilePath pageTemplate) "original"
@ -328,6 +336,9 @@ postCtx = dateField "date" "%B %e, %Y" <>
taggedPostCtx :: Tags -> Context String
taggedPostCtx tags = tagsField "tags" tags <> postCtx
appCacheCtx :: Context String
appCacheCtx = constField "appcache" "true"
pageWeight :: (Functor f, MonadMetadata f) => Item a -> f Int
pageWeight i = fmap (maybe 0 read) $ getMetadataField (itemIdentifier i) "weight"

View File

@ -1,5 +1,5 @@
<!DOCTYPE html>
<html class="en" manifest="/manifest.appcache">
<html class="en" $if(appcache)$manifest="/manifest.appcache"$endif$>
<head>
<!-- Basic Page Needs -->
<meta charset="utf-8">