Browse Source

Add fields for image (as content) and soundtrack

master
The Dod 1 year ago
parent
commit
48c2eb2dff
5 changed files with 126 additions and 17 deletions
  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 View File

13
 TEMPLATE_VID = """<video controls><source src="{}" type="video/{}"></video>"""
13
 TEMPLATE_VID = """<video controls><source src="{}" type="video/{}"></video>"""
14
 
14
 
15
 RE_SOUNDTRACK = re.compile("""\[soundtrack ["']([^['"]*?)["']\]""")
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
     if md:
20
     if md:
20
         content = markdown(md)
21
         content = markdown(md)
21
         content = RE_VID.sub(lambda m: TEMPLATE_VID.format(m.group(1), m.group(1).split('.')[-1]), content)
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
 def preprocess_payload(payload):
40
 def preprocess_payload(payload):
27
     for column in payload.get("columns", []):
41
     for column in payload.get("columns", []):
28
-        column["content"] = preprocess_markdown(column.get("markdown"))
42
+        column["content"] = preprocess_content(column)
29
         for slide in column.get("slides", []):
43
         for slide in column.get("slides", []):
30
-            slide["content"] = preprocess_markdown(slide.get("markdown"))
44
+            slide["content"] = preprocess_content(slide)
31
 
45
 
32
 load_dotenv()
46
 load_dotenv()
33
 
47
 
54
 
68
 
55
 @application.get("/enum/<topic>")
69
 @application.get("/enum/<topic>")
56
 def choices(topic):
70
 def choices(topic):
57
-    if topic in ["img", "bg", "bg-video"]:
71
+    if topic in ["img", "bg", "bg-video", "audio"]:
58
         return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
72
         return {"type": "string", "enum": glob("static/{}/*.*".format(topic))}
59
     abort(404)
73
     abort(404)
60
 
74
 

+ 2
- 2
static/css/style.css View File

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

+ 32
- 6
static/slides.json View File

25
                 "background-video-mute": true,
25
                 "background-video-mute": true,
26
                 "background-opacity": "0.75"
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
             "slides": [
30
             "slides": [
30
                 {
31
                 {
31
                     "id": "work",
32
                     "id": "work",
34
                         "background-image": "static/bg/valley-1.svg",
35
                         "background-image": "static/bg/valley-1.svg",
35
                         "background-opacity": "0.25"
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
                     "id": "rest",
47
                     "id": "rest",
44
                         "background-opacity": "0.5",
51
                         "background-opacity": "0.5",
45
                         "background-size": "contain"
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
                     "id": "horse",
77
                     "id": "horse",
65
                     "title": "My horse",
78
                     "title": "My horse",
66
                     "params": {},
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
                     "id": "cat",
89
                     "id": "cat",
72
                     "params": {
91
                     "params": {
73
                         "background-size": "contain"
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 View File

14
       "items": {
14
       "items": {
15
         "type": "object",
15
         "type": "object",
16
         "title": "Chapter",
16
         "title": "Chapter",
17
+        "headerTemplate": "{{title}}: {{self.title}}",
17
         "properties": {
18
         "properties": {
18
           "id": {
19
           "id": {
19
             "type": "string"
20
             "type": "string"
24
           "params": {
25
           "params": {
25
             "$ref": "#/definitions/params"
26
             "$ref": "#/definitions/params"
26
           },
27
           },
28
+          "image": {
29
+            "$ref": "#/definitions/image"
30
+          },
27
           "markdown": {
31
           "markdown": {
28
             "$ref": "#/definitions/markdown"
32
             "$ref": "#/definitions/markdown"
29
           },
33
           },
34
+          "soundtrack": {
35
+            "$ref": "#/definitions/soundtrack"
36
+          },
30
           "slides": {
37
           "slides": {
31
             "type": "array",
38
             "type": "array",
32
             "title": "Pages",
39
             "title": "Pages",
36
             "items": {
43
             "items": {
37
               "type": "object",
44
               "type": "object",
38
               "title": "Page",
45
               "title": "Page",
46
+              "headerTemplate": "{{title}}: {{self.title}}",
39
               "properties": {
47
               "properties": {
40
                 "id": {
48
                 "id": {
41
                   "type": "string"
49
                   "type": "string"
46
                 "params": {
54
                 "params": {
47
                   "$ref": "#/definitions/params"
55
                   "$ref": "#/definitions/params"
48
                 },
56
                 },
57
+                "image": {
58
+                  "$ref": "#/definitions/image"
59
+                },
49
                 "markdown": {
60
                 "markdown": {
50
                   "$ref": "#/definitions/markdown"
61
                   "$ref": "#/definitions/markdown"
62
+                },
63
+                "soundtrack": {
64
+                  "$ref": "#/definitions/soundtrack"
51
                 }
65
                 }
52
               },
66
               },
53
               "required": [
67
               "required": [
117
         },
131
         },
118
         "background-video-loop": {
132
         "background-video-loop": {
119
             "type": "boolean",
133
             "type": "boolean",
134
+            "format": "checkbox",
120
             "default": true
135
             "default": true
121
         },
136
         },
122
         "background-video-mute": {
137
         "background-video-mute": {
123
             "type": "boolean",
138
             "type": "boolean",
139
+            "format": "checkbox",
124
             "default": true
140
             "default": true
125
         },
141
         },
126
         "background-opacity": {
142
         "background-opacity": {
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
     "markdown": {
217
     "markdown": {
149
       "type": "string",
218
       "type": "string",
150
       "title": "Content",
219
       "title": "Content",

+ 1
- 1
templates/slides.html View File

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

Loading…
Cancel
Save