V2 #1
|
@ -9,7 +9,11 @@ open Microsoft.AspNetCore.Http
|
|||
let private pathAndPageNumber (ctx : HttpContext) =
|
||||
let slugs = (string ctx.Request.RouteValues["slug"]).Split "/" |> Array.filter (fun it -> it <> "")
|
||||
let pageIdx = Array.IndexOf (slugs, "page")
|
||||
let pageNbr = if pageIdx > 0 then (int64 slugs[pageIdx + 1]) else 1L
|
||||
let pageNbr =
|
||||
match pageIdx with
|
||||
| -1 -> Some 1L
|
||||
| idx when idx + 2 = slugs.Length -> Some (int64 slugs[pageIdx + 1])
|
||||
| _ -> None
|
||||
let slugParts = if pageIdx > 0 then Array.truncate pageIdx slugs else slugs
|
||||
pageNbr, String.Join ("/", slugParts)
|
||||
|
||||
|
@ -103,7 +107,8 @@ let pageOfPosts pageNbr : HttpHandler = fun next ctx -> task {
|
|||
let pageOfCategorizedPosts : HttpHandler = fun next ctx -> task {
|
||||
let webLog = WebLogCache.get ctx
|
||||
let conn = conn ctx
|
||||
let pageNbr, slug = pathAndPageNumber ctx
|
||||
match pathAndPageNumber ctx with
|
||||
| Some pageNbr, slug ->
|
||||
let allCats = CategoryCache.get ctx
|
||||
let cat = allCats |> Array.find (fun cat -> cat.slug = slug)
|
||||
// Category pages include posts in subcategories
|
||||
|
@ -122,6 +127,7 @@ let pageOfCategorizedPosts : HttpHandler = fun next ctx -> task {
|
|||
hash.Add ("is_category", true)
|
||||
return! themedView "index" next ctx hash
|
||||
| _ -> return! Error.notFound next ctx
|
||||
| None, _ -> return! Error.notFound next ctx
|
||||
}
|
||||
|
||||
open System.Web
|
||||
|
@ -131,7 +137,8 @@ open System.Web
|
|||
let pageOfTaggedPosts : HttpHandler = fun next ctx -> task {
|
||||
let webLog = WebLogCache.get ctx
|
||||
let conn = conn ctx
|
||||
let pageNbr, rawTag = pathAndPageNumber ctx
|
||||
match pathAndPageNumber ctx with
|
||||
| Some pageNbr, rawTag ->
|
||||
let tag = HttpUtility.UrlDecode rawTag
|
||||
match! Data.Post.findPageOfTaggedPosts webLog.id tag pageNbr webLog.postsPerPage conn with
|
||||
| posts when List.length posts > 0 ->
|
||||
|
@ -148,6 +155,7 @@ let pageOfTaggedPosts : HttpHandler = fun next ctx -> task {
|
|||
let endUrl = if pageNbr = 1L then "" else $"page/{pageNbr}"
|
||||
return! redirectTo true $"""/tag/{spacedTag.Replace (" ", "+")}/{endUrl}""" next ctx
|
||||
| _ -> return! Error.notFound next ctx
|
||||
| None, _ -> return! Error.notFound next ctx
|
||||
}
|
||||
|
||||
// GET /
|
||||
|
|
|
@ -3,5 +3,5 @@
|
|||
"hostname": "data02.bitbadger.solutions",
|
||||
"database": "myWebLog_dev"
|
||||
},
|
||||
"Generator": "myWebLog 2.0-alpha03"
|
||||
"Generator": "myWebLog 2.0-alpha04"
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user