diff --git a/docs/changelog.rst b/docs/changelog.rst index 40bcc11..aaf3f75 100644 --- a/docs/changelog.rst +++ b/docs/changelog.rst @@ -1,7 +1,12 @@ Changelog ========= -0.5 (2017-06-02) +0.6 (2017-07-14) + + * Compatibility python 2 and 3 + * Possibility to add custom css and js http://prosopopee.readthedocs.io/en/latest/theming.html + +0.5 (2017-06-04) * Add audio HTML5 player https://prosopopee.readthedocs.org/en/latest/sections.html#audio by beudbeud * Update Material theme by beudbeud @@ -10,6 +15,7 @@ Changelog * Add deploy and preview option https://prosopopee.readthedocs.io/en/latest/build.html#preview by beudbeud * Load only css and jss if the section is used by beudbeud * Possibility to add floating image in paragraph by beudbeud https://prosopopee.readthedocs.org/en/latest/sections.html#paragraph + * fix some bugs 0.4 (2016-12-11) diff --git a/docs/index.rst b/docs/index.rst index 0f6152c..6b5842d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -46,5 +46,6 @@ Documentation sections example build + theming authors changelog diff --git a/docs/sections.rst b/docs/sections.rst index fe718cf..8ca16e5 100644 --- a/docs/sections.rst +++ b/docs/sections.rst @@ -151,6 +151,7 @@ This section is for add audio file with HTML5 player.:: - type: audio title: Title of song image: song.ogg + color: "#000" (optional) Author diff --git a/docs/theming.rst b/docs/theming.rst new file mode 100644 index 0000000..88dd339 --- /dev/null +++ b/docs/theming.rst @@ -0,0 +1,24 @@ +Theming +======= + +Custom css and js +----------------- + +You can add easily css code and js code. You need create custom.css or custom.js +in root directory. + +Override template +----------------- + +If you wanna override template, you need create a "templates" directory and create your own template. + +* home page : index.html +* gallery page: gallery-index.html + +And for override sections you need create file in "templates/sections". + + +Create theme +------------ + +TODO diff --git a/prosopopee/cache.py b/prosopopee/cache.py index cc1050f..48c94a6 100644 --- a/prosopopee/cache.py +++ b/prosopopee/cache.py @@ -33,7 +33,7 @@ class Cache(object): self.cache = {"version": CACHE_VERSION} if "version" not in self.cache or self.cache["version"] != CACHE_VERSION: - print "info: cache format as changed, prune cache" + print("info: cache format as changed, prune cache") self.cache = {"version": CACHE_VERSION} def needs_to_be_generated(self, source, target, options): @@ -53,8 +53,7 @@ class Cache(object): def cache_picture(self, source, target, options): self.cache[target] = {"size": os.path.getsize(source), "options": remove_superficial_options(options)} - def __del__(self): + def cache_dump(self): self.json.dump(self.cache, open(self.cache_file_path, "w")) - CACHE = Cache(json=json) diff --git a/prosopopee/prosopopee.py b/prosopopee/prosopopee.py index 6e4bb66..12f4ce1 100644 --- a/prosopopee/prosopopee.py +++ b/prosopopee/prosopopee.py @@ -13,15 +13,14 @@ Options: """ import os -import yaml import shutil +import socketserver +import http.server + +import ruamel.yaml as yaml +#import yaml from docopt import docopt -import SocketServer -import SimpleHTTPServer - -import subprocess - from path import Path from jinja2 import Environment, FileSystemLoader @@ -94,18 +93,18 @@ class Video(object): return ffmpeg_switches = { - "source": source, - "target": target, - "loglevel": "-loglevel %s" % options["loglevel"], - "resolution": "-s %s" % options["resolution"], - "resize": "-vf scale=-1:%s" % options.get("resize"), - "vbitrate": "-b:v %s" % options["vbitrate"], - "abitrate": "-b:v %s" % options["abitrate"], - "format": "-f %s" % options["format"], - "binary": "%s" % options["binary"], - "video": "-c:v %s" % options["video"], - "audio": "-c:a %s" % options["audio"], - "other": "%s" % options["other"] + "source": source, + "target": target, + "loglevel": "-loglevel %s" % options["loglevel"], + "resolution": "-s %s" % options["resolution"], + "resize": "-vf scale=-1:%s" % options.get("resize"), + "vbitrate": "-b:v %s" % options["vbitrate"], + "abitrate": "-b:v %s" % options["abitrate"], + "format": "-f %s" % options["format"], + "binary": "%s" % options["binary"], + "video": "-c:v %s" % options["video"], + "audio": "-c:a %s" % options["audio"], + "other": "%s" % options["other"] } warning("Generation", source) @@ -168,11 +167,11 @@ class Audio(object): return ffmpeg_switches = { - "source": source, - "target": target, - "binary": "%s" % options["binary"], - "loglevel": "-loglevel %s" % options["loglevel"], - "audio": "-c:a %s" % options["audio"] + "source": source, + "target": target, + "binary": "%s" % options["binary"], + "loglevel": "-loglevel %s" % options["loglevel"], + "audio": "-c:a %s" % options["audio"] } warning("Generation", source) @@ -215,13 +214,13 @@ class Image(object): return gm_switches = { - "source": source, - "target": target, - "auto-orient": "-auto-orient" if options["auto-orient"] else "", - "strip": "-strip" if options["strip"] else "", - "quality": "-quality %s" % options["quality"] if "quality" in options else "-define jpeg:preserve-settings", - "resize": "-resize %s" % options["resize"] if options.get("resize", None) is not None else "", - "progressive": "-interlace Line" if options.get("progressive", None) is True else "" + "source": source, + "target": target, + "auto-orient": "-auto-orient" if options["auto-orient"] else "", + "strip": "-strip" if options["strip"] else "", + "quality": "-quality %s" % options["quality"] if "quality" in options else "-define jpeg:preserve-settings", + "resize": "-resize %s" % options["resize"] if options.get("resize", None) is not None else "", + "progressive": "-interlace Line" if options.get("progressive", None) is True else "" } command = "gm convert '{source}' {auto-orient} {strip} {progressive} {quality} {resize} '{target}'".format(**gm_switches) @@ -244,7 +243,7 @@ class Image(object): if not options["auto-orient"] and not options["strip"]: shutil.copyfile(source, target) - print("%s%s%s" % (source, "->", target)) + print(("%s%s%s" % (source, "->", target))) else: # Do not consider quality settings here, since we aim to copy the input image # better to preserve input encoding setting @@ -273,15 +272,22 @@ def get_settings(): error(Path("settings.yaml").exists(), "I can't find a " "settings.yaml in the current working directory") - settings = yaml.safe_load(open("settings.yaml", "r")) + try: + settings = yaml.safe_load(open("settings.yaml", "r")) + except yaml.YAMLError as exc: + if hasattr(exc, 'problem_mark'): + mark = exc.problem_mark + error(False, "There are something wrong in settings.yaml line %s" % (mark.line)) + else: + error(False, "There are omething wrong in settings.yaml") error(isinstance(settings, dict), "Your settings.yaml should be a dict") - for key, value in DEFAULTS.items(): + for key, value in list(DEFAULTS.items()): if key not in settings: settings[key] = value - for key, value in SETTINGS.items(): + for key, value in list(SETTINGS.items()): if key not in settings: settings[key] = value @@ -357,7 +363,14 @@ def process_directory(gallery_name, settings, parent_templates, parent_gallery_p else: gallery_path = gallery_name - gallery_settings = yaml.safe_load(open(Path(".").joinpath(gallery_path, "settings.yaml").abspath(), "r")) + try: + gallery_settings = yaml.safe_load(open(Path(".").joinpath(gallery_path, "settings.yaml").abspath(), "r")) + except yaml.YAMLError as exc: + if hasattr(exc, 'problem_mark'): + mark = exc.problem_mark + error(False, "There are something wrong in %s/settings.yaml line %s" % (gallery_path, mark.line)) + else: + error(False, "There are something wrong in %s/settings.yaml" % (gallery_path)) error(isinstance(gallery_settings, dict), "Your %s should be a dict" % gallery_name.joinpath("settings.yaml")) error(gallery_settings.get("title"), "You should specify a title in %s" % gallery_name.joinpath("settings.yaml")) @@ -458,7 +471,7 @@ def build_gallery(settings, gallery_settings, gallery_path, template): name=gallery_path.split('/', 1)[-1] ).encode("Utf-8") - open(Path("build").joinpath(gallery_path, "index.html"), "w").write(html) + open(Path("build").joinpath(gallery_path, "index.html"), "wb").write(html) # XXX shouldn't this be a call to build_gallery? # Build light mode gallery @@ -493,11 +506,12 @@ def build_gallery(settings, gallery_settings, gallery_path, template): name=gallery_path.split('/', 1)[-1] ).encode("Utf-8") - open(Path("build").joinpath(gallery_light_path, "index.html"), "w").write(html) + open(Path("build").joinpath(gallery_light_path, "index.html"), "wb").write(html) def build_index(settings, galleries_cover, templates, gallery_path='', sub_index=False, gallery_settings={}): index_template = templates.get_template("index.html") + reverse = gallery_settings.get('reverse', settings.get('reverse', True)) if reverse: galleries_cover = reversed(sorted(filter(lambda x: x != {}, galleries_cover), key=lambda x: x["date"])) @@ -519,7 +533,7 @@ def build_index(settings, galleries_cover, templates, gallery_path='', sub_index Video=Video ).encode("Utf-8") - open(Path("build").joinpath(gallery_path, "index.html"), "w").write(html) + open(Path("build").joinpath(gallery_path, "index.html"), "wb").write(html) def main(): @@ -538,11 +552,10 @@ def main(): error(Path("build").exists(), "Please build the website before launch preview") os.chdir('build') + handler = http.server.SimpleHTTPRequestHandler + httpd = socketserver.TCPServer(("", 9000), handler) - Handler = SimpleHTTPServer.SimpleHTTPRequestHandler - httpd = SocketServer.TCPServer(("", 9000), Handler) - - print "Start server on http://localhost:9000" + print('Start server on http://localhost:9000') # gracefully handle interrupt here httpd.serve_forever() @@ -570,6 +583,14 @@ def main(): templates = get_gallery_templates(theme) templates.add_extension('jinja2.ext.with_') + if Path("custom.js").exists(): + shutil.copy(Path("custom.js"), Path(".").joinpath("build", "", "static", "js")) + settings["custom_js"] = True + + if Path("custom.css").exists(): + shutil.copy(Path("custom.css"), Path(".").joinpath("build", "", "static", "css")) + settings["custom_css"] = True + for gallery in galleries_dirs: front_page_galleries_cover.append(process_directory(gallery, settings, templates)) @@ -578,12 +599,13 @@ def main(): xml = feed_template.render( settings=settings, - galleries=reversed(sorted(filter(lambda x: x != {}, front_page_galleries_cover), key=lambda x: x["date"])) + galleries=reversed(sorted([x for x in front_page_galleries_cover if x != {}], key=lambda x: x["date"])) ).encode("Utf-8") - open(Path("build").joinpath("feed.xml"), "w").write(xml) + open(Path("build").joinpath("feed.xml"), "wb").write(xml) build_index(settings, front_page_galleries_cover, templates) + CACHE.cache_dump() if __name__ == '__main__': diff --git a/prosopopee/themes/exposure/templates/footer.html b/prosopopee/themes/exposure/templates/footer.html index 295d26a..3503718 100644 --- a/prosopopee/themes/exposure/templates/footer.html +++ b/prosopopee/themes/exposure/templates/footer.html @@ -5,6 +5,9 @@ {% set licence_url = settings.licence.url %} {% set licence_name = settings.licence.name %} {% endif %} +{% if settings.custom_js %} + +{% endif %} diff --git a/prosopopee/themes/exposure/templates/gallery-index.html b/prosopopee/themes/exposure/templates/gallery-index.html index 521e9df..0c57f0b 100644 --- a/prosopopee/themes/exposure/templates/gallery-index.html +++ b/prosopopee/themes/exposure/templates/gallery-index.html @@ -12,6 +12,9 @@ {% if gallery.audio_enabled %} {% endif %} + {% if settings.custom_css %} + + {% endif %} {% if gallery.description %} @@ -79,18 +82,16 @@ $('audio').mediaelementplayer({ }); {% endif %} -var video = $("video"); -video.on('click', function(e){ - var vid = video[0]; - vid.play(); - if (vid.requestFullscreen) { - vid.requestFullscreen(); - } else if (vid.mozRequestFullScreen) { - vid.mozRequestFullScreen(); - } else if (vid.webkitRequestFullscreen) { - vid.webkitRequestFullscreen(); - } -}); +function goFullscreen(id) { + var element = document.getElementById(id); + if (element.requestFullscreen) { + element.requestFullscreen(); + } else if (element.mozRequestFullScreen) { + element.mozRequestFullScreen(); + } else if (element.webkitRequestFullScreen) { + element.webkitRequestFullScreen(); + } +} $(function() { $("img.lazy").lazyload({ diff --git a/prosopopee/themes/exposure/templates/index.html b/prosopopee/themes/exposure/templates/index.html index 74409a4..7037eb5 100644 --- a/prosopopee/themes/exposure/templates/index.html +++ b/prosopopee/themes/exposure/templates/index.html @@ -3,6 +3,9 @@ {% block css %} +{% if settings.custom_css %} + +{% endif %} {% endblock %} {% block logo %} diff --git a/prosopopee/themes/exposure/templates/sections/audio.html b/prosopopee/themes/exposure/templates/sections/audio.html index cf99913..7cb88b2 100644 --- a/prosopopee/themes/exposure/templates/sections/audio.html +++ b/prosopopee/themes/exposure/templates/sections/audio.html @@ -6,7 +6,7 @@ {% set format = extension %} {% endif %} {{ audio.copy() }} -