Hash :
4d2883c6
Author :
Thomas de Grivel
Date :
2024-10-27T14:25:53
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
defmodule PageController do
require EKC3
require File
require List
require Str
def show_html = fn (path_html, url) {
title = "kc3-lang.org"
name = File.name(path_html)
slug = Str.slice(name, 0, -9)
slug = Str.subst(slug, " ", "-")
slug = Str.subst(slug, ".", "-")
html = File.read_all(path_html)
page = PageView.render_show(html)
body = LayoutView.render(slug, title, page, url)
%HTTP.Response{body: body}
}
def show_md = fn (path_md, url) {
title = "kc3-lang.org"
md = File.read_all(path_md)
[title | _] = Markdown.titles(md)
slug = Str.subst(title, " ", "-")
html = Markdown.to_html_str(md)
page = PageView.render_show(html)
body = LayoutView.render(title, page, url)
%HTTP.Response{body: body}
}
def route = fn (request) {
if (request.method == GET ||
request.method == HEAD) do
locale = "en"
slash = if Str.ends_with?(request.url, "/") do "" else "/" end
path_html = "./pages#{request.url}#{slash}index.#{locale}.html"
if File.exists?(path_html) do
show_html(path_html, request.url)
else
path_md = "./pages#{request.url}#{slash}index.#{locale}.md"
if File.exists?(path_md) do
show_md(path_md, request.url)
else
path_md = "./pages#{request.url}.#{locale}.md"
if File.exists?(path_md) do
show_md(path_md, request.url)
end
end
end
end
}
end