Przeglądaj źródła

Support Markdown in list description

Gildas Chabot 4 lat temu
rodzic
commit
cb217b24e3
3 zmienionych plików z 12 dodań i 13 usunięć
  1. 9 10
      pages/pages.go
  2. 0 1
      templates/home.html
  3. 3 2
      templates/list.html

+ 9 - 10
pages/pages.go

@@ -9,6 +9,7 @@ import (
9
 
9
 
10
 	"gogs.gildas.ch/gildas/movies"
10
 	"gogs.gildas.ch/gildas/movies"
11
 	"gogs.gildas.ch/gildas/movies/omdb"
11
 	"gogs.gildas.ch/gildas/movies/omdb"
12
+	"gopkg.in/russross/blackfriday.v2"
12
 )
13
 )
13
 
14
 
14
 func Router(c *movies.Collection) http.HandlerFunc {
15
 func Router(c *movies.Collection) http.HandlerFunc {
@@ -156,15 +157,9 @@ func List(c *movies.Collection) http.HandlerFunc {
156
 		}
157
 		}
157
 
158
 
158
 		if r.Method == "POST" {
159
 		if r.Method == "POST" {
159
-			updated, err := movies.UnmarshalList([]byte(r.FormValue("list_json")))
160
-			if err != nil {
161
-				errs = append(errs, err)
162
-			} else if listID != updated.ID {
163
-				errs = append(errs, fmt.Errorf("you cannot change the imdb id."))
164
-			} else {
165
-				l = updated
166
-				c.UpdateList(updated)
167
-			}
160
+			l.Title = r.FormValue("title")
161
+			l.Description = r.FormValue("description")
162
+			c.UpdateList(l)
168
 		}
163
 		}
169
 
164
 
170
 		b, err := json.MarshalIndent(l, "", "  ")
165
 		b, err := json.MarshalIndent(l, "", "  ")
@@ -173,7 +168,11 @@ func List(c *movies.Collection) http.HandlerFunc {
173
 		}
168
 		}
174
 
169
 
175
 		t.Execute(w, map[string]interface{}{
170
 		t.Execute(w, map[string]interface{}{
176
-			"List":     l,
171
+			"List": l,
172
+			"Description": template.HTML(
173
+				blackfriday.Run(
174
+					[]byte(strings.ReplaceAll(l.Description, "\r\n", "\n")),
175
+					blackfriday.WithExtensions(blackfriday.CommonExtensions))),
177
 			"ListJSON": string(b),
176
 			"ListJSON": string(b),
178
 			"Errors":   errs,
177
 			"Errors":   errs,
179
 		})
178
 		})

+ 0 - 1
templates/home.html

@@ -40,7 +40,6 @@
40
             <a href="/l/{{ $l.ID }}">
40
             <a href="/l/{{ $l.ID }}">
41
                 <li class="list">
41
                 <li class="list">
42
                     <h3>{{ $l.Title }} ({{ $l.ID }})</h3>
42
                     <h3>{{ $l.Title }} ({{ $l.ID }})</h3>
43
-                    <p>{{ $l.Description }}</p>
44
                 </li>
43
                 </li>
45
             </a>
44
             </a>
46
             {{ end }}
45
             {{ end }}

+ 3 - 2
templates/list.html

@@ -12,11 +12,12 @@
12
 
12
 
13
         <h1>{{ .List.Title }}</h1>
13
         <h1>{{ .List.Title }}</h1>
14
 
14
 
15
-        <p>{{ .List.Description }}</p>
15
+        {{ .Description }}
16
 
16
 
17
         <form method="post">
17
         <form method="post">
18
             <p>Update list: <input type="submit" /><br />
18
             <p>Update list: <input type="submit" /><br />
19
-                <textarea name="list_json" style="width:90%;height:500px;">{{ .ListJSON }}</textarea>
19
+                <input type="text" name="title" value="{{ .List.Title }}" /><br />
20
+                <textarea name="description" style="width:90%;height:500px;">{{ .List.Description }}</textarea>
20
             </p>
21
             </p>
21
         </form>
22
         </form>
22
     </body>
23
     </body>