Przeglądaj źródła

Add fields for image (as content) and soundtrack

master
The Dod 1 rok temu
rodzic
commit
48c2eb2dff
5 zmienionych plików z 126 dodań i 17 usunięć
  1. 22
    8
      app.py
  2. 2
    2
      static/css/style.css
  3. 32
    6
      static/slides.json
  4. 69
    0
      static/slides.schema.json
  5. 1
    1
      templates/slides.html

+ 22
- 8
app.py Wyświetl plik

@@ -13,21 +13,35 @@ RE_VID = re.compile("""\[video ["']([^['"]*?)["']\]""")
13 13
 TEMPLATE_VID = """<video controls><source src="{}" type="video/{}"></video>"""
14 14
 
15 15
 RE_SOUNDTRACK = re.compile("""\[soundtrack ["']([^['"]*?)["']\]""")
16
-TEMPLATE_SOUNDTRACK = """<audio data-autoplay><source src="{}" type="audio/{}"></audio>"""
16
+TEMPLATE_SOUNDTRACK = """<audio loop data-autoplay><source src="{}" type="audio/{}"></audio>"""
17 17
 
18
-def preprocess_markdown(md):
18
+def preprocess_content(defs):
19
+    md = defs.get("markdown", "")
19 20
     if md:
20 21
         content = markdown(md)
21 22
         content = RE_VID.sub(lambda m: TEMPLATE_VID.format(m.group(1), m.group(1).split('.')[-1]), content)
22
-        content = RE_SOUNDTRACK.sub(lambda m: TEMPLATE_SOUNDTRACK.format(m.group(1), m.group(1).split('.')[-1]), content)
23
-        return content
24
-    return ""
23
+    else:
24
+        content = ""
25
+    img = defs.get("image", {})
26
+    match img.get("placement", "none"):
27
+        case "above":
28
+            content = """<img src="{source}" alt="{alt}" class="centered w-{width}"/><br/>\n""".format(**img)+content
29
+        case "left":
30
+            content = """<img src="{source}" alt="{alt}" class="float-left w-{width}"/><br/>\n""".format(**img)+content
31
+        case "right":
32
+            content = """<img src="{source}" alt="{alt}" class="float-right w-{width}"/><br/>\n""".format(**img)+content
33
+        case "below":
34
+            content = content+"""<br/>\n<img src="{source}" alt="{alt}" class="centered w-{width}"/><br/>\n""".format(**img)
35
+    if defs.get('soundtrack'):
36
+        content = """<audio loop data-autoplay><source src="{}" type="audio/{}"></audio>\n""".format(
37
+                      defs["soundtrack"], defs["soundtrack"].split(".")[-1])+content
38
+    return content
25 39
 
26 40
 def preprocess_payload(payload):
27 41
     for column in payload.get("columns", []):
28
-        column["content"] = preprocess_markdown(column.get("markdown"))
42
+        column["content"] = preprocess_content(column)
29 43
         for slide in column.get("slides", []):
30
-            slide["content"] = preprocess_markdown(slide.get("markdown"))
44
+            slide["content"] = preprocess_content(slide)
31 45
 
32 46
 load_dotenv()
33 47
 
@@ -54,7 +68,7 @@ def update():
54 68
 
55 69
 @application.get("/enum/<topic>")
56 70
 def choices(topic):
57
-    if topic in ["img", "bg", "bg-video"]:
71
+    if topic in ["img", "bg", "bg-video", "audio"]:
58 72
         return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
59 73
     abort(404)
60 74
 

+ 2
- 2
static/css/style.css Wyświetl plik

@@ -56,12 +56,12 @@
56 56
 
57 57
 .float-left {
58 58
 	float: left;
59
-	margin-right: 1em;
59
+	margin-right: 1em !important;
60 60
 }
61 61
 
62 62
 .float-right {
63 63
 	float: right;
64
-	margin-left: 1em;
64
+	margin-left: 1em !important;
65 65
 }
66 66
 
67 67
 .centered {

+ 32
- 6
static/slides.json Wyświetl plik

@@ -25,7 +25,8 @@
25 25
                 "background-video-mute": true,
26 26
                 "background-opacity": "0.75"
27 27
             },
28
-            "markdown": "I've done many things. Some of them I'm proud of: [soundtrack \"static/audio/VJ_Memes_-_funkyGarden.mp3\"]",
28
+            "markdown": "I've done many things. Some of them I'm proud of:",
29
+            "soundtrack": "static/audio/VJ_Memes_-_funkyGarden.mp3",
29 30
             "slides": [
30 31
                 {
31 32
                     "id": "work",
@@ -34,7 +35,13 @@
34 35
                         "background-image": "static/bg/valley-1.svg",
35 36
                         "background-opacity": "0.25"
36 37
                     },
37
-                    "markdown": "### I've worked like a horse.\n\n![A horse (of course)|w-50 centered](static/img/horse.png)"
38
+                    "image": {
39
+                        "placement": "below",
40
+                        "width": "50",
41
+                        "source": "static/img/horse.png",
42
+                        "alt": "A horse (of course)"
43
+                    },
44
+                    "markdown": "### I've worked like a horse."
38 45
                 },
39 46
                 {
40 47
                     "id": "rest",
@@ -44,7 +51,13 @@
44 51
                         "background-opacity": "0.5",
45 52
                         "background-size": "contain"
46 53
                     },
47
-                    "markdown": "#### I've rested like a cat.\n\n![A cat resting|w-66 centered](static/img/cat-resting.png)"
54
+                    "image": {
55
+                        "placement": "above",
56
+                        "width": "50",
57
+                        "source": "static/img/cat-resting.png",
58
+                        "alt": "A cat resting"
59
+                    },
60
+                    "markdown": "#### I've rested like a cat."
48 61
                 }
49 62
             ]
50 63
         },
@@ -64,7 +77,13 @@
64 77
                     "id": "horse",
65 78
                     "title": "My horse",
66 79
                     "params": {},
67
-                    "markdown": "![My horse|w-50 float-right](static/img/horse2.png)\n\nPlease forgive me, horse, for this and that."
80
+                    "image": {
81
+                        "placement": "right",
82
+                        "width": "66",
83
+                        "source": "static/img/horse2.png",
84
+                        "alt": "A different horse"
85
+                    },
86
+                    "markdown": "Please forgive me, horse, for this and that."
68 87
                 },
69 88
                 {
70 89
                     "id": "cat",
@@ -72,9 +91,16 @@
72 91
                     "params": {
73 92
                         "background-size": "contain"
74 93
                     },
75
-                    "markdown": "![My cat|w-50 float-left](static/img/cat-resting.png)\n\nPlease forgive me, cat, for that and this"
94
+                    "image": {
95
+                        "placement": "left",
96
+                        "width": "33",
97
+                        "source": "static/img/cat-resting.png",
98
+                        "alt": "A cat resting to the left of the text"
99
+                    },
100
+                    "markdown": "Please forgive me, cat, for that and this."
76 101
                 }
77
-            ]
102
+            ],
103
+            "soundtrack": "static/audio/sonar.wav"
78 104
         }
79 105
     ]
80 106
 }

+ 69
- 0
static/slides.schema.json Wyświetl plik

@@ -14,6 +14,7 @@
14 14
       "items": {
15 15
         "type": "object",
16 16
         "title": "Chapter",
17
+        "headerTemplate": "{{title}}: {{self.title}}",
17 18
         "properties": {
18 19
           "id": {
19 20
             "type": "string"
@@ -24,9 +25,15 @@
24 25
           "params": {
25 26
             "$ref": "#/definitions/params"
26 27
           },
28
+          "image": {
29
+            "$ref": "#/definitions/image"
30
+          },
27 31
           "markdown": {
28 32
             "$ref": "#/definitions/markdown"
29 33
           },
34
+          "soundtrack": {
35
+            "$ref": "#/definitions/soundtrack"
36
+          },
30 37
           "slides": {
31 38
             "type": "array",
32 39
             "title": "Pages",
@@ -36,6 +43,7 @@
36 43
             "items": {
37 44
               "type": "object",
38 45
               "title": "Page",
46
+              "headerTemplate": "{{title}}: {{self.title}}",
39 47
               "properties": {
40 48
                 "id": {
41 49
                   "type": "string"
@@ -46,8 +54,14 @@
46 54
                 "params": {
47 55
                   "$ref": "#/definitions/params"
48 56
                 },
57
+                "image": {
58
+                  "$ref": "#/definitions/image"
59
+                },
49 60
                 "markdown": {
50 61
                   "$ref": "#/definitions/markdown"
62
+                },
63
+                "soundtrack": {
64
+                  "$ref": "#/definitions/soundtrack"
51 65
                 }
52 66
               },
53 67
               "required": [
@@ -117,10 +131,12 @@
117 131
         },
118 132
         "background-video-loop": {
119 133
             "type": "boolean",
134
+            "format": "checkbox",
120 135
             "default": true
121 136
         },
122 137
         "background-video-mute": {
123 138
             "type": "boolean",
139
+            "format": "checkbox",
124 140
             "default": true
125 141
         },
126 142
         "background-opacity": {
@@ -145,6 +161,59 @@
145 161
         }
146 162
       }
147 163
     },
164
+    "image": {
165
+      "type": "object",
166
+      "title": "Image",
167
+      "options": {
168
+        "collapsed": "true"
169
+      },
170
+      "properties": {
171
+        "placement": {
172
+          "type": "string",
173
+          "title": "Placement",
174
+          "enum": [
175
+            "none",
176
+            "above",
177
+            "left",
178
+            "right",
179
+            "below"
180
+          ],
181
+          "default": "none"
182
+        },
183
+        "width": {
184
+          "type": "string",
185
+          "title": "Width (percent)",
186
+          "enum": [
187
+            "25",
188
+            "33",
189
+            "50",
190
+            "66",
191
+            "75"
192
+          ],
193
+          "default": "50"
194
+        },
195
+        "source": {
196
+          "$ref": "/enum/img",
197
+          "title": "Image",
198
+          "links": [
199
+            {
200
+              "rel": "Preview image",
201
+              "class": "link-info",
202
+              "href": "{{self}}"
203
+            }
204
+          ]
205
+        },
206
+        "alt": {
207
+            "type": "string",
208
+            "title": "Description"
209
+        }
210
+      }
211
+    },
212
+    "soundtrack": {
213
+      "type": "string",
214
+      "title": "Soundtrack",
215
+      "$ref": "/enum/audio"
216
+    },
148 217
     "markdown": {
149 218
       "type": "string",
150 219
       "title": "Content",

+ 1
- 1
templates/slides.html Wyświetl plik

@@ -76,7 +76,7 @@
76 76
 			// - https://revealjs.com/config/
77 77
 			Reveal.initialize({
78 78
 				hash: true,
79
-                                // controlsTutorial: false,
79
+                                progress: false,
80 80
                                 transition: 'convex',
81 81
                                 controlsBackArrows: 'visible',  // would hopefully solve the faded-arrow thing
82 82
                                 // slideNumber: "h.v",

Ładowanie…
Anuluj
Zapisz