Compare commits

..

4 Commits

Author SHA1 Message Date
447362c74d dark-easy theme 2025-06-26 14:37:52 +02:00
7a9d5aa371 Self-host marked.js 2025-06-26 00:11:14 +02:00
d9071a4947 Rename etc dump to bakedres dump 2025-06-26 00:07:12 +02:00
632d731118 Self-host highlight.js 2025-06-25 23:58:47 +02:00
13 changed files with 1400 additions and 65 deletions

View File

@ -20,6 +20,9 @@ INCBIN(favicon_ico, "./etc/favicon.ico");
INCBIN(hotreload_js, "./etc/hotreload.js"); INCBIN(hotreload_js, "./etc/hotreload.js");
#endif #endif
INCBIN(theme_js, "./etc/theme.js"); INCBIN(theme_js, "./etc/theme.js");
INCBIN(highlight_js, "./etc/highlight.js");
INCBIN(hljs_rainbow_css, "./etc/hljs-rainbow.css");
INCBIN(marked_js, "./etc/marked.js");
INCBIN(me_jpg, "./etc/me.jpg"); INCBIN(me_jpg, "./etc/me.jpg");
INCBIN(tmoa_engine_jpg, "./etc/tmoa-engine.jpg"); INCBIN(tmoa_engine_jpg, "./etc/tmoa-engine.jpg");
INCBIN(tmoa_garbage_jpg, "./etc/tmoa-garbage.jpg"); INCBIN(tmoa_garbage_jpg, "./etc/tmoa-garbage.jpg");
@ -66,6 +69,9 @@ void init_baked_resources(void)
add_baked_resource("hotreload.js", hotreload_js_data, hotreload_js_size); add_baked_resource("hotreload.js", hotreload_js_data, hotreload_js_size);
#endif #endif
add_baked_resource("theme.js", theme_js_data, theme_js_size); add_baked_resource("theme.js", theme_js_data, theme_js_size);
add_baked_resource("highlight.js", highlight_js_data, highlight_js_size);
add_baked_resource("hljs-rainbow.css", hljs_rainbow_css_data, hljs_rainbow_css_size);
add_baked_resource("marked.js", marked_js_data, marked_js_size);
add_baked_resource("me.jpg", me_jpg_data, me_jpg_size); add_baked_resource("me.jpg", me_jpg_data, me_jpg_size);
add_baked_resource("tmoa-engine.jpg", tmoa_engine_jpg_data, tmoa_engine_jpg_size); add_baked_resource("tmoa-engine.jpg", tmoa_engine_jpg_data, tmoa_engine_jpg_size);
add_baked_resource("tmoa-garbage.jpg", tmoa_garbage_jpg_data, tmoa_garbage_jpg_size); add_baked_resource("tmoa-garbage.jpg", tmoa_garbage_jpg_data, tmoa_garbage_jpg_size);

View File

@ -16,6 +16,9 @@ INCBIN_EXTERN(favicon_ico);
INCBIN_EXTERN(hotreload_js); INCBIN_EXTERN(hotreload_js);
#endif #endif
INCBIN_EXTERN(theme_js); INCBIN_EXTERN(theme_js);
INCBIN_EXTERN(highlight_js);
INCBIN_EXTERN(hljs_rainbow_css);
INCBIN_EXTERN(marked_js);
INCBIN_EXTERN(me_jpg); INCBIN_EXTERN(me_jpg);
INCBIN_EXTERN(tmoa_engine_jpg); INCBIN_EXTERN(tmoa_engine_jpg);
INCBIN_EXTERN(tmoa_garbage_jpg); INCBIN_EXTERN(tmoa_garbage_jpg);

View File

@ -5,7 +5,7 @@ how the code is architectured and some cool tricks that are used throughout the
## Our "engine" ## Our "engine"
![the engine](/etc/tmoa-engine.jpg) ![the engine](/bakedres/tmoa-engine.jpg)
This image is a joke, obviously. This image is a joke, obviously.
@ -133,7 +133,7 @@ void *route_thread_function(void *param)
// Unparsable HTTP request // Unparsable HTTP request
} }
if (mg_match(http_msg.uri, mg_str("/etc/*"), nil)) { if (mg_match(http_msg.uri, mg_str("/bakedres/*"), nil)) {
// Request for static resource // Request for static resource
} }
@ -147,7 +147,7 @@ this functionality comes with mongoose built-in. God bless you mongoose!
## Dynamic pages and static assets. ## Dynamic pages and static assets.
![the assets](/etc/tmoa-garbage.jpg) ![the assets](/bakedres/tmoa-garbage.jpg)
Let's stop here now and talk about something different entirely (dont' worry, we'll come back later). Let's stop here now and talk about something different entirely (dont' worry, we'll come back later).
I'd like to show you how assets/pages are implemented in aboba, so we get the whole picture. I'd like to show you how assets/pages are implemented in aboba, so we get the whole picture.

View File

@ -39,6 +39,9 @@ int main(int argc, char ** argv)
"./etc/hotreload.js", "./etc/hotreload.js",
"./etc/theme.js", "./etc/theme.js",
"./etc/simple.css", "./etc/simple.css",
"./etc/highlight.js",
"./etc/hljs-rainbow.css",
"./etc/marked.js",
"./etc/favicon.ico", "./etc/favicon.ico",
"./etc/me.jpg", "./etc/me.jpg",
"./etc/tmoa-engine.jpg", "./etc/tmoa-engine.jpg",

1244
etc/highlight.js Normal file

File diff suppressed because one or more lines are too long

1
etc/hljs-rainbow.css Normal file
View File

@ -0,0 +1 @@
pre code.hljs{display:block;overflow-x:auto;padding:1em}code.hljs{padding:3px 5px}.hljs{background:#474949;color:#d1d9e1}.hljs-comment,.hljs-quote{color:#969896;font-style:italic}.hljs-addition,.hljs-keyword,.hljs-literal,.hljs-selector-tag,.hljs-type{color:#c9c}.hljs-number,.hljs-selector-attr,.hljs-selector-pseudo{color:#f99157}.hljs-doctag,.hljs-regexp,.hljs-string{color:#8abeb7}.hljs-built_in,.hljs-name,.hljs-section,.hljs-title{color:#b5bd68}.hljs-class .hljs-title,.hljs-selector-id,.hljs-template-variable,.hljs-title.class_,.hljs-variable{color:#fc6}.hljs-name,.hljs-section,.hljs-strong{font-weight:700}.hljs-bullet,.hljs-link,.hljs-meta,.hljs-subst,.hljs-symbol{color:#f99157}.hljs-deletion{color:#dc322f}.hljs-formula{background:#eee8d5}.hljs-attr,.hljs-attribute{color:#81a2be}.hljs-emphasis{font-style:italic}

69
etc/marked.js Normal file

File diff suppressed because one or more lines are too long

View File

@ -82,12 +82,29 @@ function neon_cyber()
document.documentElement.style.setProperty("--disabled", "#333333"); document.documentElement.style.setProperty("--disabled", "#333333");
} }
function dark_easy()
{
document.documentElement.style.setProperty("--bg", "#1A1A1A");
document.documentElement.style.setProperty("--accent-bg", "#2E2E2E");
document.documentElement.style.setProperty("--text", "#DCDCDC");
document.documentElement.style.setProperty("--text-light", "#A3A3A3");
document.documentElement.style.setProperty("--border", "#585858");
document.documentElement.style.setProperty("--accent", "#FF5722");
document.documentElement.style.setProperty("--accent-hover", "#F4511E");
document.documentElement.style.setProperty("--accent-text", "#1A1A1A");
document.documentElement.style.setProperty("--code", "#8BC34A");
document.documentElement.style.setProperty("--preformatted", "#A3A3A3");
document.documentElement.style.setProperty("--marked", "#FF7043");
document.documentElement.style.setProperty("--disabled", "#383838");
}
const themes = { const themes = {
"light-breeze": light_breeze, "light-breeze": light_breeze,
"plan9-acme": plan9_acme, "plan9-acme": plan9_acme,
"bold-navy": bold_navy, "bold-navy": bold_navy,
"soft-lavander": soft_lavander, "soft-lavander": soft_lavander,
"neon-cyber": neon_cyber, "neon-cyber": neon_cyber,
"dark-easy": dark_easy,
}; };

80
main.c
View File

