Browse Source

serve: colorize sat+sun

master
Astro 10 months ago
parent
commit
72d4a34015
2 changed files with 55 additions and 41 deletions
  1. 46
    40
      ticker-serve/src/index.rs
  2. 9
    1
      ticker-serve/static/style.css

+ 46
- 40
ticker-serve/src/index.rs View File

@@ -1,3 +1,4 @@
1
+use std::convert::TryInto;
1 2
 use gotham::{
2 3
     helpers::http::response::create_response,
3 4
     hyper::{Body, Response},
@@ -6,7 +7,7 @@ use gotham::{
6 7
 use http::status::StatusCode;
7 8
 use mime::TEXT_HTML;
8 9
 
9
-use typed_html::{html, text, dom::DOMTree};
10
+use typed_html::{html, text, dom::DOMTree, types::{Class, SpacedSet}};
10 11
 use diesel::prelude::*;
11 12
 use chrono::{offset::Local, Datelike, NaiveDate};
12 13
 
@@ -73,47 +74,52 @@ fn render_index(app_state: &AppState) -> String {
73 74
           <link rel="stylesheet" title="Style" type="text/css" href="static/style.css"/>
74 75
         </head>
75 76
         <body>
76
-          { days.iter().map(|day| html!(<div>
77
-            <h2>
78
-              <span class="date">
79
-                <span class="day">
80
-                  { text!("{}", day.date.day()) }
81
-                </span>
82
-                <span class="month">
83
-                  { text!("{}", &config.months[day.date.month0() as usize]) }
84
-                </span>
85
-              </span>
86
-              <span class="weekday">
87
-                { text!("{}", &config.weekdays[day.date.weekday().num_days_from_monday() as usize]) }
88
-              </span>
89
-            </h2>
77
+          { days.iter().map(|day| {
78
+              let mut day_class: SpacedSet<Class> = ["date"].try_into().unwrap();
79
+              day_class.add(&format!("wd{}", day.date.weekday().num_days_from_monday())[..]);
80
+              html!(
81
+               <div>
82
+                 <h2>
83
+                   <span class={ day_class }>
84
+                     <span class="day">
85
+                       { text!("{}", day.date.day()) }
86
+                     </span>
87
+                     <span class="month">
88
+                       { text!("{}", &config.months[day.date.month0() as usize]) }
89
+                     </span>
90
+                   </span>
91
+                   <span class="weekday">
92
+                     { text!("{}", &config.weekdays[day.date.weekday().num_days_from_monday() as usize]) }
93
+                   </span>
94
+                 </h2>
90 95
 
91
-            { day.events.iter().map(|e| html!(
92
-                <article class="event" style={ format!("border-left: 1.5rem solid {}", &config.calendars.get(&e.calendar).map(|o| &o.color[..]).unwrap_or("white")) }>
93
-                  { match &e.url {
94
-                      None => html!(
95
-                        <h3>{ text!("{}", &e.summary) }</h3>
96
-                      ),
97
-                      Some(url) => html!(
98
-                        <h3>
99
-                          <a href={ fix_url(url) }>
100
-                            { text!("{}", &e.summary) }
101
-                          </a>
102
-                        </h3>
103
-                      ),
104
-                  } }
96
+                 { day.events.iter().map(|e| html!(
97
+                     <article class="event" style={ format!("border-left: 1.5rem solid {}", &config.calendars.get(&e.calendar).map(|o| &o.color[..]).unwrap_or("white")) }>
98
+                       { match &e.url {
99
+                           None => html!(
100
+                             <h3>{ text!("{}", &e.summary) }</h3>
101
+                           ),
102
+                           Some(url) => html!(
103
+                             <h3>
104
+                               <a href={ fix_url(url) }>
105
+                                 { text!("{}", &e.summary) }
106
+                               </a>
107
+                             </h3>
108
+                           ),
109
+                       } }
105 110
 
106
-                <p class="dtstart" title={ format!("{}", e.dtstart.format("%c")) }>
107
-                  { text!("{}", &e.dtstart.format("%H:%S")) }
108
-                </p>
109
-                { e.location.as_ref().map(|location| html!(
110
-                  <p class="location">
111
-                    { text!("{}", location) }
112
-                    </p>
113
-                )) }
114
-              </article>
115
-            )) }
116
-          </div>)) }
111
+                     <p class="dtstart" title={ format!("{}", e.dtstart.format("%c")) }>
112
+                       { text!("{}", &e.dtstart.format("%H:%S")) }
113
+                     </p>
114
+                     { e.location.as_ref().map(|location| html!(
115
+                       <p class="location">
116
+                         { text!("{}", location) }
117
+                         </p>
118
+                     )) }
119
+                   </article>
120
+                 )) }
121
+           </div>)
122
+          }) }
117 123
         </body>
118 124
       </html>
119 125
     );

+ 9
- 1
ticker-serve/static/style.css View File

@@ -23,6 +23,14 @@ h2 {
23 23
     text-align: center;
24 24
     width: 4rem;
25 25
 }
26
+/* saturday */
27
+.date.wd5 {
28
+    color: #999;
29
+}
30
+/* sunday */
31
+.date.wd6 {
32
+    color: #d33;
33
+}
26 34
 .date .day {
27 35
     align-self: center;
28 36
     font-size: 140%;
@@ -40,7 +48,7 @@ article {
40 48
     background-color: #f7f7f7;
41 49
     color: #222;
42 50
     margin: 0;
43
-    padding: 0.5rem 0 0.5rem 1rem;
51
+    padding: 0.8rem 0 0.8rem 1rem;
44 52
     clear: both;
45 53
     line-height: 1.3rem;
46 54
     /*box-shadow: 0 -0.3rem 0.5rem 0.5rem #373737;*/

Loading…
Cancel
Save