Static site generator + my presonnal website written in rust for some reason.

rewrite in tiny_http and then abandonning

+253 -544
+1
.gitignore
··· 1 1 /target 2 + /output
+37 -511
Cargo.lock
··· 3 3 version = 3 4 4 5 5 [[package]] 6 - name = "addr2line" 7 - version = "0.22.0" 8 - source = "registry+https://github.com/rust-lang/crates.io-index" 9 - checksum = "6e4503c46a5c0c7844e948c9a4d6acd9f50cccb4de1c48eb9e291ea17470c678" 10 - dependencies = [ 11 - "gimli", 12 - ] 13 - 14 - [[package]] 15 - name = "adler" 16 - version = "1.0.2" 17 - source = "registry+https://github.com/rust-lang/crates.io-index" 18 - checksum = "f26201604c87b1e01bd3d98f8d5d9a8fcbb815e8cedb41ffccbeb4bf593a35fe" 19 - 20 - [[package]] 21 6 name = "adler2" 22 7 version = "2.0.0" 23 8 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 82 67 ] 83 68 84 69 [[package]] 70 + name = "ascii" 71 + version = "1.1.0" 72 + source = "registry+https://github.com/rust-lang/crates.io-index" 73 + checksum = "d92bec98840b8f03a5ff5413de5293bfcd8bf96467cf5452609f939ec6f5de16" 74 + 75 + [[package]] 85 76 name = "askama" 86 77 version = "0.12.1" 87 78 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 92 83 "humansize", 93 84 "num-traits", 94 85 "percent-encoding", 95 - ] 96 - 97 - [[package]] 98 - name = "askama_axum" 99 - version = "0.4.0" 100 - source = "registry+https://github.com/rust-lang/crates.io-index" 101 - checksum = "a41603f7cdbf5ac4af60760f17253eb6adf6ec5b6f14a7ed830cf687d375f163" 102 - dependencies = [ 103 - "askama", 104 - "axum-core", 105 - "http", 106 86 ] 107 87 108 88 [[package]] ··· 137 117 ] 138 118 139 119 [[package]] 140 - name = "async-trait" 141 - version = "0.1.81" 142 - source = "registry+https://github.com/rust-lang/crates.io-index" 143 - checksum = "6e0c28dcc82d7c8ead5cb13beb15405b57b8546e93215673ff8ca0349a028107" 144 - dependencies = [ 145 - "proc-macro2", 146 - "quote", 147 - "syn 2.0.76", 148 - ] 149 - 150 - [[package]] 151 120 name = "autocfg" 152 121 version = "1.3.0" 153 122 source = "registry+https://github.com/rust-lang/crates.io-index" 154 123 checksum = "0c4b4d0bd25bd0b74681c0ad21497610ce1b7c91b1022cd21c80c6fbdd9476b0" 155 124 156 125 [[package]] 157 - name = "axum" 158 - version = "0.7.5" 159 - source = "registry+https://github.com/rust-lang/crates.io-index" 160 - checksum = "3a6c9af12842a67734c9a2e355436e5d03b22383ed60cf13cd0c18fbfe3dcbcf" 161 - dependencies = [ 162 - "async-trait", 163 - "axum-core", 164 - "bytes", 165 - "futures-util", 166 - "http", 167 - "http-body", 168 - "http-body-util", 169 - "hyper", 170 - "hyper-util", 171 - "itoa", 172 - "matchit", 173 - "memchr", 174 - "mime", 175 - "percent-encoding", 176 - "pin-project-lite", 177 - "rustversion", 178 - "serde", 179 - "serde_json", 180 - "serde_path_to_error", 181 - "serde_urlencoded", 182 - "sync_wrapper 1.0.1", 183 - "tokio", 184 - "tower", 185 - "tower-layer", 186 - "tower-service", 187 - "tracing", 188 - ] 189 - 190 - [[package]] 191 - name = "axum-core" 192 - version = "0.4.3" 193 - source = "registry+https://github.com/rust-lang/crates.io-index" 194 - checksum = "a15c63fd72d41492dc4f497196f5da1fb04fb7529e631d73630d1b491e47a2e3" 195 - dependencies = [ 196 - "async-trait", 197 - "bytes", 198 - "futures-util", 199 - "http", 200 - "http-body", 201 - "http-body-util", 202 - "mime", 203 - "pin-project-lite", 204 - "rustversion", 205 - "sync_wrapper 0.1.2", 206 - "tower-layer", 207 - "tower-service", 208 - "tracing", 209 - ] 210 - 211 - [[package]] 212 - name = "backtrace" 213 - version = "0.3.73" 214 - source = "registry+https://github.com/rust-lang/crates.io-index" 215 - checksum = "5cc23269a4f8976d0a4d2e7109211a419fe30e8d88d677cd60b6bc79c5732e0a" 216 - dependencies = [ 217 - "addr2line", 218 - "cc", 219 - "cfg-if", 220 - "libc", 221 - "miniz_oxide 0.7.4", 222 - "object", 223 - "rustc-demangle", 224 - ] 225 - 226 - [[package]] 227 126 name = "base64" 228 127 version = "0.22.1" 229 128 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 287 186 checksum = "1fd0f2584146f6f2ef48085050886acf353beff7305ebd1ae69500e27c67f64b" 288 187 289 188 [[package]] 290 - name = "bytes" 291 - version = "1.7.1" 292 - source = "registry+https://github.com/rust-lang/crates.io-index" 293 - checksum = "8318a53db07bb3f8dca91a600466bdb3f2eaadeedfdbcf02e1accbad9271ba50" 294 - 295 - [[package]] 296 189 name = "caseless" 297 190 version = "0.2.1" 298 191 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 318 211 checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 319 212 320 213 [[package]] 214 + name = "chunked_transfer" 215 + version = "1.5.0" 216 + source = "registry+https://github.com/rust-lang/crates.io-index" 217 + checksum = "6e4de3bc4ea267985becf712dc6d9eed8b04c953b3fcfb339ebc87acd9804901" 218 + 219 + [[package]] 321 220 name = "clap" 322 221 version = "4.5.16" 323 222 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 440 339 441 340 [[package]] 442 341 name = "derive_builder" 443 - version = "0.20.0" 342 + version = "0.20.1" 444 343 source = "registry+https://github.com/rust-lang/crates.io-index" 445 - checksum = "0350b5cb0331628a5916d6c5c0b72e97393b8b6b03b47a9284f4e7f5a405ffd7" 344 + checksum = "cd33f37ee6a119146a1781d3356a7c26028f83d779b2e04ecd45fdc75c76877b" 446 345 dependencies = [ 447 346 "derive_builder_macro", 448 347 ] 449 348 450 349 [[package]] 451 350 name = "derive_builder_core" 452 - version = "0.20.0" 351 + version = "0.20.1" 453 352 source = "registry+https://github.com/rust-lang/crates.io-index" 454 - checksum = "d48cda787f839151732d396ac69e3473923d54312c070ee21e9effcaa8ca0b1d" 353 + checksum = "7431fa049613920234f22c47fdc33e6cf3ee83067091ea4277a3f8c4587aae38" 455 354 dependencies = [ 456 355 "darling", 457 356 "proc-macro2", ··· 461 360 462 361 [[package]] 463 362 name = "derive_builder_macro" 464 - version = "0.20.0" 363 + version = "0.20.1" 465 364 source = "registry+https://github.com/rust-lang/crates.io-index" 466 - checksum = "206868b8242f27cecce124c19fd88157fbd0dd334df2587f36417bafbc85097b" 365 + checksum = "4abae7035bf79b9877b779505d8cf3749285b80c43941eda66604841889451dc" 467 366 dependencies = [ 468 367 "derive_builder_core", 469 368 "syn 2.0.76", ··· 534 433 checksum = "324a1be68054ef05ad64b861cc9eaf1d623d2d8cb25b4bf2cb9cdd902b4bf253" 535 434 dependencies = [ 536 435 "crc32fast", 537 - "miniz_oxide 0.8.0", 436 + "miniz_oxide", 538 437 ] 539 438 540 439 [[package]] ··· 544 443 checksum = "3f9eec918d3f24069decb9af1554cad7c880e2da24a9afd88aca000531ab82c1" 545 444 546 445 [[package]] 547 - name = "form_urlencoded" 548 - version = "1.2.1" 549 - source = "registry+https://github.com/rust-lang/crates.io-index" 550 - checksum = "e13624c2627564efccf4934284bdd98cbaa14e79b0b5a141218e507b3a823456" 551 - dependencies = [ 552 - "percent-encoding", 553 - ] 554 - 555 - [[package]] 556 - name = "futures-channel" 557 - version = "0.3.30" 558 - source = "registry+https://github.com/rust-lang/crates.io-index" 559 - checksum = "eac8f7d7865dcb88bd4373ab671c8cf4508703796caa2b1985a9ca867b3fcb78" 560 - dependencies = [ 561 - "futures-core", 562 - ] 563 - 564 - [[package]] 565 - name = "futures-core" 566 - version = "0.3.30" 567 - source = "registry+https://github.com/rust-lang/crates.io-index" 568 - checksum = "dfc6580bb841c5a68e9ef15c77ccc837b40a7504914d52e47b8b0e9bbda25a1d" 569 - 570 - [[package]] 571 - name = "futures-sink" 572 - version = "0.3.30" 573 - source = "registry+https://github.com/rust-lang/crates.io-index" 574 - checksum = "9fb8e00e87438d937621c1c6269e53f536c14d3fbd6a042bb24879e57d474fb5" 575 - 576 - [[package]] 577 - name = "futures-task" 578 - version = "0.3.30" 579 - source = "registry+https://github.com/rust-lang/crates.io-index" 580 - checksum = "38d84fa142264698cdce1a9f9172cf383a0c82de1bddcf3092901442c4097004" 581 - 582 - [[package]] 583 - name = "futures-util" 584 - version = "0.3.30" 585 - source = "registry+https://github.com/rust-lang/crates.io-index" 586 - checksum = "3d6401deb83407ab3da39eba7e33987a73c3df0c82b4bb5813ee871c19c41d48" 587 - dependencies = [ 588 - "futures-core", 589 - "futures-task", 590 - "pin-project-lite", 591 - "pin-utils", 592 - ] 593 - 594 - [[package]] 595 446 name = "getrandom" 596 447 version = "0.2.15" 597 448 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 615 466 ] 616 467 617 468 [[package]] 618 - name = "gimli" 619 - version = "0.29.0" 620 - source = "registry+https://github.com/rust-lang/crates.io-index" 621 - checksum = "40ecd4077b5ae9fd2e9e169b102c6c330d0605168eb0e8bf79952b256dbefffd" 622 - 623 - [[package]] 624 469 name = "hashbrown" 625 470 version = "0.12.3" 626 471 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 639 484 checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea" 640 485 641 486 [[package]] 642 - name = "hermit-abi" 643 - version = "0.3.9" 644 - source = "registry+https://github.com/rust-lang/crates.io-index" 645 - checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" 646 - 647 - [[package]] 648 - name = "http" 649 - version = "1.1.0" 650 - source = "registry+https://github.com/rust-lang/crates.io-index" 651 - checksum = "21b9ddb458710bc376481b842f5da65cdf31522de232c1ca8146abce2a358258" 652 - dependencies = [ 653 - "bytes", 654 - "fnv", 655 - "itoa", 656 - ] 657 - 658 - [[package]] 659 - name = "http-body" 660 - version = "1.0.1" 661 - source = "registry+https://github.com/rust-lang/crates.io-index" 662 - checksum = "1efedce1fb8e6913f23e0c92de8e62cd5b772a67e7b3946df930a62566c93184" 663 - dependencies = [ 664 - "bytes", 665 - "http", 666 - ] 667 - 668 - [[package]] 669 - name = "http-body-util" 670 - version = "0.1.2" 671 - source = "registry+https://github.com/rust-lang/crates.io-index" 672 - checksum = "793429d76616a256bcb62c2a2ec2bed781c8307e797e2598c50010f2bee2544f" 673 - dependencies = [ 674 - "bytes", 675 - "futures-util", 676 - "http", 677 - "http-body", 678 - "pin-project-lite", 679 - ] 680 - 681 - [[package]] 682 - name = "http-range-header" 683 - version = "0.4.1" 684 - source = "registry+https://github.com/rust-lang/crates.io-index" 685 - checksum = "08a397c49fec283e3d6211adbe480be95aae5f304cfb923e9970e08956d5168a" 686 - 687 - [[package]] 688 - name = "httparse" 689 - version = "1.9.4" 690 - source = "registry+https://github.com/rust-lang/crates.io-index" 691 - checksum = "0fcc0b4a115bf80b728eb8ea024ad5bd707b615bfed49e0665b6e0f86fd082d9" 692 - 693 - [[package]] 694 487 name = "httpdate" 695 488 version = "1.0.3" 696 489 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 706 499 ] 707 500 708 501 [[package]] 709 - name = "hyper" 710 - version = "1.4.1" 711 - source = "registry+https://github.com/rust-lang/crates.io-index" 712 - checksum = "50dfd22e0e76d0f662d429a5f80fcaf3855009297eab6a0a9f8543834744ba05" 713 - dependencies = [ 714 - "bytes", 715 - "futures-channel", 716 - "futures-util", 717 - "http", 718 - "http-body", 719 - "httparse", 720 - "httpdate", 721 - "itoa", 722 - "pin-project-lite", 723 - "smallvec", 724 - "tokio", 725 - ] 726 - 727 - [[package]] 728 - name = "hyper-util" 729 - version = "0.1.7" 730 - source = "registry+https://github.com/rust-lang/crates.io-index" 731 - checksum = "cde7055719c54e36e95e8719f95883f22072a48ede39db7fc17a4e1d5281e9b9" 732 - dependencies = [ 733 - "bytes", 734 - "futures-util", 735 - "http", 736 - "http-body", 737 - "hyper", 738 - "pin-project-lite", 739 - "tokio", 740 - ] 741 - 742 - [[package]] 743 502 name = "ident_case" 744 503 version = "1.0.1" 745 504 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 757 516 758 517 [[package]] 759 518 name = "indexmap" 760 - version = "2.4.0" 519 + version = "2.5.0" 761 520 source = "registry+https://github.com/rust-lang/crates.io-index" 762 - checksum = "93ead53efc7ea8ed3cfb0c79fc8023fbb782a5432b52830b6518941cebe6505c" 521 + checksum = "68b900aa2f7301e21c36462b170ee99994de34dff39a4a6a528e80e7376d07e5" 763 522 dependencies = [ 764 523 "equivalent", 765 524 "hashbrown 0.14.5", ··· 832 591 ] 833 592 834 593 [[package]] 835 - name = "matchit" 836 - version = "0.7.3" 837 - source = "registry+https://github.com/rust-lang/crates.io-index" 838 - checksum = "0e7465ac9959cc2b1404e8e2367b43684a6d13790fe23056cc8c6c5a6b7bcb94" 839 - 840 - [[package]] 841 594 name = "memchr" 842 595 version = "2.7.4" 843 596 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 867 620 868 621 [[package]] 869 622 name = "miniz_oxide" 870 - version = "0.7.4" 871 - source = "registry+https://github.com/rust-lang/crates.io-index" 872 - checksum = "b8a240ddb74feaf34a79a7add65a741f3167852fba007066dcac1ca548d89c08" 873 - dependencies = [ 874 - "adler", 875 - ] 876 - 877 - [[package]] 878 - name = "miniz_oxide" 879 623 version = "0.8.0" 880 624 source = "registry+https://github.com/rust-lang/crates.io-index" 881 625 checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" ··· 884 628 ] 885 629 886 630 [[package]] 887 - name = "mio" 888 - version = "1.0.2" 889 - source = "registry+https://github.com/rust-lang/crates.io-index" 890 - checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" 891 - dependencies = [ 892 - "hermit-abi", 893 - "libc", 894 - "wasi", 895 - "windows-sys 0.52.0", 896 - ] 897 - 898 - [[package]] 899 631 name = "nom" 900 632 version = "7.1.3" 901 633 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 921 653 ] 922 654 923 655 [[package]] 924 - name = "object" 925 - version = "0.36.3" 926 - source = "registry+https://github.com/rust-lang/crates.io-index" 927 - checksum = "27b64972346851a39438c60b341ebc01bba47464ae329e55cf343eb93964efd9" 928 - dependencies = [ 929 - "memchr", 930 - ] 931 - 932 - [[package]] 933 656 name = "once_cell" 934 657 version = "1.19.0" 935 658 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 964 687 checksum = "e3148f5046208a5d56bcfc03053e3ca6334e51da8dfb19b6cdc8b306fae3283e" 965 688 966 689 [[package]] 967 - name = "pin-project" 968 - version = "1.1.5" 969 - source = "registry+https://github.com/rust-lang/crates.io-index" 970 - checksum = "b6bf43b791c5b9e34c3d182969b4abb522f9343702850a2e57f460d00d09b4b3" 971 - dependencies = [ 972 - "pin-project-internal", 973 - ] 974 - 975 - [[package]] 976 - name = "pin-project-internal" 977 - version = "1.1.5" 978 - source = "registry+https://github.com/rust-lang/crates.io-index" 979 - checksum = "2f38a4412a78282e09a2cf38d195ea5420d15ba0602cb375210efbc877243965" 980 - dependencies = [ 981 - "proc-macro2", 982 - "quote", 983 - "syn 2.0.76", 984 - ] 985 - 986 - [[package]] 987 - name = "pin-project-lite" 988 - version = "0.2.14" 989 - source = "registry+https://github.com/rust-lang/crates.io-index" 990 - checksum = "bda66fc9667c18cb2758a2ac84d1167245054bcf85d5d1aaa6923f45801bdd02" 991 - 992 - [[package]] 993 - name = "pin-utils" 994 - version = "0.1.0" 995 - source = "registry+https://github.com/rust-lang/crates.io-index" 996 - checksum = "8b870d8c151b6f2fb93e84a13146138f05d02ed11c7e7c54f8826aaaf7c9f184" 997 - 998 - [[package]] 999 690 name = "pkg-config" 1000 691 version = "0.3.30" 1001 692 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1008 699 checksum = "42cf17e9a1800f5f396bc67d193dc9411b59012a5876445ef450d449881e1016" 1009 700 dependencies = [ 1010 701 "base64", 1011 - "indexmap 2.4.0", 702 + "indexmap 2.5.0", 1012 703 "quick-xml", 1013 704 "serde", 1014 705 "time", ··· 1146 837 checksum = "7a66a03ae7c801facd77a29370b4faec201768915ac14a721ba36f20bc9c209b" 1147 838 1148 839 [[package]] 1149 - name = "rustc-demangle" 1150 - version = "0.1.24" 1151 - source = "registry+https://github.com/rust-lang/crates.io-index" 1152 - checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" 1153 - 1154 - [[package]] 1155 840 name = "rustix" 1156 841 version = "0.38.35" 1157 842 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1165 850 ] 1166 851 1167 852 [[package]] 1168 - name = "rustversion" 1169 - version = "1.0.17" 1170 - source = "registry+https://github.com/rust-lang/crates.io-index" 1171 - checksum = "955d28af4278de8121b7ebeb796b6a45735dc01436d898801014aced2773a3d6" 1172 - 1173 - [[package]] 1174 853 name = "rusty_duck" 1175 854 version = "0.1.0" 1176 855 dependencies = [ 856 + "ascii", 1177 857 "askama", 1178 - "askama_axum", 1179 - "axum", 1180 858 "comrak", 1181 859 "markdown-parser", 1182 860 "rand", 1183 861 "serde", 1184 862 "serde_yaml 0.9.34+deprecated", 1185 - "tokio", 1186 - "tower-http", 863 + "tiny_http", 1187 864 ] 1188 865 1189 866 [[package]] ··· 1234 911 ] 1235 912 1236 913 [[package]] 1237 - name = "serde_path_to_error" 1238 - version = "0.1.16" 1239 - source = "registry+https://github.com/rust-lang/crates.io-index" 1240 - checksum = "af99884400da37c88f5e9146b7f1fd0fbcae8f6eec4e9da38b67d05486f814a6" 1241 - dependencies = [ 1242 - "itoa", 1243 - "serde", 1244 - ] 1245 - 1246 - [[package]] 1247 - name = "serde_urlencoded" 1248 - version = "0.7.1" 1249 - source = "registry+https://github.com/rust-lang/crates.io-index" 1250 - checksum = "d3491c14715ca2294c4d6a88f15e84739788c1d030eed8c110436aafdaa2f3fd" 1251 - dependencies = [ 1252 - "form_urlencoded", 1253 - "itoa", 1254 - "ryu", 1255 - "serde", 1256 - ] 1257 - 1258 - [[package]] 1259 914 name = "serde_yaml" 1260 915 version = "0.8.26" 1261 916 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1273 928 source = "registry+https://github.com/rust-lang/crates.io-index" 1274 929 checksum = "6a8b1a1a2ebf674015cc02edccce75287f1a0130d394307b36743c2f5d504b47" 1275 930 dependencies = [ 1276 - "indexmap 2.4.0", 931 + "indexmap 2.5.0", 1277 932 "itoa", 1278 933 "ryu", 1279 934 "serde", ··· 1300 955 dependencies = [ 1301 956 "deunicode", 1302 957 "wasm-bindgen", 1303 - ] 1304 - 1305 - [[package]] 1306 - name = "smallvec" 1307 - version = "1.13.2" 1308 - source = "registry+https://github.com/rust-lang/crates.io-index" 1309 - checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 1310 - 1311 - [[package]] 1312 - name = "socket2" 1313 - version = "0.5.7" 1314 - source = "registry+https://github.com/rust-lang/crates.io-index" 1315 - checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" 1316 - dependencies = [ 1317 - "libc", 1318 - "windows-sys 0.52.0", 1319 958 ] 1320 959 1321 960 [[package]] ··· 1347 986 ] 1348 987 1349 988 [[package]] 1350 - name = "sync_wrapper" 1351 - version = "0.1.2" 1352 - source = "registry+https://github.com/rust-lang/crates.io-index" 1353 - checksum = "2047c6ded9c721764247e62cd3b03c09ffc529b2ba5b10ec482ae507a4a70160" 1354 - 1355 - [[package]] 1356 - name = "sync_wrapper" 1357 - version = "1.0.1" 1358 - source = "registry+https://github.com/rust-lang/crates.io-index" 1359 - checksum = "a7065abeca94b6a8a577f9bd45aa0867a2238b74e8eb67cf10d492bc39351394" 1360 - 1361 - [[package]] 1362 989 name = "syntect" 1363 990 version = "5.2.0" 1364 991 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1443 1070 ] 1444 1071 1445 1072 [[package]] 1073 + name = "tiny_http" 1074 + version = "0.12.0" 1075 + source = "registry+https://github.com/rust-lang/crates.io-index" 1076 + checksum = "389915df6413a2e74fb181895f933386023c71110878cd0825588928e64cdc82" 1077 + dependencies = [ 1078 + "ascii", 1079 + "chunked_transfer", 1080 + "httpdate", 1081 + "log", 1082 + ] 1083 + 1084 + [[package]] 1446 1085 name = "tinyvec" 1447 1086 version = "1.8.0" 1448 1087 source = "registry+https://github.com/rust-lang/crates.io-index" ··· 1458 1097 checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" 1459 1098 1460 1099 [[package]] 1461 - name = "tokio" 1462 - version = "1.39.3" 1463 - source = "registry+https://github.com/rust-lang/crates.io-index" 1464 - checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" 1465 - dependencies = [ 1466 - "backtrace", 1467 - "bytes", 1468 - "libc", 1469 - "mio", 1470 - "pin-project-lite", 1471 - "socket2", 1472 - "tokio-macros", 1473 - "windows-sys 0.52.0", 1474 - ] 1475 - 1476 - [[package]] 1477 - name = "tokio-macros" 1478 - version = "2.4.0" 1479 - source = "registry+https://github.com/rust-lang/crates.io-index" 1480 - checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" 1481 - dependencies = [ 1482 - "proc-macro2", 1483 - "quote", 1484 - "syn 2.0.76", 1485 - ] 1486 - 1487 - [[package]] 1488 - name = "tokio-util" 1489 - version = "0.7.11" 1490 - source = "registry+https://github.com/rust-lang/crates.io-index" 1491 - checksum = "9cf6b47b3771c49ac75ad09a6162f53ad4b8088b76ac60e8ec1455b31a189fe1" 1492 - dependencies = [ 1493 - "bytes", 1494 - "futures-core", 1495 - "futures-sink", 1496 - "pin-project-lite", 1497 - "tokio", 1498 - ] 1499 - 1500 - [[package]] 1501 1100 name = "toml" 1502 1101 version = "0.5.11" 1503 1102 source = "registry+https://github.com/rust-lang/crates.io-index" 1504 1103 checksum = "f4f7f0dd8d50a853a531c426359045b1998f04219d88799810762cd4ad314234" 1505 1104 dependencies = [ 1506 1105 "serde", 1507 - ] 1508 - 1509 - [[package]] 1510 - name = "tower" 1511 - version = "0.4.13" 1512 - source = "registry+https://github.com/rust-lang/crates.io-index" 1513 - checksum = "b8fa9be0de6cf49e536ce1851f987bd21a43b771b09473c3549a6c853db37c1c" 1514 - dependencies = [ 1515 - "futures-core", 1516 - "futures-util", 1517 - "pin-project", 1518 - "pin-project-lite", 1519 - "tokio", 1520 - "tower-layer", 1521 - "tower-service", 1522 - "tracing", 1523 - ] 1524 - 1525 - [[package]] 1526 - name = "tower-http" 1527 - version = "0.5.2" 1528 - source = "registry+https://github.com/rust-lang/crates.io-index" 1529 - checksum = "1e9cd434a998747dd2c4276bc96ee2e0c7a2eadf3cae88e52be55a05fa9053f5" 1530 - dependencies = [ 1531 - "bitflags 2.6.0", 1532 - "bytes", 1533 - "futures-util", 1534 - "http", 1535 - "http-body", 1536 - "http-body-util", 1537 - "http-range-header", 1538 - "httpdate", 1539 - "mime", 1540 - "mime_guess", 1541 - "percent-encoding", 1542 - "pin-project-lite", 1543 - "tokio", 1544 - "tokio-util", 1545 - "tower-layer", 1546 - "tower-service", 1547 - "tracing", 1548 - ] 1549 - 1550 - [[package]] 1551 - name = "tower-layer" 1552 - version = "0.3.3" 1553 - source = "registry+https://github.com/rust-lang/crates.io-index" 1554 - checksum = "121c2a6cda46980bb0fcd1647ffaf6cd3fc79a013de288782836f6df9c48780e" 1555 - 1556 - [[package]] 1557 - name = "tower-service" 1558 - version = "0.3.3" 1559 - source = "registry+https://github.com/rust-lang/crates.io-index" 1560 - checksum = "8df9b6e13f2d32c91b9bd719c00d1958837bc7dec474d94952798cc8e69eeec3" 1561 - 1562 - [[package]] 1563 - name = "tracing" 1564 - version = "0.1.40" 1565 - source = "registry+https://github.com/rust-lang/crates.io-index" 1566 - checksum = "c3523ab5a71916ccf420eebdf5521fcef02141234bbc0b8a49f2fdc4544364ef" 1567 - dependencies = [ 1568 - "log", 1569 - "pin-project-lite", 1570 - "tracing-core", 1571 - ] 1572 - 1573 - [[package]] 1574 - name = "tracing-core" 1575 - version = "0.1.32" 1576 - source = "registry+https://github.com/rust-lang/crates.io-index" 1577 - checksum = "c06d3da6113f116aaee68e4d601191614c9053067f9ab7f6edbcb161237daa54" 1578 - dependencies = [ 1579 - "once_cell", 1580 1106 ] 1581 1107 1582 1108 [[package]]
+3 -5
Cargo.toml
··· 11 11 strip = "symbols" # Strip symbols from binary 12 12 13 13 [dependencies] 14 - askama = { version = "0.12.1", features = ["with-axum"] } 15 - askama_axum = "0.4.0" 16 - axum = "0.7.5" 14 + ascii = "1.1.0" 15 + askama = { version = "0.12.1" } 17 16 comrak = "0.27.0" 18 17 markdown-parser = "0.1.2" 19 18 rand = "0.8.5" 20 19 serde = { version = "1.0.209", features = ["derive"] } 21 20 serde_yaml = "0.9.34" 22 - tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread"] } 23 - tower-http = { version = "0.5.2", features = ["fs"] } 21 + tiny_http = "0.12.0"
+8
posts/005-regenesis.md
··· 27 27 tower-http = { version = "0.5.2", features = ["fs"] } 28 28 ``` 29 29 30 + ```json 31 + { 32 + "firstName": "John", 33 + "lastName": "Smith", 34 + "age": 25 35 + } 36 + ``` 37 + 30 38 as dependancies in the end we get a clean~ish, 2.8MB executable. 31 39 32 40 All markdown compilation gets done every time page is loaded, which is sub-optimal,
+1 -1
src/blog_entries.rs
··· 29 29 post_vec.push(IndexPostEntry{ 30 30 title: front_matter.title, 31 31 date: front_matter.date, 32 - path: format!("/blog/{filename}"), 32 + path: format!("/blog/{filename}.html"), 33 33 }); 34 34 35 35 }
+27 -13
src/handlers.rs
··· 1 - use axum::{extract::Path,response::Html}; 2 1 use crate::structs::*; 3 2 use crate::rand_quote::get_quote; 4 3 use crate::blog_entries::{get_all_markdowns, get_blog_entry_markdown}; 5 4 6 - pub async fn index() -> Html<String> { 5 + pub fn index() -> String { 7 6 let all_entries = get_all_markdowns(); 8 7 let quote = get_quote(); 9 8 let new_page = IndexTemplate { random_quote: quote, index_post_entries:&all_entries}; 10 - Html(new_page.to_string()) 9 + new_page.to_string() 11 10 } 12 11 13 - pub async fn about() -> Html<String> { 12 + pub fn about() -> String { 14 13 15 - let about_content = comrak::markdown_to_html("about", &comrak::Options::default()); 14 + let about_content = parse_markdown("about"); 16 15 let page_content = AboutTemplate{about_content: &about_content}; 17 - Html(page_content.to_string()) 16 + page_content.to_string() 18 17 } 19 18 20 19 21 - pub async fn blog(Path(blog_path):Path<String>) -> Html<String> { 20 + pub fn blog(blog_path:String) -> String { 22 21 23 22 match get_blog_entry_markdown(&blog_path){ 24 - Ok(markdown) => Html( 23 + Ok(markdown) => 25 24 BlogTemplate{ 26 - blog_content: &comrak::markdown_to_html(markdown.content(), &comrak::Options::default()), 25 + blog_content: &parse_markdown(markdown.content()), 27 26 front_matter:&serde_yaml::from_str(markdown.front_matter()).unwrap()}.to_string() 28 - ), 29 - Err(..) => not_found().await, 27 + , 28 + Err(..) => not_found(), 30 29 } 31 30 32 31 } 33 32 34 - pub async fn not_found() -> Html<String> { 35 - Html(NotFoundTemplate{}.to_string()) 33 + pub fn not_found() -> String { 34 + NotFoundTemplate{}.to_string() 35 + } 36 + 37 + 38 + fn parse_markdown(content: &str) -> String { 39 + let mut options = comrak::Options::default(); 40 + 41 + options.extension.underline = true; 42 + options.extension.strikethrough = true; 43 + let plugins = comrak::Plugins::default(); 44 + //let adapter = comrak::plugins::syntect::SyntectAdapterBuilder::new() 45 + // .theme("base16-ocean.dark") 46 + // .build(); 47 + 48 + //plugins.render.codefence_syntax_highlighter = Some(&adapter); 49 + comrak::markdown_to_html_with_plugins(content, &options, &plugins) 36 50 }
+176 -14
src/main.rs
··· 1 - use axum::{routing::get, Router}; 2 - use tower_http::services::{ServeDir, ServeFile}; 1 + use std::{error::Error, fs::{self, read_dir, DirBuilder, File}, io::Write, path::Path}; 2 + 3 + use ascii::AsciiString; 4 + use tiny_http::{Response, Server}; 3 5 4 6 5 7 mod handlers; ··· 9 11 10 12 11 13 12 - #[tokio::main] 13 - async fn main() { 14 + fn main() { 15 + let output_path = "output"; 16 + match DirBuilder::new() 17 + .recursive(true) 18 + .create(output_path) { 19 + Ok(_) => (), 20 + Err(_) => (), 21 + } 14 22 15 - let app: axum::Router = Router::new() 16 - .route("/", get(handlers::index)) 17 - .route("/about", get(handlers::about)) 18 - .route("/blog",get(handlers::index)) 19 - .route("/blog/:blog_path",get(handlers::blog)) 20 - .route_service("/robots.txt", ServeFile::new("assets/robots.txt")) 21 - .fallback(get(handlers::not_found)) 22 - .nest_service("/assets", ServeDir::new("assets")); 23 + match copy_dir_all("assets", format!("{output_path}/assets")) { 24 + Ok(_) => (), 25 + Err(err) => println!("Couldnt copy assets directory, err: {err}"), 26 + } 27 + 28 + 29 + 30 + fs::write(format!("{output_path}/index.html"), handlers::index().as_bytes()).expect("Couldnt write index file"); 31 + fs::write(format!("{output_path}/about.html"), handlers::about().as_bytes()).expect("Couldnt write about file"); 32 + fs::write(format!("{output_path}/404.html"), handlers::not_found().as_bytes()).expect("Couldnt write 404 file"); 33 + 34 + match DirBuilder::new() 35 + .create(format!("{output_path}/blog")) { 36 + Ok(_) => (), 37 + Err(_) => (), 38 + } 39 + 40 + 41 + let post_dir_iter = match read_dir("posts/") { 42 + Ok(iter) => iter, 43 + Err(err) => panic!("could ls files, err {err}") 44 + }; 45 + 46 + for entry in post_dir_iter { 47 + if let Ok(entry) = entry { 48 + 49 + let filename = entry.file_name().into_string().unwrap().split(".").collect::<Vec<_>>()[0].to_string(); 50 + 51 + fs::write(format!("{output_path}/blog/{filename}.html"), handlers::blog(filename).as_bytes()).expect("Couldnt write blog entry"); 52 + }; 23 53 54 + } 24 55 25 - let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap(); 26 - axum::serve(listener, app).await.unwrap(); 27 56 } 57 + fn copy_dir_all(src: impl AsRef<Path>, dst: impl AsRef<Path>) -> std::io::Result<()> { 58 + std::fs::create_dir_all(&dst)?; 59 + for entry in std::fs::read_dir(src)? { 60 + let entry = entry?; 61 + let ty = entry.file_type()?; 62 + if ty.is_dir() { 63 + copy_dir_all(entry.path(), dst.as_ref().join(entry.file_name()))?; 64 + } else { 65 + std::fs::copy(entry.path(), dst.as_ref().join(entry.file_name()))?; 66 + } 67 + } 68 + Ok(()) 69 + } 70 + 71 + fn old_main() { 72 + 73 + // let app: axum::Router = Router::new() 74 + // .route("/", get(handlers::index)) 75 + // .route("/about", get(handlers::about)) 76 + // .route("/blog",get(handlers::index)) 77 + // .route("/blog/:blog_path",get(handlers::blog)) 78 + // .route_service("/robots.txt", ServeFile::new("assets/robots.txt")) 79 + // .fallback(get(handlers::not_found)) 80 + // .nest_service("/assets", ServeDir::new("assets")); 81 + // 82 + // 83 + // let listener = tokio::net::TcpListener::bind("127.0.0.1:3000").await.unwrap(); 84 + // axum::serve(listener, app).await.unwrap(); 85 + // 86 + //----- 87 + // let server = Arc::new(Server::http("127.0.0.1:3001").unwrap()); 88 + // println!("started server on port 3001"); 89 + // 90 + // let mut handles = Vec::new(); 91 + // 92 + // for thread_num in 0..6 { 93 + // println!("starting thread {}",thread_num); 94 + // let server = server.clone(); 95 + // handles.push(thread::spawn(move || server_thread(server))); 96 + // 97 + // } 98 + // for h in handles { 99 + // h.join().unwrap(); 100 + // } 101 + // ------------ 102 + let server = Server::http("127.0.0.1:3000").unwrap(); 103 + println!("started server on port 3001"); 104 + server_thread(server); 105 + 106 + } 107 + 108 + fn server_thread(server: Server) { 109 + for request in server.incoming_requests() { 110 + println!("received request; method: {}, url: {}", 111 + request.method(),request.url()); 112 + 113 + match request.url() { 114 + "" | "/" => { 115 + let response = Response::from_string(handlers::index()); 116 + let response = response.with_header(tiny_http::Header { 117 + field: "Content-Type".parse().unwrap(), 118 + value: AsciiString::from_ascii("text/html;charset=utf8").unwrap(), 119 + }); 120 + 121 + let _ = request.respond(response); 122 + 123 + } 124 + "/about" => { 125 + let response = Response::from_string(handlers::about()); 126 + let response = response.with_header(tiny_http::Header { 127 + field: "Content-Type".parse().unwrap(), 128 + value: AsciiString::from_ascii("text/html;charset=utf8").unwrap(), 129 + }); 130 + 131 + let _ = request.respond(response); 132 + 133 + } 134 + asset_url @ _ if asset_url.starts_with("/assets/") => { 135 + println!("getting asset : {}",asset_url); 136 + if let Some(asset) = get_asset(&asset_url){ 137 + let _ = request.respond(asset); 138 + } 139 + 140 + } 141 + blog_url @ _ if blog_url.starts_with("/blog/") => { 142 + 143 + 144 + let response = Response::from_string(handlers::blog(blog_url[6..].to_string())); 145 + let response = response.with_header(tiny_http::Header { 146 + field: "Content-Type".parse().unwrap(), 147 + value: AsciiString::from_ascii("text/html;charset=utf8").unwrap(), 148 + }); 149 + 150 + let _ = request.respond(response); 151 + 152 + } 153 + &_ => { 154 + 155 + let response = Response::from_string(handlers::not_found()); 156 + let response = response.with_header(tiny_http::Header { 157 + field: "Content-Type".parse().unwrap(), 158 + value: AsciiString::from_ascii("text/html;charset=utf8").unwrap(), 159 + }); 160 + 161 + let _ = request.respond(response); 162 + } 163 + } 164 + } 165 + } 166 + 167 + 168 + 169 + fn get_asset(asset:&str)-> Option<Response<File>>{ 170 + 171 + match Path::new(&asset[1..]).exists() { 172 + true => { 173 + println!("found asset"); 174 + Some(Response::from_file(File::open(&asset[1..]).unwrap())) 175 + } 176 + false => None, 177 + } 178 + 179 + } 180 + 181 + 182 + 183 + 184 + 185 + 186 + 187 + 188 + 189 +