Browse Source

Move CSS/JS to separate files

master
Dylan Baker 3 years ago
parent
commit
cec01575e0
4 changed files with 184 additions and 186 deletions
  1. 2
    0
      src/main.rs
  2. 16
    0
      static/script.js
  3. 161
    0
      static/style.css
  4. 5
    186
      templates/layout.html

+ 2
- 0
src/main.rs View File

@@ -24,6 +24,8 @@ async fn main() -> std::io::Result<()> {
24 24
         login_path: login_path.clone(),
25 25
     });
26 26
 
27
+    app.at("/static").serve_dir("static")?;
28
+
27 29
     app.with(After(errors));
28 30
     app.with(session());
29 31
 

+ 16
- 0
static/script.js View File

@@ -0,0 +1,16 @@
1
+document.querySelectorAll('[data-delete]').forEach((el) => {
2
+  el.addEventListener('click', (e) => {
3
+    if (confirm('Are you sure? This cannot be undone.')) {
4
+      let postId = e.target.dataset.delete;
5
+      fetch(`/posts/${postId}`, {
6
+        method: 'DELETE',
7
+      }).then((r) => {
8
+        r.json().then((data) => {
9
+          if (data.success) {
10
+            window.location = '/';
11
+          }
12
+        });
13
+      });
14
+    }
15
+  });
16
+});

+ 161
- 0
static/style.css View File

@@ -0,0 +1,161 @@
1
+* {
2
+  box-sizing: border-box;
3
+  margin: 0;
4
+  padding: 0;
5
+}
6
+
7
+body {
8
+  background: #aab5a9;
9
+  color: #000;
10
+  font-family: Verdana, Geneva, Tahoma, sans-serif;
11
+  font-size: 12px;
12
+}
13
+
14
+a {
15
+  color: #000;
16
+}
17
+
18
+a:hover {
19
+  text-decoration: none;
20
+}
21
+
22
+.btn {
23
+  cursor: pointer;
24
+  background: #ffffff;
25
+  border: 1px solid #383e37;
26
+  border-radius: 0;
27
+  padding: 0.15em 0.3em;
28
+}
29
+
30
+.btn:hover {
31
+  background-color: #f0f0f0;
32
+}
33
+
34
+.danger {
35
+  color: #942626;
36
+}
37
+
38
+.container {
39
+  margin: auto;
40
+  max-width: 800px;
41
+  padding: 1em;
42
+}
43
+
44
+.header {
45
+  align-items: center;
46
+  display: flex;
47
+  justify-content: space-between;
48
+  margin: 1em 0;
49
+}
50
+
51
+.header__logo {
52
+  background-color: #ffffff;
53
+  border: 1px solid #383e37;
54
+  font-size: 14px;
55
+  font-style: italic;
56
+  font-weight: bold;
57
+  letter-spacing: 2px;
58
+  padding: 0.25em 0.5em;
59
+  text-decoration: none;
60
+}
61
+
62
+.header__logo:hover {
63
+  background-color: #f0f0f0;
64
+}
65
+
66
+.form__field {
67
+  margin: 1em 0;
68
+}
69
+
70
+.form__label {
71
+  display: block;
72
+  margin-bottom: 0.5em;
73
+}
74
+
75
+.form__textarea,
76
+.form__text-field {
77
+  font-family: Verdana, Geneva, Tahoma, sans-serif;
78
+  font-size: 12px;
79
+  padding: 0.25em;
80
+  width: 100%;
81
+}
82
+
83
+.form__textarea {
84
+  height: 200px;
85
+  resize: vertical;
86
+}
87
+
88
+.post:not(:last-child) {
89
+  margin: 3em 0;
90
+}
91
+
92
+.post__heading {
93
+  align-items: center;
94
+  background: white;
95
+  border: 1px solid #383e37;
96
+  display: flex;
97
+  flex-wrap: wrap;
98
+  font-size: 12px;
99
+  font-weight: bold;
100
+  justify-content: space-between;
101
+  margin-bottom: 1em;
102
+  padding: 0.5em;
103
+}
104
+
105
+.post__title {
106
+  flex: 1;
107
+  margin-right: 1em;
108
+  min-width: 220px;
109
+}
110
+
111
+.post__date {
112
+  font-style: italic;
113
+  white-space: nowrap;
114
+}
115
+
116
+.post__link {
117
+  cursor: pointer;
118
+  font-style: normal;
119
+  font-weight: normal;
120
+  text-decoration: underline;
121
+}
122
+
123
+.post__link:hover {
124
+  text-decoration: none;
125
+}
126
+
127
+.post__body {
128
+  border-top: none;
129
+  padding: 0.5em;
130
+}
131
+
132
+.message {
133
+  border: 1px solid #383e37;
134
+  color: #fff;
135
+  margin: 0.5em 0;
136
+  padding: 0.25em 1.5em;
137
+  text-align: center;
138
+  width: 100%;
139
+}
140
+
141
+.message--error {
142
+  background-color: #942626;
143
+}
144
+
145
+.message--success {
146
+  background-color: #289426;
147
+}
148
+
149
+.error__heading {
150
+  margin: 2em 0 1em;
151
+}
152
+
153
+.error__message {
154
+  font-size: 18px;
155
+}
156
+
157
+@media (max-width: 500px) {
158
+  .form__button {
159
+    width: 100%;
160
+  }
161
+}

+ 5
- 186
templates/layout.html View File

@@ -5,169 +5,7 @@
5 5
     <meta charset="UTF-8" />
6 6
     <meta name="viewport" content="width=device-width, initial-scale=1.0" />
7 7
     <title>bngl://ws/</title>
