Implements /about/license

This commit is contained in:
Dominik Picheta 2018-05-19 23:43:10 +01:00
commit 1592be0503
6 changed files with 92 additions and 42 deletions

View file

@ -1,30 +1,30 @@
Forum content license
=====================
Content license
===============
All the content contributed to the Nim Forum is `cc-wiki (aka cc-by-sa)
All the content contributed to $hostname is `cc-wiki (aka cc-by-sa)
<http://creativecommons.org/licenses/by-sa/3.0/>`_ licensed, intended to be
**shared and remixed**. In the future we may even provide all this data as a
convenient data dump.
**shared and remixed**.
But our cc-wiki licensing, while intentionally permissive, does **require
attribution**::
The cc-wiki licensing, while intentionally permissive, does require
attribution:
**Attribution** — You must attribute the work in the manner specified by
the author or licensor (but not in any way that suggests that they endorse
you or your use of the work).
**Attribution** — You must attribute the work in the manner specified by
the author or licensor (but not in any way that suggests that they endorse
you or your use of the work).
Let us clarify what we mean by attribution. If you republish this content, we
require that you:
This means that if you republish this content, you are
required to:
* **Visually indicate that the content is from the Nim Forum**. It doesnt
* **Visually indicate that the content is from the $name**. It doesnt
have to be obnoxious; a discreet text blurb is fine.
* **Hyperlink directly to the original post** (e.g.,
http://forum.nim-lang.org/t/186)
https://$hostname/t/186/1#908)
* **Show the author names** for every post.
* **Hyperlink each author name** directly back to their user profile page
(e.g., http://forum.nim-lang.org/profile/Araq)
(e.g., http://$hostname/profile/Araq)
By “directly”, we mean each hyperlink must point directly to our domain in
To be more specific, each hyperlink must
point directly to the $hostname domain in
standard HTML visible even with JavaScript disabled, and not use a tinyurl or
any other form of obfuscation or redirection. Furthermore, the links must not
be `nofollowed
@ -36,7 +36,3 @@ time to create that content in the first place!
Feel free to remix and reuse to your hearts content, as long as a good faith
effort is made to attribute the content!
Content previous to the forum license change of
http://forum.nim-lang.org/t/186 remains under the original authors'
copyright, and therefore you cannot reuse it.

View file

@ -1848,6 +1848,15 @@ routes:
get "/404":
resp Http404, readFile("public/karax.html")
get "/about/license.html":
let content = readFile("public/license.rst").multiReplace(
{
"$hostname": config.hostname,
"$name": config.name
}
)
resp content.rstToHtml()
get re"/(.+)?":
resp readFile("public/karax.html")
@ -1992,11 +2001,6 @@ routes:
else:
resp genMain(c, genFormResetPassword(c), "Reset Password - Nim Forum")
get "/license":
createTFD()
resp genMain(c, rstToHtml(readFile("static/license.rst")),
"Content license - Nim Forum")
post "/search/?@page?":
cond isFTSAvailable
createTFD()

44
src/frontend/about.nim Normal file
View file

@ -0,0 +1,44 @@
when defined(js):
import sugar, httpcore, options, json
import dom except Event
include karax/prelude
import karax / [kajax, kdom]
import error, replybox, threadlist, post
import karaxutils
type
About* = ref object
loading: bool
status: HttpCode
content: kstring
page: string
proc newAbout*(): About =
About(
status: Http200
)
proc onContent(status: int, response: kstring, state: About) =
state.status = status.HttpCode
state.content = response
proc render*(state: About, page: string): VNode =
if state.status != Http200:
return renderError($state.content, state.status)
if page != state.page:
if not state.loading:
state.page = page
state.loading = true
state.status = Http200
let uri = makeUri("/about/" & page & ".html")
ajaxGet(uri, @[], (s: int, r: kstring) => onContent(s, r, state))
return buildHtml(tdiv(class="loading"))
result = buildHtml():
section(class="container grid-xl"):
tdiv(id="about"):
verbatim(state.content)

View file

@ -4,7 +4,7 @@ from dom import window, Location
include karax/prelude
import jester/patterns
import threadlist, postlist, header, profile, newthread, error
import threadlist, postlist, header, profile, newthread, error, about
import karaxutils
type
@ -12,6 +12,7 @@ type
url: Location
profile: ProfileState
newThread: NewThread
about: About
proc copyLocation(loc: Location): Location =
# TODO: It sucks that I had to do this. We need a nice way to deep copy in JS.
@ -30,7 +31,8 @@ proc newState(): State =
State(
url: copyLocation(window.location),
profile: newProfileState(),
newThread: newNewThread()
newThread: newNewThread(),
about: newAbout()
)
var state = newState()
@ -87,6 +89,9 @@ proc render(): VNode =
)
)
),
r("/about/?@page?",
(params: Params) => (render(state.about, params["page"]))
),
r("/404",
(params: Params) => render404()
),

View file

@ -235,7 +235,7 @@ when isMainModule:
echo("Initialising nimforum for development...")
initialiseConfig(
"Development Forum",
"localhost.local",
"localhost",
recaptcha=("", ""),
smtp=("", "", ""),
isDev=true,
@ -251,7 +251,7 @@ when isMainModule:
echo("Initialising nimforum for testing...")
initialiseConfig(
"Test Forum",
"localhost.local",
"localhost",
recaptcha=("", ""),
smtp=("", "", ""),
isDev=true,

View file

@ -26,6 +26,8 @@ type
recaptchaSiteKey*: string
isDev*: bool
dbPath*: string
hostname*: string
name*: string
var docConfig: StringTableRef
@ -36,19 +38,18 @@ docConfig["doc.listing_end"] = "</code><div class='code-buttons'><button class='
proc loadConfig*(filename = getCurrentDir() / "forum.json"): Config =
result = Config(smtpAddress: "", smtpPort: 25, smtpUser: "",
smtpPassword: "", mlistAddress: "")
try:
let root = parseFile(filename)
result.smtpAddress = root{"smtpAddress"}.getStr("")
result.smtpPort = root{"smtpPort"}.getNum(25).int
result.smtpUser = root{"smtpUser"}.getStr("")
result.smtpPassword = root{"smtpPassword"}.getStr("")
result.mlistAddress = root{"mlistAddress"}.getStr("")
result.recaptchaSecretKey = root{"recaptchaSecretKey"}.getStr("")
result.recaptchaSiteKey = root{"recaptchaSiteKey"}.getStr("")
result.isDev = root{"isDev"}.getBool()
result.dbPath = root{"dbPath"}.getStr("nimforum.db")
except:
echo("[WARNING] Couldn't read config file: ", filename)
let root = parseFile(filename)
result.smtpAddress = root{"smtpAddress"}.getStr("")
result.smtpPort = root{"smtpPort"}.getNum(25).int
result.smtpUser = root{"smtpUser"}.getStr("")
result.smtpPassword = root{"smtpPassword"}.getStr("")
result.mlistAddress = root{"mlistAddress"}.getStr("")
result.recaptchaSecretKey = root{"recaptchaSecretKey"}.getStr("")
result.recaptchaSiteKey = root{"recaptchaSiteKey"}.getStr("")
result.isDev = root{"isDev"}.getBool()
result.dbPath = root{"dbPath"}.getStr("nimforum.db")
result.hostname = root["hostname"].getStr()
result.name = root["name"].getStr()
proc processGT(n: XmlNode, tag: string): (int, XmlNode, string) =
result = (0, newElement(tag), tag)