-
Notifications
You must be signed in to change notification settings - Fork 0
/
examples.py
36 lines (28 loc) · 1.33 KB
/
examples.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
from nikola.plugin_categories import ShortcodePlugin
import glob
import os
def file_list(gallery):
return sorted(glob.glob(os.path.join('files', gallery, '*.html')))
class ExampleGallery(ShortcodePlugin):
name = "examples"
def handler(self, gallery_dir, site=None, lang=None, post=None, data=None):
files = file_list(gallery_dir)
html_lines = ['<div id="carouselExampleIndicators" class="carousel slide pb-5" data-ride="carousel" data-interval="10000">']
html_lines += ['<ol class="carousel-indicators">']
for i, html in enumerate(files):
if i == 0:
html_lines += [f'<li data-target="#carouselExampleIndicators" data-slide-to="{i}" class="active"></li>']
else:
html_lines += [f'<li data-target="#carouselExampleIndicators" data-slide-to="{i}"></li>']
html_lines += ['</ol>']
html_lines += ['<div class="carousel-inner">']
for i, html in enumerate(files):
if i == 0:
html_lines += ['<div class="carousel-item active">']
else:
html_lines += ['<div class="carousel-item">']
with open(html, 'r') as f:
html_lines.append(f.read())
html_lines +=['</div>']
html_lines += ['</div></div>']
return '\n'.join(html_lines), files