@@ -25,6 +25,8 @@ use tokio::sync::Mutex;
25
25
26
26
const TEMPLATE : & str = include_str ! ( "../static/index.html" ) ;
27
27
const PICO_CSS : & str = include_str ! ( "../static/pico.min.css" ) ;
28
+ const AA_PROXY_RS_URL : & str = "https://github.com/aa-proxy/aa-proxy-rs" ;
29
+ const BUILDROOT_URL : & str = "https://github.com/aa-proxy/buildroot" ;
28
30
29
31
// module name for logging engine
30
32
const NAME : & str = "<i><bright-black> web: </>" ;
@@ -48,11 +50,51 @@ pub fn app(state: Arc<AppState>) -> Router {
48
50
. with_state ( state)
49
51
}
50
52
53
+ fn linkify_git_info ( git_date : & str , git_hash : & str ) -> String {
54
+ // check if git_date is really a YYYYMMDD date
55
+ let is_date = git_date. len ( ) == 8 && git_date. chars ( ) . all ( |c| c. is_ascii_digit ( ) ) ;
56
+
57
+ if is_date {
58
+ let clean_hash = git_hash. trim_end_matches ( "-dirty" ) ;
59
+ let url = format ! (
60
+ "<a href=\" {}/commit/{}\" target=\" _blank\" >{}</a>{}" ,
61
+ AA_PROXY_RS_URL ,
62
+ clean_hash,
63
+ clean_hash,
64
+ {
65
+ if clean_hash == git_hash {
66
+ ""
67
+ } else {
68
+ "-dirty"
69
+ }
70
+ }
71
+ ) ;
72
+ format ! ( "{}-{}" , git_date, url)
73
+ } else if git_hash. starts_with ( "br#" ) {
74
+ let url_aaproxy = format ! (
75
+ "<a href=\" {}/commit/{}\" target=\" _blank\" >{}</a>" ,
76
+ AA_PROXY_RS_URL , git_date, git_date,
77
+ ) ;
78
+
79
+ let clean_hash = git_date. trim_start_matches ( "br#" ) ;
80
+ let url_br = format ! (
81
+ "br#<a href=\" {}/commit/{}\" target=\" _blank\" >{}</a>" ,
82
+ BUILDROOT_URL , clean_hash, clean_hash,
83
+ ) ;
84
+ format ! ( "{}-{}" , url_aaproxy, url_br)
85
+ } else {
86
+ // format not recognized, use without links
87
+ format ! ( "{}-{}" , git_date, git_hash)
88
+ }
89
+ }
90
+
51
91
async fn index ( ) -> impl IntoResponse {
52
92
let html = TEMPLATE
53
93
. replace ( "{BUILD_DATE}" , env ! ( "BUILD_DATE" ) )
54
- . replace ( "{GIT_DATE}" , env ! ( "GIT_DATE" ) )
55
- . replace ( "{GIT_HASH}" , env ! ( "GIT_HASH" ) )
94
+ . replace (
95
+ "{GIT_INFO}" ,
96
+ & linkify_git_info ( env ! ( "GIT_DATE" ) , env ! ( "GIT_HASH" ) ) ,
97
+ )
56
98
. replace ( "{PICO_CSS}" , PICO_CSS ) ;
57
99
Html ( html)
58
100
}
0 commit comments