kmx.io Blog
-
-
2024-12-06 20:45:49
Viewed 1325 times
A tour of the KC3 HTTPd Wiki
-
The https://www.kmx.io/ website relies primarily on a private wiki to translate the website pages from Markdown syntax to HTML. The page slug is included in the page body and div classes for custom CSS per page. The CSS still has to be configured site-wide there are no CSS includes per page for now but it could be easy to add.
To be able to edit a page you must be connected to the website with a login and password that only an admin can setup. Admin users can invite other users and set them as admin too. Admin users can remove other users and can delete pages from the website. Be careful when giving admin permissions to a user on a KC3 wiki.
Now if the user is connected, they can create a page by just visiting a URL that does not exist on the website and the
WikiController.routewill return a nice HTML form to create the page with Markdown syntax instead of the usual 404 not found. That allows any connected user to create any page that is not already a registered route on the server.Once the page is submitted, we are redirected to a
WikiController.showwhere the url is just the wiki page slug, meaning that if the wiki page slug is/then you just created the front page of the website. The wiki page shows the HTML version of the submitted Markdown so everything is fine.There is an Edit button at the top of the wiki show page if the user is still connected. The Edit button links to the wiki edit page which looks the same as the create page. And actually in database (facts) it also behaves the same as create as it generates a full new wiki page (in triples) as creating a new wiki page would, with a nice join on the slug and sort order on time.
Also there is a History button at the top of the wiki show page if the user is still connected. The History button links to the history page. The history page shows all versions of the wiki page from first to last. It is not possible to delete one version of the page. To delete a revision, you must delete the whole page. I'm not sure yet if it is a bug or a feature so I'm not going to fix it for now. But maybe a more sane behaviour is if you are an admin, or if you are the owner of the version, you can also just remove it. We'll see. On the wiki history page you can visit each version of the page by clicking on the Show button. Or you can stay on the history page and select (with an option list) a version to set as the current page version, which will change the wiki page show controller to display the selected version for the given slug (URL).
Any Delete operation on the website requires the admin user to type the full slug of what is to be removed in a web form.
The big idea behind this behaviour is that if users cannot be trusted we must prevent them from removing content from the website. The admins can still clean the data without any loss and figure out what happened with the logs and change all the possibly compromised users password.
Anyway that's how this website was built (except for the Blog, which you are reading). It's all Markdown all the way.
I will add some screen captures soon. Please come back later :) .
-
2024-12-06 20:45:49
Viewed 1325 times
-
-
2024-12-05 12:55:32
Viewed 724 times
First try for thread support in KC3 using pthread
-
I did a first try for thread support using pthread on KC3 and it mostly works because the facts database (triple store) and its cursors (iterators) are already [...]
-
2024-12-05 12:55:32
Viewed 724 times
-
-
2024-11-21 13:08:07
Viewed 702 times
New pages featuring SVG drawing in kc3_httpd
-
The images are generated on the fly by a custom route and controller in kc3_httpd. The xml body is then rendered with content type image/svg+xml.
This is an excerpt of our production code in
app/controllers/svg_controller.kc3:defmodule SvgController do def margin = 10 def points_on_circle = fn { (n, size) { points_on_circle(n, size, n, []) } (n, size, 0, acc) { List.reverse(acc) } (n, size, i, acc) { i = i - 1 a = 2 * F128.pi * i / n + F128.pi / 2 p = {(F128.cos(a) + 1) / 2 * size + margin, (F128.sin(a) + 1) / 2 * size + margin} points_on_circle(n, size, i, [p | acc]) } } def polygon = fn (request) { name = File.name(request.url) #puts("SvgController.polygon: name = \#\{name}") if Str.starts_with?(name, "polygon_") do name = Str.slice(name, 8, -1) if [n, size, "svg"] = Str.split(name, ".") do n = (U64) n size = (U64) size if (n > 1 && size > margin * 2) do points = points_on_circle(n, size - margin * 2) svg = SvgView.render_polygon(points, size) %HTTP.Response{body: svg, headers: [{"Content-Type", "image/svg+xml"}]} end end end } def points_to_star = fn { (points, n, k) { points_to_star(points, n, n - 1 - k, 0, []) } (points, n, i, j, acc) { acc = [points[i] | acc] if (j == n) do acc else i = if i < 2 do n + i - 2 else i - 2 end points_to_star(points, n, i, j + 1, acc) end } } def star = fn (request) { name = File.name(request.url) puts("SvgController.star: name = \#\{name}") if Str.starts_with?(name, "star_") do name = Str.slice(name, 5, -1) if [n, size, "svg"] = Str.split(name, ".") do n = (U64) n size = (U64) size if (n > 1 && size > margin * 2) do points = points_on_circle(n, size - margin * 2) star_0 = points_to_star(points, n, 0) star_1 = if (! (n mod 2)) do points_to_star(points, n, 1) else [] end svg = SvgView.render_star([star_0, star_1], size) %HTTP.Response{body: svg, headers: [{"Content-Type", "image/svg+xml"}]} end end end } def complete_graph = fn (request) { name = File.name(request.url) if Str.starts_with?(name, "complete_graph_") do name = Str.slice(name, 15, -1) if [n, size, "svg"] = Str.split(name, ".") do n = (U64) n size = (U64) size if (n > 1 && size > margin * 2) do points = points_on_circle(n, size - margin * 2) svg = SvgView.render_complete_graph(points, size) %HTTP.Response{body: svg, headers: [{"Content-Type", "image/svg+xml"}]} end end end } endTo understand better you should learn more Elixir because all the data model of KC3 is taken from Elixir. The main advantages of KC3 is that everything is introspectable through the graph database (triple store), and there is a much more simple and efficient KC3 / C interoperability with shared libraries through
dlopenanddlsym.We return a struct :
%HTTP.Response{}which is a KC3 struct compatible with C code. Unfortunately the KC3 <-> C interoperability is not portable and does not work on ARM64 (Apple Sillicon) because the padding and size of structs is different on each C compiler infrastructure. So it will always be a lot of work to follow each ABI on each system.
-
2024-11-21 13:08:07
Viewed 702 times
-
-
2024-11-10 10:41:13
Viewed 1060 times
New website for kmx.io, written in KC3
-
Today we released the new kmx.io website.
It is a web application including a blog and user management written in [KC3](https://kc3-la [...]
-
2024-11-10 10:41:13
Viewed 1060 times
-
-
2024-10-10 12:00:00
Viewed 773 times
New website for KC3
-
We put a new website online for the KC3 Programming Language
The website is self hosted on
kc3_httpdweb server written in KC3 and [...]
-
2024-10-10 12:00:00
Viewed 773 times