diff --git a/web/build.py b/web/build.py index ca2c27a..2fb5267 100755 --- a/web/build.py +++ b/web/build.py @@ -4,15 +4,8 @@ from pathlib import Path, PurePath from negromateweb.builder import Builder -if len(sys.argv) == 2: - root_path = sys.argv[1] -else: - # root_path = '/nm/' - root_path = '/' - builder = Builder( Path('../bideoak'), Path('../libreto/libreto.pdf'), - root_path=PurePath(root_path) ) builder.build() diff --git a/web/ipfs.sh b/web/ipfs.sh new file mode 100755 index 0000000..ffb49e7 --- /dev/null +++ b/web/ipfs.sh @@ -0,0 +1,5 @@ +#!/bin/sh +cd .. +last_hash=$(ipfs add -r bideoak|awk '$3 == "bideoak" {print $2}') +cd - +echo "$last_hash" > ipfs.txt diff --git a/web/ipfs.txt b/web/ipfs.txt new file mode 100644 index 0000000..4b48f9f --- /dev/null +++ b/web/ipfs.txt @@ -0,0 +1 @@ +QmVm7kQ3p4Sg7rT41XJEC6KbnAhhBjBCBAcbsUpZAtq5Fb diff --git a/web/negromateweb/builder.py b/web/negromateweb/builder.py index 9c3344e..c8d8645 100644 --- a/web/negromateweb/builder.py +++ b/web/negromateweb/builder.py @@ -13,11 +13,12 @@ import webvtt class SongPage: THUMBNAIL_GEOMETRY = '200x200' - def __init__(self, path): + def __init__(self, path, root): self.name = path.name self.original = None self.author = None self.path = path + self.root = root self.video = None self.video_type = None self.vtt = None @@ -112,9 +113,11 @@ class SongPage: parsed_srt = list(srt.parse(srt_str)) except Exception as e: print("{}: srt parse error: {}".format(self.path.name, e)) + root_path = os.path.relpath(self.root, self.path) return { 'song': self, 'parsed_srt': parsed_srt, + 'root_path': root_path, } def render(self, builder, context): @@ -124,10 +127,9 @@ class SongPage: class Builder: - def __init__(self, root_folder, libreto, root_path=PurePath('/')): + def __init__(self, root_folder, libreto): self.root_folder = root_folder self.libreto = libreto - self.root_path = root_path self.static_dir = Path(__file__).parent / 'static' self.env = Environment( @@ -135,13 +137,16 @@ class Builder: autoescape=select_autoescape(['html']), ) self.env.filters['url'] = self.url + self.current_path = self.root_folder def url(self, path): - return self.root_path / path.relative_to(self.root_folder) + return os.path.relpath(path, self.current_path) def render(self, template, target, context): html_file = target / 'index.html' page_template = self.env.get_template(template) + root_path = os.path.relpath(self.root_folder, target) + context['root_path'] = root_path with html_file.open('w') as page: page.write(page_template.render(context)) @@ -154,7 +159,7 @@ class Builder: if entry.is_dir(): print("building {}".format(entry.name)) try: - songpage = SongPage(entry) + songpage = SongPage(entry, self.root_folder) except Exception as e: raise e print("Error: {}".format(e)) @@ -164,20 +169,23 @@ class Builder: songs.sort(key=lambda a: a.name) global_context = { 'songs': songs, - 'root_path': self.root_path, + 'root_folder': self.root_folder, } for song in songs: + self.current_path = song.path song.render(self, global_context) self.render('index.html', self.root_folder, global_context) home = self.root_folder / 'home' + self.current_path = home if not home.exists(): home.mkdir() self.render('home.html', home, global_context) playlist = self.root_folder / 'playlist' + self.current_path = playlist if not playlist.exists(): playlist.mkdir() diff --git a/web/negromateweb/static/css/main.css b/web/negromateweb/static/css/main.css index e5563f6..b1d8c4b 100644 --- a/web/negromateweb/static/css/main.css +++ b/web/negromateweb/static/css/main.css @@ -1,8 +1,3 @@ -@font-face { - font-family: "CyrBit"; - src: url("/static/css/CyrBit.ttf"); -} - body { display: flex; flex-wrap: wrap; diff --git a/web/negromateweb/templates/base.html b/web/negromateweb/templates/base.html index 75a9317..df270d5 100644 --- a/web/negromateweb/templates/base.html +++ b/web/negromateweb/templates/base.html @@ -4,23 +4,29 @@