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)":
|
task frontend, "Builds the necessary JS frontend (with CSS)":
|
||||||
exec "nimble c -r src/frontend/buildcss"
|
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"
|
mkDir "public/js"
|
||||||
cpFile "src/frontend/nimcache/forum.js", "public/js/forum.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":
|
task testdb, "Creates a test DB":
|
||||||
exec "nimble c src/setup_nimforum"
|
exec "nimble c src/setup_nimforum"
|
||||||
exec "./src/setup_nimforum --test"
|
exec "./src/setup_nimforum --test"
|
||||||
|
|
|
||||||
|
|
@ -6,9 +6,9 @@
|
||||||
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
<meta http-equiv="x-ua-compatible" content="ie=edge">
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1">
|
<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="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">
|
<link rel="icon" href="/images/favicon.png">
|
||||||
</head>
|
</head>
|
||||||
|
|
@ -16,6 +16,6 @@
|
||||||
<body>
|
<body>
|
||||||
<div id="ROOT" />
|
<div id="ROOT" />
|
||||||
|
|
||||||
<script type="text/javascript" src="/nimcache/forum.js"></script>
|
<script type="text/javascript" src="/js/forum.js?t=$timestamp"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
||||||
|
|
@ -51,6 +51,7 @@ var
|
||||||
config: Config
|
config: Config
|
||||||
captcha: ReCaptcha
|
captcha: ReCaptcha
|
||||||
mailer: Mailer
|
mailer: Mailer
|
||||||
|
karaxHtml: string
|
||||||
|
|
||||||
proc init(c: TForumData) =
|
proc init(c: TForumData) =
|
||||||
c.userPass = ""
|
c.userPass = ""
|
||||||
|
|
@ -248,6 +249,14 @@ proc initialise() =
|
||||||
if not existsFile(cssLoc / "nimforum.css"):
|
if not existsFile(cssLoc / "nimforum.css"):
|
||||||
sass.compileFile(cssLoc / "nimforum.scss", 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() =
|
template createTFD() =
|
||||||
var c {.inject.}: TForumData
|
var c {.inject.}: TForumData
|
||||||
new(c)
|
new(c)
|
||||||
|
|
@ -701,17 +710,6 @@ initialise()
|
||||||
|
|
||||||
routes:
|
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":
|
get "/threads.json":
|
||||||
var
|
var
|
||||||
start = getInt(@"start", 0)
|
start = getInt(@"start", 0)
|
||||||
|
|
@ -1332,22 +1330,9 @@ routes:
|
||||||
createTFD()
|
createTFD()
|
||||||
resp genPostsRSS(c), "application/atom+xml"
|
resp genPostsRSS(c), "application/atom+xml"
|
||||||
|
|
||||||
get re"/(.+)?":
|
get re"/(.*)":
|
||||||
resp readFile("public/karax.html")
|
cond request.matches[0].splitFile.ext == ""
|
||||||
|
resp karaxHtml
|
||||||
|
|
||||||
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, "")
|
|
||||||
|
|
||||||
when false:
|
when false:
|
||||||
post "/search/?@page?":
|
post "/search/?@page?":
|
||||||
|
|
|
||||||
|
|
@ -204,7 +204,7 @@ proc initialiseDb(admin: tuple[username, password, email: string],
|
||||||
close(db)
|
close(db)
|
||||||
|
|
||||||
proc initialiseConfig(
|
proc initialiseConfig(
|
||||||
name, hostname: string,
|
name, title, hostname: string,
|
||||||
recaptcha: tuple[siteKey, secretKey: string],
|
recaptcha: tuple[siteKey, secretKey: string],
|
||||||
smtp: tuple[address, user, password: string],
|
smtp: tuple[address, user, password: string],
|
||||||
isDev: bool,
|
isDev: bool,
|
||||||
|
|
@ -214,6 +214,7 @@ proc initialiseConfig(
|
||||||
|
|
||||||
var j = %{
|
var j = %{
|
||||||
"name": %name,
|
"name": %name,
|
||||||
|
"title": %title,
|
||||||
"hostname": %hostname,
|
"hostname": %hostname,
|
||||||
"recaptchaSiteKey": %recaptcha.siteKey,
|
"recaptchaSiteKey": %recaptcha.siteKey,
|
||||||
"recaptchaSecretKey": %recaptcha.secretKey,
|
"recaptchaSecretKey": %recaptcha.secretKey,
|
||||||
|
|
@ -224,8 +225,8 @@ proc initialiseConfig(
|
||||||
"dbPath": %dbPath
|
"dbPath": %dbPath
|
||||||
}
|
}
|
||||||
|
|
||||||
backup(path, some($j))
|
backup(path, some(pretty(j)))
|
||||||
writeFile(path, $j)
|
writeFile(path, pretty(j))
|
||||||
|
|
||||||
when isMainModule:
|
when isMainModule:
|
||||||
if paramCount() > 0:
|
if paramCount() > 0:
|
||||||
|
|
@ -234,6 +235,7 @@ when isMainModule:
|
||||||
let dbPath = "nimforum-dev.db"
|
let dbPath = "nimforum-dev.db"
|
||||||
echo("Initialising nimforum for development...")
|
echo("Initialising nimforum for development...")
|
||||||
initialiseConfig(
|
initialiseConfig(
|
||||||
|
"Development Forum",
|
||||||
"Development Forum",
|
"Development Forum",
|
||||||
"localhost",
|
"localhost",
|
||||||
recaptcha=("", ""),
|
recaptcha=("", ""),
|
||||||
|
|
@ -250,6 +252,7 @@ when isMainModule:
|
||||||
let dbPath = "nimforum-test.db"
|
let dbPath = "nimforum-test.db"
|
||||||
echo("Initialising nimforum for testing...")
|
echo("Initialising nimforum for testing...")
|
||||||
initialiseConfig(
|
initialiseConfig(
|
||||||
|
"Test Forum",
|
||||||
"Test Forum",
|
"Test Forum",
|
||||||
"localhost",
|
"localhost",
|
||||||
recaptcha=("", ""),
|
recaptcha=("", ""),
|
||||||
|
|
|
||||||
|
|
@ -27,7 +27,7 @@ type
|
||||||
isDev*: bool
|
isDev*: bool
|
||||||
dbPath*: string
|
dbPath*: string
|
||||||
hostname*: string
|
hostname*: string
|
||||||
name*: string
|
name*, title*: string
|
||||||
|
|
||||||
ForumError* = object of Exception
|
ForumError* = object of Exception
|
||||||
data*: PostError
|
data*: PostError
|
||||||
|
|
@ -63,6 +63,7 @@ proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
|
||||||
result.dbPath = root{"dbPath"}.getStr("nimforum.db")
|
result.dbPath = root{"dbPath"}.getStr("nimforum.db")
|
||||||
result.hostname = root["hostname"].getStr()
|
result.hostname = root["hostname"].getStr()
|
||||||
result.name = root["name"].getStr()
|
result.name = root["name"].getStr()
|
||||||
|
result.title = root["title"].getStr()
|
||||||
|
|
||||||
proc processGT(n: XmlNode, tag: string): (int, XmlNode, string) =
|
proc processGT(n: XmlNode, tag: string): (int, XmlNode, string) =
|
||||||
result = (0, newElement(tag), tag)
|
result = (0, newElement(tag), tag)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue