#include "website.h" #define BLOG_PREVIEW_LINE_LIMIT 20 static void render_blog_preview(Filesystem& fs, String *html, const char *class_name, int blog_idx) { FS_File& file = fs.files[blog_idx]; char *fname = fs.name_pool.at(file.name_idx); int name_len = strlen(fname) - 3; if (name_len <= 0) { html->add("
"); return; } html->add("add_and_escape(fname, name_len); if (class_name) { html->add("\" class=\""); html->add_and_escape(class_name); } html->add("\">
"); //fs.refresh_file(blog_idx); html->add("
"); Markdown_Params md_params = { .created_time = file.created_time, .line_limit = BLOG_PREVIEW_LINE_LIMIT, .disable_anchors = true }; Space title = produce_markdown_html(fs, *html, (const char*)file.buffer, file.size, md_params); html->add("
"); html->add("
"); } void serve_blog_overview(Filesystem& fs, Response& response) { Inline_Vector blogs; FS_Directory folder = fs.dirs[fs.lookup_dir("content/blog")]; int fidx = folder.first_file.created; while (fidx >= 0) { FS_File& file = fs.files[fidx]; char *fname = fs.name_pool.at(file.name_idx); int len = strlen(fname); if (len < 4 || fname[len-3] != '.' || fname[len-2] != 'j' || fname[len-1] != 'b') { fidx = file.next.created; continue; } blogs.add(fidx); fidx = file.next.created; } String *html = &response.html; html->reserve(2048); html->add("" HTML_METAS "Blogs\n"); add_banner(fs, html, NAV_IDX_BLOG); html->add("
"); for (int i = 0; i < blogs.size; i++) { const char *kind = i % 2 ? "blog-right" : "blog-left"; render_blog_preview(fs, html, kind, blogs[blogs.size - i - 1]); } html->add("
"); } void serve_specific_blog(Filesystem& fs, Response& response, char *name, int name_len) { String path; path.add("content/blog/"); path.add_and_escape(name, name_len); path.add(".jb"); int fidx = fs.lookup_file(path.data()); if (fidx < 0) { serve_404(fs, response); return; } //fs.refresh_file(fidx); FS_File& file = fs.files[fidx]; String *html = &response.html; html->reserve(2048); html->add("" HTML_METAS); int title_dst_pos = html->len; html->add_chars(' ', 128); html->add("\n"); add_banner(fs, html, NAV_IDX_BLOG); html->add("
"); Markdown_Params md_params = { .created_time = file.created_time }; Space title = produce_markdown_html(fs, *html, (const char*)file.buffer, file.size, md_params); html->add("
"); html->add(""); title.size = title.size < 113 ? title.size : 113; // 128 - length("") - length("") char *title_dst = html->data() + title_dst_pos; strcpy(title_dst, ""); memcpy(title_dst + 7, (const char*)&file.buffer[title.offset], title.size); int title_end = 7 + title.size; if (title.size >= 110) { strcpy(title_dst + 117, "..."); title_end = 120; } memcpy(title_dst + title_end, "", 8); }