8
-    <style>
9
-      * {
10
-        box-sizing: border-box;
11
-        margin: 0;
12
-        padding: 0;
13
-      }
14
-
15
-      body {
16
-        background: #aab5a9;
17
-        color: #000;
18
-        font-family: Verdana, Geneva, Tahoma, sans-serif;
19
-        font-size: 12px;
20
-      }
21
-
22
-      a {
23
-        color: #000;
24
-      }
25
-
26
-      a:hover {
27
-        text-decoration: none;
28
-      }
29
-
30
-      .btn {
31
-        cursor: pointer;
32
-        background: #ffffff;
33
-        border: 1px solid #383e37;
34
-        border-radius: 0;
35
-        padding: 0.15em 0.3em;
36
-      }
37
-
38
-      .btn:hover {
39
-        background-color: #f0f0f0;
40
-      }
41
-
42
-      .danger {
43
-        color: #942626;
44
-      }
45
-
46
-      .container {
47
-        margin: auto;
48
-        max-width: 800px;
49
-        padding: 1em;
50
-      }
51
-
52
-      .header {
53
-        align-items: center;
54
-        display: flex;
55
-        justify-content: space-between;
56
-        margin: 1em 0;
57
-      }
58
-
59
-      .header__logo {
60
-        background-color: #ffffff;
61
-        border: 1px solid #383e37;
62
-        font-size: 14px;
63
-        font-style: italic;
64
-        font-weight: bold;
65
-        letter-spacing: 2px;
66
-        padding: 0.25em 0.5em;
67
-        text-decoration: none;
68
-      }
69
-
70
-      .header__logo:hover {
71
-        background-color: #f0f0f0;
72
-      }
73
-
74
-      .form__field {
75
-        margin: 1em 0;
76
-      }
77
-
78
-      .form__label {
79
-        display: block;
80
-        margin-bottom: 0.5em;
81
-      }
82
-
83
-      .form__textarea,
84
-      .form__text-field {
85
-        font-family: Verdana, Geneva, Tahoma, sans-serif;
86
-        font-size: 12px;
87
-        padding: 0.25em;
88
-        width: 100%;
89
-      }
90
-
91
-      .form__textarea {
92
-        height: 200px;
93
-        resize: vertical;
94
-      }
95
-
96
-      .post:not(:last-child) {
97
-        margin: 3em 0;
98
-      }
99
-
100
-      .post__heading {
101
-        align-items: center;
102
-        background: white;
103
-        border: 1px solid #383e37;
104
-        display: flex;
105
-        flex-wrap: wrap;
106
-        font-size: 12px;
107
-        font-weight: bold;
108
-        justify-content: space-between;
109
-        margin-bottom: 1em;
110
-        padding: 0.5em;
111
-      }
112
-
113
-      .post__title {
114
-        flex: 1;
115
-        margin-right: 1em;
116
-        min-width: 220px;
117
-      }
118
-
119
-      .post__date {
120
-        font-style: italic;
121
-        white-space: nowrap;
122
-      }
123
-
124
-      .post__link {
125
-        cursor: pointer;
126
-        font-style: normal;
127
-        font-weight: normal;
128
-        text-decoration: underline;
129
-      }
130
-
131
-      .post__link:hover {
132
-        text-decoration: none;
133
-      }
134
-
135
-      .post__body {
136
-        border-top: none;
137
-        padding: 0.5em;
138
-      }
139
-
140
-      .message {
141
-        border: 1px solid #383e37;
142
-        color: #fff;
143
-        margin: .5em 0;
144
-        padding: .25em 1.5em;
145
-        text-align: center;
146
-        width: 100%;
147
-      }
148
-
149
-      .message--error {
150
-        background-color: #942626;
151
-      }
152
-
153
-      .message--success {
154
-        background-color: #289426;
155
-      }
156
-
157
-      .error__heading {
158
-        margin: 2em 0 1em;
159
-      }
160
-
161
-      .error__message {
162
-        font-size: 18px;
163
-      }
164
-
165
-      @media (max-width: 500px) {
166
-        .form__button {
167
-          width: 100%;
168
-        }
169
-      }
170
-    </style>
8
+    <link rel="stylesheet" href="/static/style.css" />
171 9
   </head>
172 10
   <body>
173 11
     <div class="container">
@@ -181,32 +19,13 @@
181 19
       </header>
182 20
       <div class="messages">
183 21
         {% if flash_error %}
184
-          <p class="message message--error">{{ flash_error }}</p>
185
-        {% endif %}
186
-
187
-        {% if flash_success %}
188
-          <p class="message message--success">{{ flash_success }}</p>
22
+        <p class="message message--error">{{ flash_error }}</p>
23
+        {% endif %} {% if flash_success %}
24
+        <p class="message message--success">{{ flash_success }}</p>
189 25
         {% endif %}
190 26
       </div>
191 27
       {% block content %} {% endblock %}
192 28
     </div>
193
-    <script>
194
-      document.querySelectorAll('[data-delete]').forEach((el) => {
195
-        el.addEventListener('click', (e) => {
196
-          if (confirm('Are you sure? This cannot be undone.')) {
197
-            let postId = e.target.dataset.delete;
198
-            fetch(`/posts/${postId}`, {
199
-              method: 'DELETE',
200
-            }).then((r) => {
201
-              r.json().then((data) => {
202
-                if (data.success) {
203
-                  window.location = '/';
204
-                }
205
-              });
206
-            });
207
-          }
208
-        });
209
-      });
210
-    </script>
29
+    <script src="/static/script.js"></script>
211 30
   </body>
212 31
 </html>

Loading…
Cancel
Save