<<
path:
root/public/blog.git/html/src/gen/main.jai
blob: b7dac6d5ad1ebf4f4c1594778ff17f46829a6db5
[raw]
[clear marker]
1 Static html generator & search server.
2 Copyright (C) 2026 dev@ptrace.dev
4 This program is free software: you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation, either version 3 of the License, or
7 (at your option) any later version.
9 This program is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 GNU General Public License for more details.
14 You should have received a copy of the GNU General Public License
15 along with this program. If not, see <https://www.gnu.org/licenses/>.
18#import "Basic"()(MEMORY_DEBUGGER = MEMORY_DEBUGGER_ENABLED);
20#import "File_Utilities";
26#import "stb_image_write";
27#import "stb_image_resize";
30#import "htmltemplate";
33re :: #import "uniform";
36#load "../marshal.jai";
45/** This projects uses the convention of 'header' files. Which are unusual for Jai.
46 But since we have more than one program in the same project, it is easier to
47 share structs and constants.
49 The important bit is, that only indepentend objects can live there, with no
50 reference to the other program. Every header file must be self-contained.
54 This is fine to include.
61 This is bad to include.
68 Except you include `My_Custom_Type` too, which has no other dependencies!
73/** About memory: The current memory footprint is very small.
74 Like ~0.2 MB RAM leaked, while processing ~0.3 MB of HTML documents.
76 I do not expect to ever reach high numbers, so we can make use of the OS GC.
80/** TODO: The deployment to prod of blog posts and binary changes is quite annoying.
81 Need a more streamlined approach so we have less friction.
83 There are two workflows.
86 - Generate site: jai build.jai - run silent gen
87 - Refresh search index: jai build.jai - run silent search :: store
88 - Deploy: dev/push.py prod
90 2. Change something on the page
91 - Generate site: jai build.jai - run silent gen
92 - Refresh search index: jai build.jai - run silent search :: store
93 - Rebuild index binary: jai build.jai - silent search release
94 - Deploy: dev/push.py exe
97 - SSH into server: service.sh restart
102nav_bar: [..]Navbar_Item;
104pages_generated: [..]string;
108 #if MEMORY_DEBUGGER_ENABLED defer report_memory_leaks();
110 args := get_command_line_arguments();
112 if arg_find("help", "-h", "-help", "--help", "?") {
119 create_project_directories();
122 /** Update headers */
123 posts_to_update := posts_open(DIR_POSTS);
124 update_metadata_in_posts(posts_to_update);
126 generic_pages_to_update := posts_open(DIR_GENERIC);
127 update_metadata_in_posts(generic_pages_to_update);
130 /** Generate files */
131 posts := posts_open(DIR_POSTS);
132 entries := entries_make(posts);
133 entries_raw_md := array_copy(entries);
135 annotations_filter(*entries);
136 markdown_generate(*entries);
141 Currently, `entries_sorted_by_published` is not really used - except in
142 `page_entries_to_disk` where the order does not matter.
144 We might need it laterâ„¢
147 entries_sorted_by_update,
148 entries_sorted_by_published
149 := entries_sort(entries);
151 rss := page_rss(entries_sorted_by_update);
153 html_sorted_by_update_diet, // aka no images supplied, only links
154 html_sorted_by_published
155 := entries_make_html(entries_sorted_by_update, entries_sorted_by_published);
157 page_entries_to_disk(entries_sorted_by_published, html_sorted_by_published);
158 page_entries(html_sorted_by_update_diet);
159 page_entries_limited(html_sorted_by_update_diet);
160 page_overview(html_sorted_by_update_diet);
161 page_overview_limited(html_sorted_by_update_diet);
165 page_search_for_server();
168 /** If any operation above fails, it will exit and not write to file. */
169 entries_dump_data_or_exit(entries_raw_md, FP_DUMP_ENTRIES_MD);
170 entries_dump_data_or_exit(entries, FP_DUMP_ENTRIES_HTML);
171 copy_files_from_to(FILES_TO_COPY);
175 if !pages_generated log("No pages generated.");
176 for pages_generated log("> Generated: %", it);
184ARGS_HELP :: #string STR_END
186 -h, --help This help menu.
191arg_find :: (words: ..string) -> bool #expand {
192 for words if array_find(`args, it) return true;