aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2023-05-29 01:41:15 +0200
committerbptato <nincsnevem662@gmail.com>2023-06-01 13:01:44 +0200
commit245a2067ef8204dd6a260e1bdc415981243f549b (patch)
tree46ca4b7618766df1a358fa33567a00739b9772be
parentd48aa61fd8e3595a8ae90cfacc9f35318acbe8d4 (diff)
downloadchawan-245a2067ef8204dd6a260e1bdc415981243f549b.tar.gz
Fix more config inconsistencies
So that the default config actually works again. Also some doc updates.
-rw-r--r--doc/config.md14
-rw-r--r--src/buffer/container.nim2
-rw-r--r--src/config/config.nim45
-rw-r--r--src/display/pager.nim21
4 files changed, 48 insertions, 34 deletions
diff --git a/doc/config.md b/doc/config.md
index d18c3fa1..6b6d5dd2 100644
--- a/doc/config.md
+++ b/doc/config.md
@@ -301,7 +301,7 @@ passed as arguments are matched as well.</td>
</tr>
<tr>
-<td>substitute</td>
+<td>substitute-url</td>
<td>JavaScript function</td>
<td>A JavaScript function Chawan will pass the input string to. If a new string is
returned, it will be parsed instead of the old one.</td>
@@ -396,6 +396,18 @@ Defaults to false.
</td>
</tr>
+<tr>
+<td>scripting</td>
+<td>boolean</td>
+<td>Enable/disable JavaScript execution on this site.</td>
+</tr>
+
+<tr>
+<td>document-charset</td>
+<td>boolean</td>
+<td>Specify the default encoding for this site. Overrides document-charset
+in [encoding].</td>
+</tr>
</table>
diff --git a/src/buffer/container.nim b/src/buffer/container.nim
index 118bb57d..7ee40f22 100644
--- a/src/buffer/container.nim
+++ b/src/buffer/container.nim
@@ -701,7 +701,7 @@ proc load(container: Container) =
container.triggerEvent(SUCCESS)
if res.cookies.len > 0 and container.config.cookiejar != nil: # accept cookies
container.config.cookiejar.cookies.add(res.cookies)
- if res.referrerpolicy.isSome and container.config.refererfrom:
+ if res.referrerpolicy.isSome and container.config.referer_from:
container.config.referrerpolicy = res.referrerpolicy.get
container.setLoadInfo("Connected to " & $container.source.location & ". Downloading...")
if res.needsAuth:
diff --git a/src/config/config.nim b/src/config/config.nim
index 5817bdc2..90402149 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -28,32 +28,32 @@ type
StaticSiteConfig = object
url: Option[string]
host: Option[string]
- subst: Option[string]
+ rewrite_url: Option[string]
cookie: Option[bool]
- thirdpartycookie: seq[string]
- sharecookiejar: Option[string]
- refererfrom*: Option[bool]
+ third_party_cookie: seq[string]
+ share_cookie_jar: Option[string]
+ referer_from*: Option[bool]
scripting: Option[bool]
document_charset: seq[Charset]
StaticOmniRule = object
match: string
- subst: string
+ substitute_url: string
SiteConfig* = object
url*: Option[Regex]
host*: Option[Regex]
- subst*: (proc(s: URL): Option[URL])
+ rewrite_url*: (proc(s: URL): Option[URL])
cookie*: Option[bool]
- thirdpartycookie*: seq[Regex]
- sharecookiejar*: Option[string]
- refererfrom*: Option[bool]
+ third_party_cookie*: seq[Regex]
+ share_cookie_jar*: Option[string]
+ referer_from*: Option[bool]
scripting*: Option[bool]
document_charset*: seq[Charset]
OmniRule* = object
match*: Regex
- subst*: (proc(s: string): Option[string])
+ substitute_url*: (proc(s: string): Option[string])
StartConfig = object
visual_home*: string
@@ -110,7 +110,7 @@ type
filter*: URLFilter
cookiejar*: CookieJar
headers*: Headers
- refererfrom*: bool
+ referer_from*: bool
referrerpolicy*: ReferrerPolicy
scripting*: bool
charsets*: seq[Charset]
@@ -134,14 +134,14 @@ func getForkServerConfig*(config: Config): ForkServerConfig =
)
proc getBufferConfig*(config: Config, location: URL, cookiejar: CookieJar = nil,
- headers: Headers = nil, refererfrom = false, scripting = false,
+ headers: Headers = nil, referer_from = false, scripting = false,
charsets = config.encoding.document_charset): BufferConfig =
result = BufferConfig(
userstyle: config.css.stylesheet,
filter: newURLFilter(scheme = some(location.scheme), default = true),
cookiejar: cookiejar,
headers: headers,
- refererfrom: refererfrom,
+ referer_from: referer_from,
scripting: scripting,
charsets: charsets
)
@@ -153,20 +153,21 @@ proc getSiteConfig*(config: Config, jsctx: JSContext): seq[SiteConfig] =
var conf = SiteConfig(
cookie: sc.cookie,
scripting: sc.scripting,
- sharecookiejar: sc.sharecookiejar,
- refererfrom: sc.refererfrom,
+ share_cookie_jar: sc.share_cookie_jar,
+ referer_from: sc.referer_from,
document_charset: sc.document_charset
)
if sc.url.isSome:
conf.url = compileRegex(sc.url.get, 0)
elif sc.host.isSome:
conf.host = compileRegex(sc.host.get, 0)
- for rule in sc.thirdpartycookie:
- conf.thirdpartycookie.add(compileRegex(rule, 0).get)
- if sc.subst.isSome:
- let fun = jsctx.eval(sc.subst.get, "<siteconf>", JS_EVAL_TYPE_GLOBAL)
+ for rule in sc.third_party_cookie:
+ conf.third_party_cookie.add(compileRegex(rule, 0).get)
+ if sc.rewrite_url.isSome:
+ let fun = jsctx.eval(sc.rewrite_url.get, "<siteconf>",
+ JS_EVAL_TYPE_GLOBAL)
let f = getJSFunction[URL, URL](jsctx, fun)
- conf.subst = f.get
+ conf.rewrite_url = f.get
result.add(conf)
proc getOmniRules*(config: Config, jsctx: JSContext): seq[OmniRule] =
@@ -175,9 +176,9 @@ proc getOmniRules*(config: Config, jsctx: JSContext): seq[OmniRule] =
var conf = OmniRule(
match: re.get
)
- let fun = jsctx.eval(rule.subst, "<siteconf>", JS_EVAL_TYPE_GLOBAL)
+ let fun = jsctx.eval(rule.substitute_url, "<siteconf>", JS_EVAL_TYPE_GLOBAL)
let f = getJSFunction[string, string](jsctx, fun)
- conf.subst = f.get
+ conf.substitute_url = f.get
result.add(conf)
func getRealKey(key: string): string =
diff --git a/src/display/pager.nim b/src/display/pager.nim
index e79df4c7..85381c48 100644
--- a/src/display/pager.nim
+++ b/src/display/pager.nim
@@ -543,7 +543,7 @@ proc windowChange*(pager: Pager, attrs: WindowAttributes) =
proc applySiteconf(pager: Pager, request: Request): BufferConfig =
let url = $request.url
let host = request.url.host
- var refererfrom: bool
+ var referer_from: bool
var cookiejar: CookieJar
var headers: Headers
var scripting: bool
@@ -553,33 +553,34 @@ proc applySiteconf(pager: Pager, request: Request): BufferConfig =
continue
elif sc.host.isSome and not sc.host.get.match(host):
continue
- if sc.subst != nil:
- let s = sc.subst(request.url)
+ if sc.rewrite_url != nil:
+ let s = sc.rewrite_url(request.url)
if s.isSome and s.get != nil:
request.url = s.get
if sc.cookie.isSome:
if sc.cookie.get:
# host/url might have changed by now
- let jarid = sc.sharecookiejar.get(request.url.host)
+ let jarid = sc.share_cookiejar.get(request.url.host)
if jarid notin pager.cookiejars:
- pager.cookiejars[jarid] = newCookieJar(request.url, sc.thirdpartycookie)
+ pager.cookiejars[jarid] = newCookieJar(request.url,
+ sc.third_party_cookie)
cookiejar = pager.cookiejars[jarid]
else:
cookiejar = nil # override
if sc.scripting.isSome:
scripting = sc.scripting.get
- if sc.refererfrom.isSome:
- refererfrom = sc.refererfrom.get
+ if sc.referer_from.isSome:
+ referer_from = sc.referer_from.get
if sc.document_charset.len > 0:
charsets = sc.document_charset
return pager.config.getBufferConfig(request.url, cookiejar, headers,
- refererfrom, scripting, charsets)
+ referer_from, scripting, charsets)
# Load request in a new buffer.
proc gotoURL(pager: Pager, request: Request, prevurl = none(URL),
ctype = none(string), cs = none(Charset), replace: Container = nil,
redirectdepth = 0, referrer: Container = nil) =
- if referrer != nil and referrer.config.refererfrom:
+ if referrer != nil and referrer.config.referer_from:
request.referer = referrer.source.location
var bufferconfig = pager.applySiteconf(request)
if prevurl.isnone or not prevurl.get.equals(request.url, true) or
@@ -611,7 +612,7 @@ proc gotoURL(pager: Pager, request: Request, prevurl = none(URL),
proc omniRewrite(pager: Pager, s: string): string =
for rule in pager.omnirules:
if rule.match.match(s):
- let sub = rule.subst(s)
+ let sub = rule.substitute_url(s)
if sub.isSome:
return sub.get
else: