aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Garrelou <simon.garrelou@gmail.com>2023-07-01 22:21:57 +0200
committerSimon Garrelou <simon.garrelou@gmail.com>2023-07-01 22:21:57 +0200
commit377bfd98cea99483eda2d659d8f1423761ea25ed (patch)
treeb98cf34073e4aa7dcbe9243edc4ed3c98a05588d
parente1488de3a644113b4de826767a003426c0004d42 (diff)
downloadrss-377bfd98cea99483eda2d659d8f1423761ea25ed.tar.gz
rss-377bfd98cea99483eda2d659d8f1423761ea25ed.zip
Imporve filter, add render
-rw-r--r--Cargo.lock516
-rw-r--r--Cargo.toml4
-rw-r--r--src/filter.rs82
-rw-r--r--src/main.rs79
-rw-r--r--src/render.rs15
5 files changed, 690 insertions, 6 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 6d2f3e9..4555e1d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -3,6 +3,24 @@
3version = 3 3version = 3
4 4
5[[package]] 5[[package]]
6name = "aho-corasick"
7version = "0.7.20"
8source = "registry+https://github.com/rust-lang/crates.io-index"
9checksum = "cc936419f96fa211c1b9166887b38e5e40b19958e5b895be7c1f93adec7071ac"
10dependencies = [
11 "memchr",
12]
13
14[[package]]
15name = "aho-corasick"
16version = "1.0.2"
17source = "registry+https://github.com/rust-lang/crates.io-index"
18checksum = "43f6cb1bf222025340178f382c426f13757b2960e89779dfcb319c32542a5a41"
19dependencies = [
20 "memchr",
21]
22
23[[package]]
6name = "android-tzdata" 24name = "android-tzdata"
7version = "0.1.1" 25version = "0.1.1"
8source = "registry+https://github.com/rust-lang/crates.io-index" 26source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -104,6 +122,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
104checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" 122checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
105 123
106[[package]] 124[[package]]
125name = "block-buffer"
126version = "0.10.4"
127source = "registry+https://github.com/rust-lang/crates.io-index"
128checksum = "3078c7629b62d3f0439517fa394996acacc5cbc91c5a20d8c658e77abd503a71"
129dependencies = [
130 "generic-array",
131]
132
133[[package]]
134name = "bstr"
135version = "1.5.0"
136source = "registry+https://github.com/rust-lang/crates.io-index"
137checksum = "a246e68bb43f6cd9db24bea052a53e40405417c5fb372e3d1a8a7f770a564ef5"
138dependencies = [
139 "memchr",
140 "serde",
141]
142
143[[package]]
107name = "bumpalo" 144name = "bumpalo"
108version = "3.13.0" 145version = "3.13.0"
109source = "registry+https://github.com/rust-lang/crates.io-index" 146source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -143,6 +180,28 @@ dependencies = [
143] 180]
144 181
145[[package]] 182[[package]]
183name = "chrono-tz"
184version = "0.6.1"
185source = "registry+https://github.com/rust-lang/crates.io-index"
186checksum = "58549f1842da3080ce63002102d5bc954c7bc843d4f47818e642abdc36253552"
187dependencies = [
188 "chrono",
189 "chrono-tz-build",
190 "phf",
191]
192
193[[package]]
194name = "chrono-tz-build"
195version = "0.0.2"
196source = "registry+https://github.com/rust-lang/crates.io-index"
197checksum = "db058d493fb2f65f41861bfed7e3fe6335264a9f0f92710cab5bdf01fef09069"
198dependencies = [
199 "parse-zoneinfo",
200 "phf",
201 "phf_codegen",
202]
203
204[[package]]
146name = "clap" 205name = "clap"
147version = "4.3.4" 206version = "4.3.4"
148source = "registry+https://github.com/rust-lang/crates.io-index" 207source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -207,6 +266,25 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
207checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa" 266checksum = "e496a50fda8aacccc86d7529e2c1e0892dbd0f898a6b5645b5561b89c3210efa"
208 267
209[[package]] 268[[package]]
269name = "cpufeatures"
270version = "0.2.8"
271source = "registry+https://github.com/rust-lang/crates.io-index"
272checksum = "03e69e28e9f7f77debdedbaafa2866e1de9ba56df55a8bd7cfc724c25a09987c"
273dependencies = [
274 "libc",
275]
276
277[[package]]
278name = "crypto-common"
279version = "0.1.6"
280source = "registry+https://github.com/rust-lang/crates.io-index"
281checksum = "1bfb12502f3fc46cca1bb51ac28df9d618d813cdc3d2f25b9fe775a34af26bb3"
282dependencies = [
283 "generic-array",
284 "typenum",
285]
286
287[[package]]
210name = "darling" 288name = "darling"
211version = "0.14.4" 289version = "0.14.4"
212source = "registry+https://github.com/rust-lang/crates.io-index" 290source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -273,6 +351,22 @@ dependencies = [
273] 351]
274 352
275[[package]] 353[[package]]
354name = "deunicode"
355version = "0.4.3"
356source = "registry+https://github.com/rust-lang/crates.io-index"
357checksum = "850878694b7933ca4c9569d30a34b55031b9b139ee1fc7b94a527c4ef960d690"
358
359[[package]]
360name = "digest"
361version = "0.10.7"
362source = "registry+https://github.com/rust-lang/crates.io-index"
363checksum = "9ed9a281f7bc9b7576e61468ba615a66a5c8cfdff42420a70aa82701a3b1e292"
364dependencies = [
365 "block-buffer",
366 "crypto-common",
367]
368
369[[package]]
276name = "diligent-date-parser" 370name = "diligent-date-parser"
277version = "0.1.4" 371version = "0.1.4"
278source = "registry+https://github.com/rust-lang/crates.io-index" 372source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -390,6 +484,51 @@ dependencies = [
390] 484]
391 485
392[[package]] 486[[package]]
487name = "generic-array"
488version = "0.14.7"
489source = "registry+https://github.com/rust-lang/crates.io-index"
490checksum = "85649ca51fd72272d7821adaf274ad91c288277713d9c18820d8499a7ff69e9a"
491dependencies = [
492 "typenum",
493 "version_check",
494]
495
496[[package]]
497name = "getrandom"
498version = "0.2.10"
499source = "registry+https://github.com/rust-lang/crates.io-index"
500checksum = "be4136b2a15dd319360be1c07d9933517ccf0be8f16bf62a3bee4f0d618df427"
501dependencies = [
502 "cfg-if",
503 "libc",
504 "wasi 0.11.0+wasi-snapshot-preview1",
505]
506
507[[package]]
508name = "globset"
509version = "0.4.10"
510source = "registry+https://github.com/rust-lang/crates.io-index"
511checksum = "029d74589adefde59de1a0c4f4732695c32805624aec7b68d91503d4dba79afc"
512dependencies = [
513 "aho-corasick 0.7.20",
514 "bstr",
515 "fnv",
516 "log",
517 "regex",
518]
519
520[[package]]
521name = "globwalk"
522version = "0.8.1"
523source = "registry+https://github.com/rust-lang/crates.io-index"
524checksum = "93e3af942408868f6934a7b85134a3230832b9977cf66125df2f9edcfce4ddcc"
525dependencies = [
526 "bitflags",
527 "ignore",
528 "walkdir",
529]
530
531[[package]]
393name = "h2" 532name = "h2"
394version = "0.3.19" 533version = "0.3.19"
395source = "registry+https://github.com/rust-lang/crates.io-index" 534source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -470,6 +609,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
470checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421" 609checksum = "c4a1e36c821dbe04574f602848a19f742f4fb3c98d40449f11bcad18d6b17421"
471 610
472[[package]] 611[[package]]
612name = "humansize"
613version = "2.1.3"
614source = "registry+https://github.com/rust-lang/crates.io-index"
615checksum = "6cb51c9a029ddc91b07a787f1d86b53ccfa49b0e86688c946ebe8d3555685dd7"
616dependencies = [
617 "libm",
618]
619
620[[package]]
473name = "hyper" 621name = "hyper"
474version = "0.14.26" 622version = "0.14.26"
475source = "registry+https://github.com/rust-lang/crates.io-index" 623source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -546,6 +694,23 @@ dependencies = [
546] 694]
547 695
548[[package]] 696[[package]]
697name = "ignore"
698version = "0.4.20"
699source = "registry+https://github.com/rust-lang/crates.io-index"
700checksum = "dbe7873dab538a9a44ad79ede1faf5f30d49f9a5c883ddbab48bce81b64b7492"
701dependencies = [
702 "globset",
703 "lazy_static",
704 "log",
705 "memchr",
706 "regex",
707 "same-file",
708 "thread_local",
709 "walkdir",
710 "winapi-util",
711]
712
713[[package]]
549name = "indexmap" 714name = "indexmap"
550version = "1.9.3" 715version = "1.9.3"
551source = "registry+https://github.com/rust-lang/crates.io-index" 716source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -621,6 +786,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
621checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b" 786checksum = "f92be4933c13fd498862a9e02a3055f8a8d9c039ce33db97306fd5a6caa7f29b"
622 787
623[[package]] 788[[package]]
789name = "libm"
790version = "0.2.7"
791source = "registry+https://github.com/rust-lang/crates.io-index"
792checksum = "f7012b1bbb0719e1097c47611d3898568c546d597c2e74d66f6087edd5233ff4"
793
794[[package]]
624name = "linux-raw-sys" 795name = "linux-raw-sys"
625version = "0.3.8" 796version = "0.3.8"
626source = "registry+https://github.com/rust-lang/crates.io-index" 797source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -749,12 +920,104 @@ dependencies = [
749] 920]
750 921
751[[package]] 922[[package]]
923name = "parse-zoneinfo"
924version = "0.3.0"
925source = "registry+https://github.com/rust-lang/crates.io-index"
926checksum = "c705f256449c60da65e11ff6626e0c16a0a0b96aaa348de61376b249bc340f41"
927dependencies = [
928 "regex",
929]
930
931[[package]]
752name = "percent-encoding" 932name = "percent-encoding"
753version = "2.3.0" 933version = "2.3.0"
754source = "registry+https://github.com/rust-lang/crates.io-index" 934source = "registry+https://github.com/rust-lang/crates.io-index"
755checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94" 935checksum = "9b2a4787296e9989611394c33f193f676704af1686e70b8f8033ab5ba9a35a94"
756 936
757[[package]] 937[[package]]
938name = "pest"
939version = "2.7.0"
940source = "registry+https://github.com/rust-lang/crates.io-index"
941checksum = "f73935e4d55e2abf7f130186537b19e7a4abc886a0252380b59248af473a3fc9"
942dependencies = [
943 "thiserror",
944 "ucd-trie",
945]
946
947[[package]]
948name = "pest_derive"
949version = "2.7.0"
950source = "registry+https://github.com/rust-lang/crates.io-index"
951checksum = "aef623c9bbfa0eedf5a0efba11a5ee83209c326653ca31ff019bec3a95bfff2b"
952dependencies = [
953 "pest",
954 "pest_generator",
955]
956
957[[package]]
958name = "pest_generator"
959version = "2.7.0"
960source = "registry+https://github.com/rust-lang/crates.io-index"
961checksum = "b3e8cba4ec22bada7fc55ffe51e2deb6a0e0db2d0b7ab0b103acc80d2510c190"
962dependencies = [
963 "pest",
964 "pest_meta",
965 "proc-macro2",
966 "quote",
967 "syn 2.0.18",
968]
969
970[[package]]
971name = "pest_meta"
972version = "2.7.0"
973source = "registry+https://github.com/rust-lang/crates.io-index"
974checksum = "a01f71cb40bd8bb94232df14b946909e14660e33fc05db3e50ae2a82d7ea0ca0"
975dependencies = [
976 "once_cell",
977 "pest",
978 "sha2",
979]
980
981[[package]]
982name = "phf"
983version = "0.10.1"
984source = "registry+https://github.com/rust-lang/crates.io-index"
985checksum = "fabbf1ead8a5bcbc20f5f8b939ee3f5b0f6f281b6ad3468b84656b658b455259"
986dependencies = [
987 "phf_shared",
988]
989
990[[package]]
991name = "phf_codegen"
992version = "0.10.0"
993source = "registry+https://github.com/rust-lang/crates.io-index"
994checksum = "4fb1c3a8bc4dd4e5cfce29b44ffc14bedd2ee294559a294e2a4d4c9e9a6a13cd"
995dependencies = [
996 "phf_generator",
997 "phf_shared",
998]
999
1000[[package]]
1001name = "phf_generator"
1002version = "0.10.0"
1003source = "registry+https://github.com/rust-lang/crates.io-index"
1004checksum = "5d5285893bb5eb82e6aaf5d59ee909a06a16737a8970984dd7746ba9283498d6"
1005dependencies = [
1006 "phf_shared",
1007 "rand",
1008]
1009
1010[[package]]
1011name = "phf_shared"
1012version = "0.10.0"
1013source = "registry+https://github.com/rust-lang/crates.io-index"
1014checksum = "b6796ad771acdc0123d2a88dc428b5e38ef24456743ddb1744ed628f9815c096"
1015dependencies = [
1016 "siphasher",
1017 "uncased",
1018]
1019
1020[[package]]
758name = "pin-project-lite" 1021name = "pin-project-lite"
759version = "0.2.9" 1022version = "0.2.9"
760source = "registry+https://github.com/rust-lang/crates.io-index" 1023source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -773,6 +1036,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
773checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964" 1036checksum = "26072860ba924cbfa98ea39c8c19b4dd6a4a25423dbdf219c1eca91aa0cf6964"
774 1037
775[[package]] 1038[[package]]
1039name = "ppv-lite86"
1040version = "0.2.17"
1041source = "registry+https://github.com/rust-lang/crates.io-index"
1042checksum = "5b40af805b3121feab8a3c29f04d8ad262fa8e0561883e7653e024ae4479e6de"
1043
1044[[package]]
776name = "proc-macro2" 1045name = "proc-macro2"
777version = "1.0.60" 1046version = "1.0.60"
778source = "registry+https://github.com/rust-lang/crates.io-index" 1047source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -801,6 +1070,36 @@ dependencies = [
801] 1070]
802 1071
803[[package]] 1072[[package]]
1073name = "rand"
1074version = "0.8.5"
1075source = "registry+https://github.com/rust-lang/crates.io-index"
1076checksum = "34af8d1a0e25924bc5b7c43c079c942339d8f0a8b57c39049bef581b46327404"
1077dependencies = [
1078 "libc",
1079 "rand_chacha",
1080 "rand_core",
1081]
1082
1083[[package]]
1084name = "rand_chacha"
1085version = "0.3.1"
1086source = "registry+https://github.com/rust-lang/crates.io-index"
1087checksum = "e6c10a63a0fa32252be49d21e7709d4d4baf8d231c2dbce1eaa8141b9b127d88"
1088dependencies = [
1089 "ppv-lite86",
1090 "rand_core",
1091]
1092
1093[[package]]
1094name = "rand_core"
1095version = "0.6.4"
1096source = "registry+https://github.com/rust-lang/crates.io-index"
1097checksum = "ec0be4795e2f6a28069bec0b5ff3e2ac9bafc99e6a9a7dc3547996c5c816922c"
1098dependencies = [
1099 "getrandom",
1100]
1101
1102[[package]]
804name = "redox_syscall" 1103name = "redox_syscall"
805version = "0.3.5" 1104version = "0.3.5"
806source = "registry+https://github.com/rust-lang/crates.io-index" 1105source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -810,6 +1109,23 @@ dependencies = [
810] 1109]
811 1110
812[[package]] 1111[[package]]
1112name = "regex"
1113version = "1.8.4"
1114source = "registry+https://github.com/rust-lang/crates.io-index"
1115checksum = "d0ab3ca65655bb1e41f2a8c8cd662eb4fb035e67c3f78da1d61dffe89d07300f"
1116dependencies = [
1117 "aho-corasick 1.0.2",
1118 "memchr",
1119 "regex-syntax",
1120]
1121
1122[[package]]
1123name = "regex-syntax"
1124version = "0.7.2"
1125source = "registry+https://github.com/rust-lang/crates.io-index"
1126checksum = "436b050e76ed2903236f032a59761c1eb99e1b0aead2c257922771dab1fc8c78"
1127
1128[[package]]
813name = "reqwest" 1129name = "reqwest"
814version = "0.11.18" 1130version = "0.11.18"
815source = "registry+https://github.com/rust-lang/crates.io-index" 1131source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -853,8 +1169,10 @@ dependencies = [
853 "anyhow", 1169 "anyhow",
854 "chrono", 1170 "chrono",
855 "clap", 1171 "clap",
1172 "regex",
856 "reqwest", 1173 "reqwest",
857 "rss 2.0.4", 1174 "rss 2.0.4",
1175 "tera",
858 "tokio", 1176 "tokio",
859] 1177]
860 1178
@@ -868,6 +1186,7 @@ dependencies = [
868 "derive_builder", 1186 "derive_builder",
869 "never", 1187 "never",
870 "quick-xml", 1188 "quick-xml",
1189 "serde",
871] 1190]
872 1191
873[[package]] 1192[[package]]
@@ -891,6 +1210,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
891checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041" 1210checksum = "f91339c0467de62360649f8d3e185ca8de4224ff281f66000de5eb2a77a79041"
892 1211
893[[package]] 1212[[package]]
1213name = "same-file"
1214version = "1.0.6"
1215source = "registry+https://github.com/rust-lang/crates.io-index"
1216checksum = "93fc1dc3aaa9bfed95e02e6eadabb4baf7e3078b0bd1b4d7b6b0b68378900502"
1217dependencies = [
1218 "winapi-util",
1219]
1220
1221[[package]]
894name = "schannel" 1222name = "schannel"
895version = "0.1.21" 1223version = "0.1.21"
896source = "registry+https://github.com/rust-lang/crates.io-index" 1224source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -927,6 +1255,20 @@ name = "serde"
927version = "1.0.164" 1255version = "1.0.164"
928source = "registry+https://github.com/rust-lang/crates.io-index" 1256source = "registry+https://github.com/rust-lang/crates.io-index"
929checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d" 1257checksum = "9e8c8cf938e98f769bc164923b06dce91cea1751522f46f8466461af04c9027d"
1258dependencies = [
1259 "serde_derive",
1260]
1261
1262[[package]]
1263name = "serde_derive"
1264version = "1.0.164"
1265source = "registry+https://github.com/rust-lang/crates.io-index"
1266checksum = "d9735b638ccc51c28bf6914d90a2e9725b377144fc612c49a611fddd1b631d68"
1267dependencies = [
1268 "proc-macro2",
1269 "quote",
1270 "syn 2.0.18",
1271]
930 1272
931[[package]] 1273[[package]]
932name = "serde_json" 1274name = "serde_json"
@@ -952,6 +1294,23 @@ dependencies = [
952] 1294]
953 1295
954[[package]] 1296[[package]]
1297name = "sha2"
1298version = "0.10.7"
1299source = "registry+https://github.com/rust-lang/crates.io-index"
1300checksum = "479fb9d862239e610720565ca91403019f2f00410f1864c5aa7479b950a76ed8"
1301dependencies = [
1302 "cfg-if",
1303 "cpufeatures",
1304 "digest",
1305]
1306
1307[[package]]
1308name = "siphasher"
1309version = "0.3.10"
1310source = "registry+https://github.com/rust-lang/crates.io-index"
1311checksum = "7bd3e3206899af3f8b12af284fafc038cc1dc2b41d1b89dd17297221c5d225de"
1312
1313[[package]]
955name = "slab" 1314name = "slab"
956version = "0.4.8" 1315version = "0.4.8"
957source = "registry+https://github.com/rust-lang/crates.io-index" 1316source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -961,6 +1320,15 @@ dependencies = [
961] 1320]
962 1321
963[[package]] 1322[[package]]
1323name = "slug"
1324version = "0.1.4"
1325source = "registry+https://github.com/rust-lang/crates.io-index"
1326checksum = "b3bc762e6a4b6c6fcaade73e77f9ebc6991b676f88bb2358bddb56560f073373"
1327dependencies = [
1328 "deunicode",
1329]
1330
1331[[package]]
964name = "socket2" 1332name = "socket2"
965version = "0.4.9" 1333version = "0.4.9"
966source = "registry+https://github.com/rust-lang/crates.io-index" 1334source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1013,6 +1381,58 @@ dependencies = [
1013] 1381]
1014 1382
1015[[package]] 1383[[package]]
1384name = "tera"
1385version = "1.19.0"
1386source = "registry+https://github.com/rust-lang/crates.io-index"
1387checksum = "a5ab29bb4f3e256ae6ad5c3e2775aa1f8829f2c0c101fc407bfd3a6df15c60c5"
1388dependencies = [
1389 "chrono",
1390 "chrono-tz",
1391 "globwalk",
1392 "humansize",
1393 "lazy_static",
1394 "percent-encoding",
1395 "pest",
1396 "pest_derive",
1397 "rand",
1398 "regex",
1399 "serde",
1400 "serde_json",
1401 "slug",
1402 "thread_local",
1403 "unic-segment",
1404]
1405
1406[[package]]
1407name = "thiserror"
1408version = "1.0.40"
1409source = "registry+https://github.com/rust-lang/crates.io-index"
1410checksum = "978c9a314bd8dc99be594bc3c175faaa9794be04a5a5e153caba6915336cebac"
1411dependencies = [
1412 "thiserror-impl",
1413]
1414
1415[[package]]
1416name = "thiserror-impl"
1417version = "1.0.40"
1418source = "registry+https://github.com/rust-lang/crates.io-index"
1419checksum = "f9456a42c5b0d803c8cd86e73dd7cc9edd429499f37a3550d286d5e86720569f"
1420dependencies = [
1421 "proc-macro2",
1422 "quote",
1423 "syn 2.0.18",
1424]
1425
1426[[package]]
1427name = "thread_local"
1428version = "1.1.4"
1429source = "registry+https://github.com/rust-lang/crates.io-index"
1430checksum = "5516c27b78311c50bf42c071425c560ac799b11c30b31f87e3081965fe5e0180"
1431dependencies = [
1432 "once_cell",
1433]
1434
1435[[package]]
1016name = "time" 1436name = "time"
1017version = "0.1.45" 1437version = "0.1.45"
1018source = "registry+https://github.com/rust-lang/crates.io-index" 1438source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1123,6 +1543,77 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1123checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed" 1543checksum = "3528ecfd12c466c6f163363caf2d02a71161dd5e1cc6ae7b34207ea2d42d81ed"
1124 1544
1125[[package]] 1545[[package]]
1546name = "typenum"
1547version = "1.16.0"
1548source = "registry+https://github.com/rust-lang/crates.io-index"
1549checksum = "497961ef93d974e23eb6f433eb5fe1b7930b659f06d12dec6fc44a8f554c0bba"
1550
1551[[package]]
1552name = "ucd-trie"
1553version = "0.1.5"
1554source = "registry+https://github.com/rust-lang/crates.io-index"
1555checksum = "9e79c4d996edb816c91e4308506774452e55e95c3c9de07b6729e17e15a5ef81"
1556
1557[[package]]
1558name = "uncased"
1559version = "0.9.9"
1560source = "registry+https://github.com/rust-lang/crates.io-index"
1561checksum = "9b9bc53168a4be7402ab86c3aad243a84dd7381d09be0eddc81280c1da95ca68"
1562dependencies = [
1563 "version_check",
1564]
1565
1566[[package]]
1567name = "unic-char-property"
1568version = "0.9.0"
1569source = "registry+https://github.com/rust-lang/crates.io-index"
1570checksum = "a8c57a407d9b6fa02b4795eb81c5b6652060a15a7903ea981f3d723e6c0be221"
1571dependencies = [
1572 "unic-char-range",
1573]
1574
1575[[package]]
1576name = "unic-char-range"
1577version = "0.9.0"
1578source = "registry+https://github.com/rust-lang/crates.io-index"
1579checksum = "0398022d5f700414f6b899e10b8348231abf9173fa93144cbc1a43b9793c1fbc"
1580
1581[[package]]
1582name = "unic-common"
1583version = "0.9.0"
1584source = "registry+https://github.com/rust-lang/crates.io-index"
1585checksum = "80d7ff825a6a654ee85a63e80f92f054f904f21e7d12da4e22f9834a4aaa35bc"
1586
1587[[package]]
1588name = "unic-segment"
1589version = "0.9.0"
1590source = "registry+https://github.com/rust-lang/crates.io-index"
1591checksum = "e4ed5d26be57f84f176157270c112ef57b86debac9cd21daaabbe56db0f88f23"
1592dependencies = [
1593 "unic-ucd-segment",
1594]
1595
1596[[package]]
1597name = "unic-ucd-segment"
1598version = "0.9.0"
1599source = "registry+https://github.com/rust-lang/crates.io-index"
1600checksum = "2079c122a62205b421f499da10f3ee0f7697f012f55b675e002483c73ea34700"
1601dependencies = [
1602 "unic-char-property",
1603 "unic-char-range",
1604 "unic-ucd-version",
1605]
1606
1607[[package]]
1608name = "unic-ucd-version"
1609version = "0.9.0"
1610source = "registry+https://github.com/rust-lang/crates.io-index"
1611checksum = "96bd2f2237fe450fcd0a1d2f5f4e91711124f7857ba2e964247776ebeeb7b0c4"
1612dependencies = [
1613 "unic-common",
1614]
1615
1616[[package]]
1126name = "unicode-bidi" 1617name = "unicode-bidi"
1127version = "0.3.13" 1618version = "0.3.13"
1128source = "registry+https://github.com/rust-lang/crates.io-index" 1619source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1167,6 +1658,22 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1167checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426" 1658checksum = "accd4ea62f7bb7a82fe23066fb0957d48ef677f6eeb8215f372f52e48bb32426"
1168 1659
1169[[package]] 1660[[package]]
1661name = "version_check"
1662version = "0.9.4"
1663source = "registry+https://github.com/rust-lang/crates.io-index"
1664checksum = "49874b5167b65d7193b8aba1567f5c7d93d001cafc34600cee003eda787e483f"
1665
1666[[package]]
1667name = "walkdir"
1668version = "2.3.3"
1669source = "registry+https://github.com/rust-lang/crates.io-index"
1670checksum = "36df944cda56c7d8d8b7496af378e6b16de9284591917d307c9b4d313c44e698"
1671dependencies = [
1672 "same-file",
1673 "winapi-util",
1674]
1675
1676[[package]]
1170name = "want" 1677name = "want"
1171version = "0.3.0" 1678version = "0.3.0"
1172source = "registry+https://github.com/rust-lang/crates.io-index" 1679source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -1281,6 +1788,15 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
1281checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6" 1788checksum = "ac3b87c63620426dd9b991e5ce0329eff545bccbbb34f3be09ff6fb6ab51b7b6"
1282 1789
1283[[package]] 1790[[package]]
1791name = "winapi-util"
1792version = "0.1.5"
1793source = "registry+https://github.com/rust-lang/crates.io-index"
1794checksum = "70ec6ce85bb158151cae5e5c87f95a8e97d2c0c4b001223f33a334e3ce5de178"
1795dependencies = [
1796 "winapi",
1797]
1798
1799[[package]]
1284name = "winapi-x86_64-pc-windows-gnu" 1800name = "winapi-x86_64-pc-windows-gnu"
1285version = "0.4.0" 1801version = "0.4.0"
1286source = "registry+https://github.com/rust-lang/crates.io-index" 1802source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/Cargo.toml b/Cargo.toml
index 06007b2..f9be050 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -10,6 +10,8 @@ edition = "2021"
10anyhow = "1.0.71" 10anyhow = "1.0.71"
11chrono = "0.4.26" 11chrono = "0.4.26"
12clap = { version = "4.3.4", features = ["derive"] } 12clap = { version = "4.3.4", features = ["derive"] }
13regex = "1.8.4"
13reqwest = "0.11.18" 14reqwest = "0.11.18"
14rss = "2.0.4" 15rss = { version = "2.0.4", features = ["serde"] }
16tera = "1.19.0"
15tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] } 17tokio = { version = "1.28.2", features = ["macros", "rt-multi-thread"] }
diff --git a/src/filter.rs b/src/filter.rs
new file mode 100644
index 0000000..c1c00b1
--- /dev/null
+++ b/src/filter.rs
@@ -0,0 +1,82 @@
1use anyhow::{Result, Context};
2use rss::Channel;
3use regex::Regex;
4use chrono::{DateTime, Datelike, NaiveDate};
5
6pub fn run(c: Channel, regex: bool, invert_match: bool, url: Option<String>, title: Option<String>, date: Option<String>) -> Result<Channel> {
7 let invalid_date = NaiveDate::parse_from_str("1970-01-01", "%Y-%m-%d")?.and_hms_opt(0, 0, 0).unwrap();
8
9 let mut new_channel = c.clone();
10 let filter_date = match &date {
11 Some(date) => {
12 NaiveDate::parse_from_str(&date, "%Y-%m-%d").context("invalid date")?.and_hms_opt(0, 0, 0).unwrap()
13 },
14 None => {
15 invalid_date
16 }
17 };
18
19 new_channel.items = c.items.iter().filter(|&e| {
20 let mut url_ok = true;
21 if let Some(url) = &url {
22 match &e.link {
23 Some(link) => {
24 if !do_match(regex, link, url) {
25 url_ok = false;
26 }
27 },
28 None => {
29 url_ok = false;
30 }
31 }
32 }
33
34 let mut title_ok = true;
35 if let Some(title) = &title {
36 match &e.title {
37 Some(feed_title) => {
38 if !do_match(regex, feed_title, title) {
39 title_ok = false;
40 }
41 },
42 None => {
43 title_ok = false;
44 }
45 }
46 }
47
48 let mut date_ok = true;
49 if filter_date.timestamp() != invalid_date.timestamp() {
50 let pub_date = DateTime::parse_from_rfc2822(&e.pub_date.as_ref().unwrap()).unwrap();
51
52 if pub_date.year() != filter_date.year() || pub_date.month() != filter_date.month() || pub_date.day() != filter_date.day() {
53 date_ok = false;
54 }
55 }
56
57 let mut ok = url_ok && title_ok && date_ok;
58 if invert_match {
59 ok = !ok;
60 }
61
62 return ok;
63 }).cloned().collect();
64
65 Ok(new_channel)
66}
67
68fn do_match(is_regex: bool, haystack: &String, needle: &String) -> bool {
69 if is_regex {
70 return match_regex(haystack, needle);
71 }
72 return match_substr(haystack, needle);
73}
74
75fn match_substr(haystack: &String, needle: &String) -> bool {
76 return haystack.to_lowercase().contains(&needle.to_lowercase());
77}
78
79fn match_regex(haystack: &String, pattern: &String) -> bool {
80 let re = Regex::new(pattern).unwrap();
81 return re.is_match(haystack);
82} \ No newline at end of file
diff --git a/src/main.rs b/src/main.rs
index 1836aeb..7fa00f7 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -1,11 +1,13 @@
1use clap::{Subcommand, Parser, ValueEnum}; 1use clap::{Subcommand, Parser, ValueEnum};
2use rss::Channel; 2use rss::Channel;
3use tokio; 3use tokio;
4use std::process::exit; 4use std::{process::exit, io::Write};
5 5
6mod fetch; 6mod fetch;
7mod sort; 7mod sort;
8mod take; 8mod take;
9mod filter;
10mod render;
9 11
10#[derive(Parser)] 12#[derive(Parser)]
11struct Args { 13struct Args {
@@ -28,7 +30,34 @@ enum Commands {
28 }, 30 },
29 31
30 /// Gets the first N items 32 /// Gets the first N items
31 Take { n: usize } 33 Take { n: usize },
34
35 /// Filters a feed
36 Filter {
37 /// Treat filters as regexes instead of substrings
38 #[arg(short='E', long)]
39 regex: bool,
40
41 /// Only keep non-matching items
42 #[arg(short='v', long)]
43 invert_match: bool,
44
45 #[arg(short, long)]
46 url: Option<String>,
47
48 #[arg(short, long)]
49 title: Option<String>,
50
51 /// RFC-
52 #[arg(long)]
53 date: Option<String>
54 },
55
56 /// Renders a RSS feed using a Tera template
57 Render {
58 /// Path to the template file
59 template: String
60 }
32} 61}
33 62
34#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)] 63#[derive(Copy, Clone, PartialEq, Eq, PartialOrd, Ord, ValueEnum)]
@@ -80,7 +109,7 @@ async fn main() {
80 } 109 }
81 }, 110 },
82 Err(e) => { 111 Err(e) => {
83 eprintln!("Could not parse RSS: {:?}", e); 112 eprintln!("sort: could not parse RSS: {:?}", e);
84 exit(1); 113 exit(1);
85 } 114 }
86 } 115 }
@@ -94,13 +123,53 @@ async fn main() {
94 c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap(); 123 c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap();
95 }, 124 },
96 Err(e) => { 125 Err(e) => {
97 eprintln!("Error with 'sort': {:?}", e); 126 eprintln!("Error with 'take': {:?}", e);
127 exit(1);
128 }
129 }
130 },
131 Err(e) => {
132 eprintln!("take: could not parse RSS: {:?}", e);
133 exit(1);
134 }
135 }
136 },
137
138 Commands::Filter { regex, invert_match, url, title, date } => {
139 match Channel::read_from(std::io::stdin().lock()) {
140 Ok (c) => {
141 match filter::run(c, regex, invert_match, url, title, date) {
142 Ok(c) => {
143 c.pretty_write_to(std::io::stdout(), b' ', 2).unwrap();
144 },
145 Err(e) => {
146 eprintln!("Error with 'filter': {:?}", e);
147 exit(1);
148 }
149 }
150 },
151 Err(e) => {
152 eprintln!("filter: could not parse RSS: {:?}", e);
153 exit(1);
154 }
155 }
156 },
157
158 Commands::Render { template } => {
159 match Channel::read_from(std::io::stdin().lock()) {
160 Ok (c) => {
161 match render::run(c, template) {
162 Ok(t) => {
163 print!("{}", t);
164 },
165 Err(e) => {
166 eprintln!("Error with 'render': {:?}", e);
98 exit(1); 167 exit(1);
99 } 168 }
100 } 169 }
101 }, 170 },
102 Err(e) => { 171 Err(e) => {
103 eprintln!("Could not parse RSS: {:?}", e); 172 eprintln!("render: could not parse RSS: {:?}", e);
104 exit(1); 173 exit(1);
105 } 174 }
106 } 175 }
diff --git a/src/render.rs b/src/render.rs
new file mode 100644
index 0000000..dca941f
--- /dev/null
+++ b/src/render.rs
@@ -0,0 +1,15 @@
1use tera::{Tera, Context};
2use anyhow::Result;
3use rss::Channel;
4
5pub fn run(c: Channel, filename: String) -> Result<String> {
6 let mut tera = Tera::default();
7 let mut ctx = Context::new();
8
9 ctx.insert("items", c.items());
10
11 let file_contents = std::fs::read_to_string(filename)?;
12 tera.add_raw_template("template", &file_contents)?;
13
14 Ok(tera.render("template", &ctx)?)
15} \ No newline at end of file