@ -18,7 +18,7 @@
#include "locked.h" #include "locked.h"
static locked(Route *) route_hashtable = locked_init(nil); static locked(Route *) route_hashtable = locked_init(nil);
static locked(char *) etc_dump_path = locked_init(nil); static locked(char *) baked_dump_path = locked_init(nil);
void run_in_thread(void *(*f)(void *), void *p) void run_in_thread(void *(*f)(void *), void *p)
{ {
@ -49,7 +49,7 @@ void *route_thread_function(void *param)
return nil; return nil;
} }
if (mg_match(http_msg.uri, mg_str("/etc/*"), nil)) { if (mg_match(http_msg.uri, mg_str("/bakedres/*"), nil)) {
Route_Result result = {0}; Route_Result result = {0};
result.type = ROUTE_RESULT_STATIC; result.type = ROUTE_RESULT_STATIC;
@ -60,9 +60,9 @@ void *route_thread_function(void *param)
char *file = basename(p); char *file = basename(p);
char *full_path = malloc(PATH_MAX); char *full_path = malloc(PATH_MAX);
lockx(&etc_dump_path); lockx(&baked_dump_path);
snprintf(full_path, PATH_MAX, "%s/%s", etc_dump_path.value, file); snprintf(full_path, PATH_MAX, "%s/%s", baked_dump_path.value, file);
unlockx(&etc_dump_path); unlockx(&baked_dump_path);
sb_append_nstr(&result.body, full_path); sb_append_nstr(&result.body, full_path);
sb_finish(&result.body); sb_finish(&result.body);
@ -165,23 +165,23 @@ void free_route_hashtable(void)
unlockx(&route_hashtable); unlockx(&route_hashtable);
} }
char *init_etc_dump(void) char *init_baked_dump(void)
{ {
char template[] = "/tmp/aboba-etc.XXXXXX"; char template[] = "/tmp/aboba-bakedres.XXXXXX";
char *etc_dump1 = mkdtemp(template); char *baked_dump1 = mkdtemp(template);
char *etc_dump = malloc(strlen(etc_dump1)+1); char *baked_dump = malloc(strlen(baked_dump1)+1);
strcpy(etc_dump, etc_dump1); strcpy(baked_dump, baked_dump1);
if (etc_dump == nil) { if (baked_dump == nil) {
LOGE("Could not create etc dump\n"); LOGE("Could not create bakedres dump\n");
return nil; return nil;
} }
LOGI("etc dump dir is %s\n", etc_dump); LOGI("bakedres dump dir is %s\n", baked_dump);
return etc_dump; return baked_dump;
} }
int etc_dump_rm_cb(const char *path, int baked_dump_rm_cb(const char *path,
discard const struct stat *st, discard const struct stat *st,
discard int type, discard int type,
discard struct FTW *ftw) discard struct FTW *ftw)
@ -189,14 +189,14 @@ int etc_dump_rm_cb(const char *path,
return remove(path); return remove(path);
} }
bool free_etc_dump(char *etc_dump) bool free_baked_dump(char *baked_dump)
{ {
LOGI("Removing etc dump %s\n", etc_dump); LOGI("Removing bakedres dump %s\n", baked_dump);
bool ok = nftw(etc_dump, etc_dump_rm_cb, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS) != -1; bool ok = nftw(baked_dump, baked_dump_rm_cb, FOPEN_MAX, FTW_DEPTH | FTW_MOUNT | FTW_PHYS) != -1;
if (!ok) { if (!ok) {
LOGE("Could not remove %s\n", etc_dump); LOGE("Could not remove %s\n", baked_dump);
} }
free(etc_dump); free(baked_dump);
return ok; return ok;
} }
@ -234,28 +234,20 @@ int cp(const char* source, const char* destination)
return result; return result;
} }
void populate_etc_dump(char *etc_dump) void copy_baked_resources_to_baked_dump(Baked_Resource *resource, void *udata)
{ {
static char *files[] = { char *baked_dump = (char *)udata;
"favicon.ico",
#if MY_DEBUG
"hotreload.js",
#endif
"theme.js",
"simple.css",
"me.jpg",
"tmoa-engine.jpg",
"tmoa-garbage.jpg",
};
lock_baked_resources();
for (size_t i = 0; i < sizeof(files)/sizeof(files[0]); i++) {
char path[PATH_MAX]; char path[PATH_MAX];
get_baked_resource_path(files[i], path, sizeof(path)); get_baked_resource_path(resource->key, path, sizeof(path));
char dest[PATH_MAX]; char dest[PATH_MAX];
snprintf(dest, sizeof(dest), "%s/%s", etc_dump, files[i]); snprintf(dest, sizeof(dest), "%s/%s", baked_dump, resource->key);
cp(path, dest); cp(path, dest);
} }
void populate_baked_dump(char *baked_dump)
{
lock_baked_resources();
baked_resource_each(&copy_baked_resources_to_baked_dump, baked_dump);
unlock_baked_resources(); unlock_baked_resources();
} }
@ -269,12 +261,12 @@ int main(int argc, char ** argv)
start_timer(); start_timer();
init_baked_resources(); init_baked_resources();
lockx(&etc_dump_path); lockx(&baked_dump_path);
if ((etc_dump_path.value = init_etc_dump()) == nil) { if ((baked_dump_path.value = init_baked_dump()) == nil) {
return 1; return 1;
} }
populate_etc_dump(etc_dump_path.value); populate_baked_dump(baked_dump_path.value);
unlockx(&etc_dump_path); unlockx(&baked_dump_path);
mg_log_set(MG_LL_DEBUG); mg_log_set(MG_LL_DEBUG);
struct mg_mgr mgr; struct mg_mgr mgr;
@ -292,9 +284,9 @@ int main(int argc, char ** argv)
mg_mgr_free(&mgr); mg_mgr_free(&mgr);
lockx(&etc_dump_path); lockx(&baked_dump_path);
free_etc_dump(etc_dump_path.value); free_baked_dump(baked_dump_path.value);
unlockx(&etc_dump_path); unlockx(&baked_dump_path);
free_baked_resources(); free_baked_resources();
return 0; return 0;

