Crossposting from forest.localcharts.org mostly fixed
Owen Lynch
Tue Apr 16 2024
The discourse/forest integration (the crossposting that happens when you put \meta{comments}{true}
in the heading of a forester post) has been subtly bugged for a while, because discourse decides to convert the forest url to lowercase. I had fixed this before by manually generating a cloudflare redirect for every forest page with a uppercase letter in it from the lowercased version, but then I moved off cloudflare and that didn’t work anymore. I now fixed it with openresty
and the following piece of code in nginx.conf
rewrite_by_lua_block {
local uri = ngx.var.uri
local matches, err = ngx.re.match(uri, "^/(\\w+)-([0-9a-z]{4})\\.xml$")
if matches and not err then
local new_uri = "/" .. matches[1] .. "-" .. string.upper(matches[2]) .. ".xml"
return ngx.redirect(new_uri, ngx.HTTP_MOVED_PERMANENTLY)
end
}
As a consequence, forest links of the form xxx-yyyy
will now redirect to xxx-YYYY
. This is not a perfect workaround for discourse’s lowercasing; in particular it will not fix the case where you have uppercase letters in the xxx
part. I suggest simply not doing that.
If you didn’t understand any of this, just know that localcharts is now slightly less broken.
Owen Lynch
Tue Apr 16 2024
Here’s a fun little exercise: spot the bug in the old code. Here’s a hint: what does it do on
lc-0001.xml
?Kevin Carlson
Wed Apr 17 2024
I wonder whether it would be a good idea for the Forest crossposts to actually paste the text in so people don’t have to navigate between two different pages to comment.
Owen Lynch
Wed Apr 17 2024
I think this could work if we ran the XML → HTML pipeline on the server instead of inbrowser, but I’m hesitant to do so because I’m worried it wouldn’t respond to edits of the forest page.
Matteo Capucci
Fri Apr 19 2024
Introducing…
<iframe>
Owen Lynch
Fri Apr 19 2024
If you want to hack on the plugin, be my guest!