diff --git a/src/forum.nim b/src/forum.nim index b5b0cf1..7324dcf 100644 --- a/src/forum.nim +++ b/src/forum.nim @@ -849,7 +849,123 @@ proc updateProfile( $rank, email, username ) -include "main.tmpl" +proc genRSSHeaders(c: TForumData): string = + # Migration from main.tmpl + result = fmt""" + + + """ + +proc genThreadsRSS(c: TForumData): string = + # Migration from main.tmpl + const + query = sql"""SELECT A.id, A.name, + strftime('%Y-%m-%dT%H:%M:%SZ', (A.modified)), + COUNT(B.id), C.name, B.content, B.id + FROM thread AS A, post AS B, person AS C + WHERE A.id = b.thread AND B.author = C.id + GROUP BY B.thread + ORDER BY modified DESC LIMIT ?""" + threadId = 0 + name = 1 + threadDate = 2 + postCount = 3 + postAuthor = 4 + postContent = 5 + postId = 6 + + let + frontQuery = c.req.makeUri("/") + recent = getValue(db, sql"""SELECT + strftime('%Y-%m-%dT%H:%M:%SZ', (modified)) FROM thread + ORDER BY modified DESC LIMIT 1""") + + result = fmt""" + + + {config.name} thread activity + + + {frontQuery} + {recent} +""" + + for row in rows(db, query, 10): + let url = c.genThreadUrl(threadId = row[threadId]) & "#" & row[postId] + + result.add( + fmt""" + {xmlEncode(row[name])} + urn:entry:{row[threadId]} + + {row[threadDate]} + {row[threadDate]} + {xmlEncode(row[postAuthor])} + Posts {row[postCount]}, {xmlEncode(row[postAuthor])} said: +<p> +{xmlEncode(rstToHtml(row[postContent]))} + + """) + + return result & "" + +proc genPostsRSS(c: TForumData): string = + ## Migration from main.tmpl + const + query = sql"""SELECT A.id, B.name, A.content, A.thread, T.name, + strftime('%Y-%m-%dT%H:%M:%SZ', A.creation), + A.creation, COUNT(C.id) + FROM post AS A, person AS B, post AS C, thread AS T + WHERE A.author = B.id AND A.thread = C.thread AND C.id <= A.id + AND T.id = A.thread + GROUP BY A.id + ORDER BY A.creation DESC LIMIT 10""" + postId = 0 + postAuthor = 1 + postContent = 2 + postThread = 3 + postHeader = 4 + postRssDate = 5 + postHumanDate = 6 + postPosition = 7 + + let + frontQuery = c.req.makeUri("/") + recent = getValue(db, sql"""SELECT + strftime('%Y-%m-%dT%H:%M:%SZ', creation) FROM post + ORDER BY creation DESC LIMIT 1""") + + result = fmt""" + + + {config.name} post activity + + + {frontQuery} + {recent} +""" + + for row in rows(db, query): + let url = c.genThreadUrl(threadid = row[postThread]) & "#" & row[postId] + result.add( + fmt""" + {xmlEncode(row[postHeader])} + urn:entry:{row[postId]} + # + + {row[postRssDate]} + {row[postRssDate]} + {xmlEncode(row[postAuthor])} + On {xmlEncode(row[postHumanDate])}, {xmlEncode(row[postAuthor])} said: +<p> +{xmlEncode(rstToHtml(row[postContent]))} + """) + + return result & "" initialise() diff --git a/src/main.tmpl b/src/main.tmpl deleted file mode 100644 index 3d4f8c2..0000000 --- a/src/main.tmpl +++ /dev/null @@ -1,107 +0,0 @@ -#? stdtmpl | standard -#template `!`(idx: untyped): untyped = -# row[idx] -#end template -#proc genRSSHeaders(c: TForumData): string = -# result = "" - - -#end proc -# -#proc genThreadsRSS(c: TForumData): string = -# result = "" -# const query = sql"""SELECT A.id, A.name, -# strftime('%Y-%m-%dT%H:%M:%SZ', (A.modified)), -# COUNT(B.id), C.name, B.content, B.id -# FROM thread AS A, post AS B, person AS C -# WHERE A.id = b.thread AND B.author = C.id -# GROUP BY B.thread -# ORDER BY modified DESC LIMIT ?""" -# const threadId = 0 -# const name = 1 -# const threadDate = 2 -# const postCount = 3 -# const postAuthor = 4 -# const postContent = 5 -# const postId = 6 -# let frontQuery = c.req.makeUri("/") -# let recent = getValue(db, sql"""SELECT -# strftime('%Y-%m-%dT%H:%M:%SZ', (modified)) FROM thread -# ORDER BY modified DESC LIMIT 1""") - - - ${config.name} thread activity - - - ${frontQuery} - ${recent} -# for row in rows(db, query, 10): - - ${xmlEncode(!name)} - urn:entry:${!threadid} - # let url = c.genThreadUrl(threadid = !threadid) & - # "#" & !postId - - ${!threadDate} - ${!threadDate} - ${xmlEncode(!postAuthor)} - Posts ${!postCount}, ${xmlEncode(!postAuthor)} said: -<p> -${xmlEncode(rstToHtml(!postContent))} - -# end for - -#end proc -# -#proc genPostsRSS(c: TForumData): string = -# result = "" -# const query = sql"""SELECT A.id, B.name, A.content, A.thread, T.name, -# strftime('%Y-%m-%dT%H:%M:%SZ', A.creation), -# A.creation, COUNT(C.id) -# FROM post AS A, person AS B, post AS C, thread AS T -# WHERE A.author = B.id AND A.thread = C.thread AND C.id <= A.id -# AND T.id = A.thread -# GROUP BY A.id -# ORDER BY A.creation DESC LIMIT 10""" -# const postId = 0 -# const postAuthor = 1 -# const postContent = 2 -# const postThread = 3 -# const postHeader = 4 -# const postRssDate = 5 -# const postHumanDate = 6 -# const postPosition = 7 -# let frontQuery = c.req.makeUri("/") -# let recent = getValue(db, sql"""SELECT -# strftime('%Y-%m-%dT%H:%M:%SZ', creation) FROM post -# ORDER BY creation DESC LIMIT 1""") - - - ${config.name} post activity - - - ${frontQuery} - ${recent} -# for row in rows(db, query): - - ${xmlEncode(!postHeader)} - urn:entry:${!postId} - # let url = c.genThreadUrl(threadid = !postThread) & - # "#" & !postId - - ${!postRssDate} - ${!postRssDate} - ${xmlEncode(!postAuthor)} - On ${xmlEncode(!postHumanDate)}, ${xmlEncode(!postAuthor)} said: -<p> -${xmlEncode(rstToHtml(!postContent))} - -# end for - -#end proc