Features to improve cooperation with webcrawlers.
Added proper titles to each page, page 1 of threads and posts lists now redirects to /.
This commit is contained in:
parent
9daa79425d
commit
82cc25bd62
3 changed files with 28 additions and 16 deletions
|
|
@ -5,7 +5,7 @@ This is Nimrod's forum. The code is not nice and depends on the RST parser of
|
||||||
the Nimrod compiler.
|
the Nimrod compiler.
|
||||||
|
|
||||||
|
|
||||||
Copyright (c) 2012 Andreas Rumpf.
|
Copyright (c) 2012 Andreas Rumpf, Dominik Picheta.
|
||||||
All rights reserved.
|
All rights reserved.
|
||||||
|
|
||||||
# License
|
# License
|
||||||
|
|
|
||||||
38
forum.nim
38
forum.nim
|
|
@ -36,7 +36,7 @@ type
|
||||||
actionContent: string
|
actionContent: string
|
||||||
errorMsg, loginErrorMsg: string
|
errorMsg, loginErrorMsg: string
|
||||||
invalidField: string
|
invalidField: string
|
||||||
currentPost: TPost
|
currentPost: TPost ## Only used for reply previews
|
||||||
startTime: float
|
startTime: float
|
||||||
isThreadsList: bool
|
isThreadsList: bool
|
||||||
pageNum: int
|
pageNum: int
|
||||||
|
|
@ -551,6 +551,11 @@ proc getPagesInThread(c: var TForumData): int =
|
||||||
proc getPagesInThreadByID(c: var TForumData, thrid: int): int =
|
proc getPagesInThreadByID(c: var TForumData, thrid: int): int =
|
||||||
result = ceil(c.gatherTotalPostsByID(thrid) / postsPerPage).int
|
result = ceil(c.gatherTotalPostsByID(thrid) / postsPerPage).int
|
||||||
|
|
||||||
|
proc getThreadTitle(thrid: int, pageNum: int): string =
|
||||||
|
result = GetValue(db, sql"select name from thread where id = ?", $thrid)
|
||||||
|
if pageNum notin {0,1}:
|
||||||
|
result.add(" - Page " & $pageNum)
|
||||||
|
|
||||||
proc genPagenumLocalNav(c: var TForumData, thrid: int): string =
|
proc genPagenumLocalNav(c: var TForumData, thrid: int): string =
|
||||||
result = ""
|
result = ""
|
||||||
const maxPostPages = 6 # Maximum links to pages shown.
|
const maxPostPages = 6 # Maximum links to pages shown.
|
||||||
|
|
@ -645,23 +650,26 @@ get "/":
|
||||||
createTFD()
|
createTFD()
|
||||||
c.isThreadsList = true
|
c.isThreadsList = true
|
||||||
var count = 0
|
var count = 0
|
||||||
resp genMain(c, genThreadsList(c, count), genRSSHeaders(c))
|
resp genMain(c, genThreadsList(c, count),
|
||||||
|
additionalHeaders = genRSSHeaders(c))
|
||||||
|
|
||||||
get "/threadActivity.xml":
|
get "/threadActivity.xml":
|
||||||
createTFD()
|
createTFD()
|
||||||
c.isThreadsList = true
|
c.isThreadsList = true
|
||||||
var count = 0
|
|
||||||
resp genRSS(c), "application/atom+xml"
|
resp genRSS(c), "application/atom+xml"
|
||||||
|
|
||||||
get "/t/@threadid/?@page?/?":
|
get "/t/@threadid/?@page?/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
|
var title = "Nimrod Forum - "
|
||||||
|
parseInt(@"threadid", c.threadId, -1..1000_000)
|
||||||
if @"page".len > 0:
|
if @"page".len > 0:
|
||||||
parseInt(@"page", c.pageNum, 0..1000_000)
|
parseInt(@"page", c.pageNum, 0..1000_000)
|
||||||
cond (c.pageNum > 0)
|
cond (c.pageNum > 0)
|
||||||
parseInt(@"threadid", c.threadId, -1..1000_000)
|
if c.pageNum == 1: redirect(uri("/t/" & $c.threadId))
|
||||||
if (@"postid").len > 0:
|
if (@"postid").len > 0:
|
||||||
parseInt(@"postid", c.postId, -1..1000_000)
|
parseInt(@"postid", c.postId, -1..1000_000)
|
||||||
var count = 0
|
var count = 0
|
||||||
|
var pSubject = getThreadTitle(c.threadid, c.pageNum)
|
||||||
cond validThreadId(c)
|
cond validThreadId(c)
|
||||||
gatherTotalPosts(c)
|
gatherTotalPosts(c)
|
||||||
if (@"action").len > 0:
|
if (@"action").len > 0:
|
||||||
|
|
@ -673,6 +681,7 @@ get "/t/@threadid/?@page?/?":
|
||||||
body = genPostsList(c, $c.threadId, count)
|
body = genPostsList(c, $c.threadId, count)
|
||||||
cond count != 0
|
cond count != 0
|
||||||
body.add genFormPost(c, "doreply", "Reply", subject, "", false)
|
body.add genFormPost(c, "doreply", "Reply", subject, "", false)
|
||||||
|
title.add("Replying to thread: " & pSubject)
|
||||||
of "edit":
|
of "edit":
|
||||||
cond c.postId != -1
|
cond c.postId != -1
|
||||||
const query = sql"select header, content from post where id = ?"
|
const query = sql"select header, content from post where id = ?"
|
||||||
|
|
@ -680,12 +689,13 @@ get "/t/@threadid/?@page?/?":
|
||||||
let header = ||row[0]
|
let header = ||row[0]
|
||||||
let content = ||row[1]
|
let content = ||row[1]
|
||||||
body = genFormPost(c, "doedit", "Edit", header, content, true)
|
body = genFormPost(c, "doedit", "Edit", header, content, true)
|
||||||
resp c.genMain(body)
|
title.add("Editing post")
|
||||||
|
resp c.genMain(body, title)
|
||||||
else:
|
else:
|
||||||
incrementViews(c)
|
incrementViews(c)
|
||||||
let posts = genPostsList(c, $c.threadId, count)
|
let posts = genPostsList(c, $c.threadId, count)
|
||||||
cond count != 0
|
cond count != 0
|
||||||
resp genMain(c, posts)
|
resp genMain(c, posts, title & pSubject)
|
||||||
|
|
||||||
get "/page/@page/?":
|
get "/page/@page/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
|
|
@ -693,25 +703,26 @@ get "/page/@page/?":
|
||||||
cond (@"page" != "")
|
cond (@"page" != "")
|
||||||
parseInt(@"page", c.pageNum, 0..1000_000)
|
parseInt(@"page", c.pageNum, 0..1000_000)
|
||||||
cond (c.pageNum > 0)
|
cond (c.pageNum > 0)
|
||||||
|
if c.pageNum == 1: redirect(uri("/"))
|
||||||
var count = 0
|
var count = 0
|
||||||
let list = genThreadsList(c, count)
|
let list = genThreadsList(c, count)
|
||||||
if count == 0:
|
if count == 0:
|
||||||
pass()
|
pass()
|
||||||
resp genMain(c, list, genRSSHeaders(c))
|
resp genMain(c, list, "Nimrod Forum - Page " & $c.pageNum, genRSSHeaders(c))
|
||||||
|
|
||||||
get "/profile/@nick/?":
|
get "/profile/@nick/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
cond (@"nick" != "")
|
cond (@"nick" != "")
|
||||||
var userinfo: TUserInfo
|
var userinfo: TUserInfo
|
||||||
if gatherUserInfo(c, @"nick", userinfo):
|
if gatherUserInfo(c, @"nick", userinfo):
|
||||||
resp genMain(c, c.genProfile(userinfo))
|
resp genMain(c, c.genProfile(userinfo),
|
||||||
|
"Nimrod Forum - " & @"nick" & "'s profile")
|
||||||
else:
|
else:
|
||||||
halt()
|
halt()
|
||||||
|
|
||||||
|
|
||||||
get "/login/?":
|
get "/login/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
resp genMain(c, genFormLogin(c))
|
resp genMain(c, genFormLogin(c), "Nimrod Forum - Log in")
|
||||||
|
|
||||||
get "/logout/?":
|
get "/logout/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
|
|
@ -720,7 +731,7 @@ get "/logout/?":
|
||||||
|
|
||||||
get "/register/?":
|
get "/register/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
resp genMain(c, genFormRegister(c))
|
resp genMain(c, genFormRegister(c), "Nimrod Forum - Register")
|
||||||
|
|
||||||
template readIDs(): stmt =
|
template readIDs(): stmt =
|
||||||
# Retrieve the threadid, postid and pagenum
|
# Retrieve the threadid, postid and pagenum
|
||||||
|
|
@ -738,7 +749,7 @@ template handleError(action: string, topText: string, isEdit: bool): stmt =
|
||||||
body.add genPostPreview(c, @"subject", @"content",
|
body.add genPostPreview(c, @"subject", @"content",
|
||||||
c.userName, $getGMTime(getTime()))
|
c.userName, $getGMTime(getTime()))
|
||||||
body.add genFormPost(c, action, topText, reuseText, reuseText, isEdit)
|
body.add genFormPost(c, action, topText, reuseText, reuseText, isEdit)
|
||||||
resp genMain(c, body)
|
resp genMain(c, body, "Nimrod Forum - Error")
|
||||||
|
|
||||||
post "/dologin":
|
post "/dologin":
|
||||||
createTFD()
|
createTFD()
|
||||||
|
|
@ -786,7 +797,8 @@ post "/doedit":
|
||||||
|
|
||||||
get "/newthread/?":
|
get "/newthread/?":
|
||||||
createTFD()
|
createTFD()
|
||||||
resp genMain(c, genFormPost(c, "donewthread", "New thread", "", "", false))
|
resp genMain(c, genFormPost(c, "donewthread", "New thread", "", "", false),
|
||||||
|
"Nimrod Forum - New Thread")
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
docConfig = rstgen.defaultConfig()
|
docConfig = rstgen.defaultConfig()
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
#! stdtmpl
|
#! stdtmpl
|
||||||
#proc genMain(c: var TForumData, content: string,
|
#proc genMain(c: var TForumData, content: string,
|
||||||
# additional_headers = ""): string =
|
# title = "Nimrod Forum", additional_headers = ""): string =
|
||||||
# result = ""
|
# result = ""
|
||||||
# var stats: TForumStats
|
# var stats: TForumStats
|
||||||
# if c.isThreadsList: stats = c.getStats(false)
|
# if c.isThreadsList: stats = c.getStats(false)
|
||||||
|
|
@ -10,7 +10,7 @@
|
||||||
<!doctype html>
|
<!doctype html>
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<head>
|
||||||
<title>Nimrod Forum</title>
|
<title>${XmlEncode(title)}</title>
|
||||||
<link rel="stylesheet" href="${c.req.makeUri("css/normalize.css", absolute = false)}">
|
<link rel="stylesheet" href="${c.req.makeUri("css/normalize.css", absolute = false)}">
|
||||||
<link rel="stylesheet" href="${c.req.makeUri("css/style.css", absolute = false)}">${additional_headers}
|
<link rel="stylesheet" href="${c.req.makeUri("css/style.css", absolute = false)}">${additional_headers}
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue