mirror of
https://codeberg.org/bunbun/bunbun.dev
synced 2025-06-06 13:39:55 -07:00
initial
This commit is contained in:
40
client-handler.fnl
Normal file
40
client-handler.fnl
Normal file
@ -0,0 +1,40 @@
|
||||
(local utils (require :utils))
|
||||
|
||||
(local read-pages (. (require :page-handler) :read-pages))
|
||||
|
||||
(local client-handler {})
|
||||
|
||||
(fn client-handler.handle-client [client]
|
||||
(let [request (client:receive :*l)]
|
||||
|
||||
(print (: "Request from: %s:%s" :format (client:getpeername)))
|
||||
(print request)
|
||||
(while true
|
||||
(local request (client:receive :*l))
|
||||
(print request)
|
||||
(if (or (= request "") (not request))
|
||||
(lua :break)))
|
||||
|
||||
(var uri (request:match "GET%s+([^%s]+)%s+HTTP"))
|
||||
(set uri (uri:gsub "^/" ""))
|
||||
|
||||
(var content "")
|
||||
|
||||
(read-pages)
|
||||
|
||||
;; Maybe use scss instead of css
|
||||
;; (uri:match "%.css$") (.. "./" (utils.compile-sass (uri:gsub "%.css$" ".scss")))
|
||||
|
||||
(set content
|
||||
(if (= uri "") (. _G.files :main)
|
||||
(. _G.files uri) (. _G.files uri)
|
||||
(utils.file-exists? uri) (with-open [file (io.open uri :r)]
|
||||
(file:read :*a))
|
||||
"404 - Not Found"))
|
||||
|
||||
(client:send "HTTP/1.1 200 OK\r\n\r\n")
|
||||
(client:send content)
|
||||
|
||||
(client:close)))
|
||||
|
||||
client-handler
|
19
page-handler.fnl
Normal file
19
page-handler.fnl
Normal file
@ -0,0 +1,19 @@
|
||||
(local cmark (require :cmark))
|
||||
(local lfs (require :lfs))
|
||||
|
||||
(local page-handler {})
|
||||
|
||||
(fn page-handler.read-pages []
|
||||
(each [file (lfs.dir :pages)]
|
||||
(when (and (not= file ".") (not= file ".."))
|
||||
(local markdown (with-open [markdown-file (io.open (.. :pages/ file) :r)]
|
||||
(markdown-file:read :*a)))
|
||||
|
||||
(local html-template (with-open [html-template-file (io.open :template.html :r)]
|
||||
(html-template-file:read :*a)))
|
||||
|
||||
(local html (cmark.markdown_to_html markdown (markdown:len) cmark.OPT_UNSAFE))
|
||||
|
||||
(tset _G.files (file:match "(.+)%..+") (html-template:format html)))))
|
||||
|
||||
page-handler
|
16
rpi-os.install
Executable file
16
rpi-os.install
Executable file
@ -0,0 +1,16 @@
|
||||
#!/bin/sh
|
||||
|
||||
echo "Installing lua..."
|
||||
sudo apt install lua5.1 liblua5.1-dev
|
||||
|
||||
echo "Installing luarocks..."
|
||||
sudo apt install luarocks
|
||||
|
||||
echo "Installing dependencies..."
|
||||
sudo luarocks install cmark
|
||||
sudo luarocks install luafilesystem
|
||||
sudo luarocks install lsocket
|
||||
|
||||
echo "Installing fennel..."
|
||||
sudo curl -o /bin/fennel https://fennel-lang.org/downloads/fennel-1.4.2
|
||||
sudo chmod +x /bin/fennel
|
16
server.fnl
Normal file
16
server.fnl
Normal file
@ -0,0 +1,16 @@
|
||||
(local socket (require :socket))
|
||||
|
||||
(local handle-client (. (require :client-handler) :handle-client))
|
||||
|
||||
(local port 8080)
|
||||
(local server (socket.tcp))
|
||||
|
||||
(server:bind "*" port)
|
||||
(server:listen)
|
||||
|
||||
(while true
|
||||
(local client (server:accept))
|
||||
|
||||
(local co (coroutine.create (fn [] (handle-client client))))
|
||||
|
||||
(coroutine.resume co))
|
226
style.css
Normal file
226
style.css
Normal file
@ -0,0 +1,226 @@
|
||||
@import url("https://fonts.googleapis.com/css2?family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap");
|
||||
@import url("https://fonts.googleapis.com/css2?family=Roboto+Condensed:ital,wght@0,100..900;1,100..900&display=swap");
|
||||
@import url("https://fonts.googleapis.com/css2?family=Roboto+Mono:ital,wght@0,100..700;1,100..700&display=swap");
|
||||
@import url("https://fonts.googleapis.com/css2?family=Roboto+Slab:wght@100..900&display=swap");
|
||||
@import url("https://fonts.googleapis.com/css2?family=Roboto+Flex:opsz,wght@8..144,100..1000&display=swap");
|
||||
@import url("https://fonts.googleapis.com/css2?family=Roboto+Serif:ital,opsz,wght@0,8..144,100..900;1,8..144,100..900&display=swap");
|
||||
|
||||
:root {
|
||||
--serif-font: "Roboto Serif", serif;
|
||||
--sans-serif-font: "Roboto", sans-serif;
|
||||
--monospace-font: "Roboto Mono", monospace;
|
||||
|
||||
--white-10: #ffffff;
|
||||
--white-20: #ebebeb;
|
||||
--white-30: #d6d6d6;
|
||||
--white-40: #c2c2c2;
|
||||
--white-50: #adadad;
|
||||
|
||||
--black-10: #525252;
|
||||
--black-20: #3d3d3d;
|
||||
--black-30: #292929;
|
||||
--black-40: #141414;
|
||||
--black-50: #000000;
|
||||
}
|
||||
|
||||
:root {
|
||||
--foreground: var(--white-10);
|
||||
--background: var(--black-50);
|
||||
|
||||
--accent-10: var(--black-10);
|
||||
--accent-20: var(--black-20);
|
||||
--accent-30: var(--black-30);
|
||||
--accent-40: var(--black-40);
|
||||
--accent-50: var(--white-50);
|
||||
}
|
||||
|
||||
@media (prefers-color-scheme: light) {
|
||||
:root {
|
||||
--foreground: var(--black-50);
|
||||
--background: var(--white-10);
|
||||
|
||||
--accent-10: var(--white-50);
|
||||
--accent-20: var(--white-40);
|
||||
--accent-30: var(--white-30);
|
||||
--accent-40: var(--white-20);
|
||||
--accent-50: var(--black-10);
|
||||
}
|
||||
}
|
||||
|
||||
body {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
box-sizing: border-box;
|
||||
margin: 0;
|
||||
background: var(--background);
|
||||
padding: 1em;
|
||||
min-height: 100vh;
|
||||
color: var(--foreground);
|
||||
font-family: var(--sans-serif-font);
|
||||
}
|
||||
|
||||
body>header {
|
||||
position: sticky;
|
||||
top: 0;
|
||||
margin-top: -1em;
|
||||
border-bottom: 0.1em solid var(--accent-50);
|
||||
background: var(--background);
|
||||
padding: 0.5em;
|
||||
}
|
||||
|
||||
body>header>a {
|
||||
color: var(--foreground);
|
||||
font-weight: 550;
|
||||
font-size: 2em;
|
||||
text-decoration: none;
|
||||
|
||||
&::after {
|
||||
content: "_";
|
||||
}
|
||||
|
||||
&:hover::after {
|
||||
animation: blink 0.5s alternate infinite;
|
||||
}
|
||||
}
|
||||
|
||||
@keyframes blink {
|
||||
to {
|
||||
opacity: 0;
|
||||
}
|
||||
|
||||
from {
|
||||
opacity: 1;
|
||||
}
|
||||
}
|
||||
|
||||
body>.content {
|
||||
flex: 1;
|
||||
padding: 0.5em;
|
||||
overflow-y: hidden;
|
||||
}
|
||||
|
||||
body>.content>main {
|
||||
min-width: auto;
|
||||
}
|
||||
|
||||
body>.content>main {
|
||||
min-width: 60ch;
|
||||
max-width: 120ch;
|
||||
|
||||
/* paragraphs */
|
||||
p {
|
||||
margin: 0;
|
||||
color: var(--accent-50);
|
||||
}
|
||||
|
||||
p+p {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
/* headings */
|
||||
h1,
|
||||
h2,
|
||||
h3,
|
||||
h4,
|
||||
h5,
|
||||
h6 {
|
||||
margin: 0.5em 0;
|
||||
}
|
||||
|
||||
/* links */
|
||||
a {
|
||||
color: var(--foreground);
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
||||
|
||||
/* images */
|
||||
img {
|
||||
border-radius: 0.26em;
|
||||
}
|
||||
|
||||
/* block qutoes */
|
||||
blockquote {
|
||||
display: inline-block;
|
||||
margin: 0 1em;
|
||||
border-left: 0.2em solid var(--accent-40);
|
||||
padding-left: 0.5em;
|
||||
}
|
||||
|
||||
/* lists */
|
||||
ul,
|
||||
ol {
|
||||
margin: 0;
|
||||
padding-left: 2em;
|
||||
color: var(--accent-50);
|
||||
|
||||
li {
|
||||
margin: 0;
|
||||
}
|
||||
|
||||
li::marker {
|
||||
color: var(--foreground);
|
||||
}
|
||||
}
|
||||
|
||||
/* horizontal rule */
|
||||
hr {
|
||||
margin: 0;
|
||||
border: none;
|
||||
border-bottom: 0.1em solid var(--accent-50);
|
||||
}
|
||||
|
||||
/* inline code */
|
||||
p>code {
|
||||
display: inline-block;
|
||||
border-radius: 0.23em;
|
||||
background: var(--accent-40);
|
||||
padding: 0.2em;
|
||||
color: var(--foreground);
|
||||
font-size: 0.8em;
|
||||
line-height: 1;
|
||||
font-family: var(--monospace-font);
|
||||
}
|
||||
|
||||
/* code blocks */
|
||||
p+pre {
|
||||
margin-top: 1em;
|
||||
}
|
||||
|
||||
pre {
|
||||
display: inline-block;
|
||||
margin: 0;
|
||||
border-radius: 0.26em;
|
||||
background: var(--accent-40);
|
||||
padding: 0.8em;
|
||||
overflow: hidden;
|
||||
}
|
||||
|
||||
pre>code {
|
||||
font-size: 0.8em;
|
||||
font-family: var(--monospace-font);
|
||||
}
|
||||
}
|
||||
|
||||
body>footer {
|
||||
padding: 0.5em;
|
||||
color: var(--accent-10);
|
||||
}
|
||||
|
||||
body>footer>a {
|
||||
display: inline-block;
|
||||
margin: -0.2em 0;
|
||||
border-radius: 0.23em;
|
||||
background: #42a5f54d;
|
||||
padding: 0.2em;
|
||||
color: #42a5f5;
|
||||
line-height: 1;
|
||||
text-decoration: none;
|
||||
|
||||
&:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
}
|
22
template.html
Normal file
22
template.html
Normal file
@ -0,0 +1,22 @@
|
||||
<!doctype html>
|
||||
<html>
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<link rel="stylesheet" type="text/css" href="style.css" />
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<header>
|
||||
<a href="https://bunbun.dev">bunbun.dev</a>
|
||||
</header>
|
||||
<div class="content">
|
||||
<main>%s</main>
|
||||
</div>
|
||||
<footer>
|
||||
© 2024 Winter Hille —
|
||||
<a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.en">BY-NC-SA 4.0</a>
|
||||
</footer>
|
||||
</body>
|
||||
|
||||
</html>
|
Reference in New Issue
Block a user