View File

@ -3,7 +3,7 @@
<head> <head>
<title>Blog</title> <title>Blog</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="stylesheet" href="/etc/simple.css" /> <link rel="stylesheet" href="/bakedres/simple.css" />
<#META_TAGS> <#META_TAGS>
</head> </head>
<body> <body>
@ -24,8 +24,8 @@
</footer> </footer>
<#ifdef HOTRELOAD> <#ifdef HOTRELOAD>
<script src="/etc/hotreload.js"></script> <script src="/bakedres/hotreload.js"></script>
<#endif> <#endif>
<script src="/etc/theme.js"></script> <script src="/bakedres/theme.js"></script>
</body> </body>
</html> </html>

View File

@ -3,7 +3,7 @@
<head> <head>
<title>Kamil's personal website</title> <title>Kamil's personal website</title>
<meta charset="utf-8" /> <meta charset="utf-8" />
<link rel="stylesheet" href="/etc/simple.css" /> <link rel="stylesheet" href="/bakedres/simple.css" />
<#META_TAGS> <#META_TAGS>
</head> </head>
<body> <body>
@ -54,7 +54,7 @@
</ul> </ul>
</section> </section>
<section> <section>
<img src="/etc/me.jpg" alt="literally me" /> <img src="/bakedres/me.jpg" alt="literally me" />
</section> </section>
<footer> <footer>
<div style="float: left;"> <div style="float: left;">
@ -65,8 +65,8 @@
</footer> </footer>
<#ifdef HOTRELOAD> <#ifdef HOTRELOAD>
<script src="/etc/hotreload.js"></script> <script src="/bakedres/hotreload.js"></script>
<#endif> <#endif>
<script src="/etc/theme.js"></script> <script src="/bakedres/theme.js"></script>
</body> </body>
</html> </html>

View File

@ -2,7 +2,7 @@
<html> <html>
<head> <head>
<title>404 - Page not found</title> <title>404 - Page not found</title>
<link rel="stylesheet" href="/etc/simple.css" /> <link rel="stylesheet" href="/bakedres/simple.css" />
<#META_TAGS> <#META_TAGS>
</head> </head>
<body> <body>
@ -19,8 +19,8 @@
</footer> </footer>
<#ifdef HOTRELOAD> <#ifdef HOTRELOAD>
<script src="/etc/hotreload.js"></script> <script src="/bakedres/hotreload.js"></script>
<#endif> <#endif>
<script src="/etc/theme.js"></script> <script src="/bakedres/theme.js"></script>
</body> </body>
</html> </html>

View File

@ -3,10 +3,10 @@
<head> <head>
<meta charset="utf-8" /> <meta charset="utf-8" />
<title><#BLOG_POST_TITLE></title> <title><#BLOG_POST_TITLE></title>
<link rel="stylesheet" href="/etc/simple.css" /> <link rel="stylesheet" href="/bakedres/simple.css" />
<#META_TAGS> <#META_TAGS>
<link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.11.1/build/styles/rainbow.min.css"> <link rel="stylesheet" href="/bakedres/hljs-rainbow.css">
<script src="https://cdn.jsdelivr.net/gh/highlightjs/cdn-release@11.11.1/build/highlight.min.js"></script> <script src="/bakedres/highlight.js"></script>
</head> </head>
<body> <body>
<div id="content"></div> <div id="content"></div>
@ -17,15 +17,15 @@
<span>Running since: <#RUNNING_SINCE></span> <span>Running since: <#RUNNING_SINCE></span>
</div> </div>
</footer> </footer>
<script src="https://cdn.jsdelivr.net/npm/marked/marked.min.js"></script> <script src="/bakedres/marked.js"></script>
<script> <script>
document.getElementById("content").innerHTML = marked.parse(`<#BLOG_POST_MARKDOWN>`); document.getElementById("content").innerHTML = marked.parse(`<#BLOG_POST_MARKDOWN>`);
</script> </script>
<#ifdef HOTRELOAD> <#ifdef HOTRELOAD>
<script src="/etc/hotreload.js"></script> <script src="/bakedres/hotreload.js"></script>
<#endif> <#endif>
<script src="/etc/theme.js"></script> <script src="/bakedres/theme.js"></script>
<script>hljs.highlightAll();</script> <script>hljs.highlightAll();</script>
</body> </body>
</html> </html>