Fixes for better performance (caching, minifying, etc.)
This commit is contained in:
parent
c0ecf782c8
commit
c9901824e2
5 changed files with 27 additions and 35 deletions
|
|
@ -34,10 +34,13 @@ task runbackend, "Runs the forum backend":
|
|||
|
||||
task frontend, "Builds the necessary JS frontend (with CSS)":
|
||||
exec "nimble c -r src/frontend/buildcss"
|
||||
exec "nimble js src/frontend/forum.nim"
|
||||
exec "nimble js -d:release src/frontend/forum.nim"
|
||||
mkDir "public/js"
|
||||
cpFile "src/frontend/nimcache/forum.js", "public/js/forum.js"
|
||||
|
||||
task minify, "Minifies the JS using Google's closure compiler":
|
||||
exec "closure-compiler public/js/forum.js --js_output_file public/js/forum.js.opt"
|
||||
|
||||
task testdb, "Creates a test DB":
|
||||
exec "nimble c src/setup_nimforum"
|
||||
exec "./src/setup_nimforum --test"
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@
|
|||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
||||
|
||||
<title>The Nim programming language forum</title>
|
||||
<title>$title</title>
|
||||
|
||||
<link rel="stylesheet" href="/nimforum.css">
|
||||
<link rel="stylesheet" href="/css/nimforum.css">
|
||||
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.12/css/all.css" integrity="sha384-G0fIWCsCzJIMAVNQPfjH08cyYaUtMwjJwqiRKxxE/rx96Uroj1BtIQ6MLJuheaO9" crossorigin="anonymous">
|
||||
<link rel="icon" href="/images/favicon.png">
|
||||
</head>
|
||||
|
|
@ -16,6 +16,6 @@
|
|||
<body>
|
||||
<div id="ROOT" />
|
||||
|
||||
<script type="text/javascript" src="/nimcache/forum.js"></script>
|
||||
<script type="text/javascript" src="/js/forum.js?t=$timestamp"></script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
|
|||
|
|
@ -51,6 +51,7 @@ var
|
|||
config: Config
|
||||
captcha: ReCaptcha
|
||||
mailer: Mailer
|
||||
karaxHtml: string
|
||||
|
||||
proc init(c: TForumData) =
|
||||
c.userPass = ""
|
||||
|
|
@ -248,6 +249,14 @@ proc initialise() =
|
|||
if not existsFile(cssLoc / "nimforum.css"):
|
||||
sass.compileFile(cssLoc / "nimforum.scss", cssLoc / "nimforum.css")
|
||||
|
||||
# Read karax.html and set its properties.
|
||||
karaxHtml = readFile("public/karax.html").multiReplace(
|
||||
{
|
||||
"$title": config.title,
|
||||
"$timestamp": encodeUrl(CompileDate & CompileTime)
|
||||
}
|
||||
)
|
||||
|
||||
template createTFD() =
|
||||
var c {.inject.}: TForumData
|
||||
new(c)
|
||||
|
|
@ -701,17 +710,6 @@ initialise()
|
|||
|
||||
routes:
|
||||
|
||||
get "/nimforum.css":
|
||||
resp readFile("public/css/nimforum.css"), "text/css"
|
||||
get "/nimcache/forum.js":
|
||||
resp readFile("public/js/forum.js"), "application/javascript"
|
||||
get re"/images/(.+?\.png)/?":
|
||||
let path = "public/images/" & request.matches[0]
|
||||
if fileExists(path):
|
||||
resp readFile(path), "image/png"
|
||||
else:
|
||||
resp Http404, "No such file."
|
||||
|
||||
get "/threads.json":
|
||||
var
|
||||
start = getInt(@"start", 0)
|
||||
|
|
@ -1332,22 +1330,9 @@ routes:
|
|||
createTFD()
|
||||
resp genPostsRSS(c), "application/atom+xml"
|
||||
|
||||
get re"/(.+)?":
|
||||
resp readFile("public/karax.html")
|
||||
|
||||
|
||||
get "/activateEmail/?":
|
||||
createTFD()
|
||||
cond(@"nick" != "")
|
||||
cond(@"epoch" != "")
|
||||
cond(@"ident" != "")
|
||||
var epoch: BiggestInt = 0
|
||||
cond(parseBiggestInt(@"epoch", epoch) > 0)
|
||||
var success = false
|
||||
# if verifyIdentHash(c, @"nick", $epoch, @"ident"):
|
||||
# let ban = parseEnum[Rank](db.getValue(sql"select status from person where name = ?", @"nick"))
|
||||
# # if ban == EmailUnconfirmed:
|
||||
# # success = setStatus(c, @"nick", Moderated, "")
|
||||
get re"/(.*)":
|
||||
cond request.matches[0].splitFile.ext == ""
|
||||
resp karaxHtml
|
||||
|
||||
when false:
|
||||
post "/search/?@page?":
|
||||
|
|
|
|||
|
|
@ -204,7 +204,7 @@ proc initialiseDb(admin: tuple[username, password, email: string],
|
|||
close(db)
|
||||
|
||||
proc initialiseConfig(
|
||||
name, hostname: string,
|
||||
name, title, hostname: string,
|
||||
recaptcha: tuple[siteKey, secretKey: string],
|
||||
smtp: tuple[address, user, password: string],
|
||||
isDev: bool,
|
||||
|
|
@ -214,6 +214,7 @@ proc initialiseConfig(
|
|||
|
||||
var j = %{
|
||||
"name": %name,
|
||||
"title": %title,
|
||||
"hostname": %hostname,
|
||||
"recaptchaSiteKey": %recaptcha.siteKey,
|
||||
"recaptchaSecretKey": %recaptcha.secretKey,
|
||||
|
|
@ -224,8 +225,8 @@ proc initialiseConfig(
|
|||
"dbPath": %dbPath
|
||||
}
|
||||
|
||||
backup(path, some($j))
|
||||
writeFile(path, $j)
|
||||
backup(path, some(pretty(j)))
|
||||
writeFile(path, pretty(j))
|
||||
|
||||
when isMainModule:
|
||||
if paramCount() > 0:
|
||||
|
|
@ -234,6 +235,7 @@ when isMainModule:
|
|||
let dbPath = "nimforum-dev.db"
|
||||
echo("Initialising nimforum for development...")
|
||||
initialiseConfig(
|
||||
"Development Forum",
|
||||
"Development Forum",
|
||||
"localhost",
|
||||
recaptcha=("", ""),
|
||||
|
|
@ -250,6 +252,7 @@ when isMainModule:
|
|||
let dbPath = "nimforum-test.db"
|
||||
echo("Initialising nimforum for testing...")
|
||||
initialiseConfig(
|
||||
"Test Forum",
|
||||
"Test Forum",
|
||||
"localhost",
|
||||
recaptcha=("", ""),
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ type
|
|||
isDev*: bool
|
||||
dbPath*: string
|
||||
hostname*: string
|
||||
name*: string
|
||||
name*, title*: string
|
||||
|
||||
ForumError* = object of Exception
|
||||
data*: PostError
|
||||
|
|
@ -63,6 +63,7 @@ proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
|
|||
result.dbPath = root{"dbPath"}.getStr("nimforum.db")
|
||||
result.hostname = root["hostname"].getStr()
|
||||
result.name = root["name"].getStr()
|
||||
result.title = root["title"].getStr()
|
||||
|
||||
proc processGT(n: XmlNode, tag: string): (int, XmlNode, string) =
|
||||
result = (0, newElement(tag), tag)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue