merge
This commit is contained in:
commit
c195974848
@ -8,6 +8,7 @@ The files organisation is quite simple:
|
||||
* in the root directory of your project you need a settings.yaml file that will contains the title and subtitle of your gallery
|
||||
* for each gallery you'll need a folder that also contains a settings.yaml file that will describe how to display the content on your gallery
|
||||
* and you put the pictures of the gallery inside the gallery folder
|
||||
* or other directory, in the gallery became an index (so pictures won't be display, only cover of child gallery)
|
||||
|
||||
Root settings.yaml
|
||||
------------------
|
||||
|
@ -42,3 +42,79 @@ The content of ``example/first_gallery/settings.yaml``::
|
||||
- stuff.png
|
||||
- type: full-picture
|
||||
image: stuff.png
|
||||
|
||||
The content of ``example/second_gallery/settings.yaml``::
|
||||
|
||||
title: my second level gallery
|
||||
sub_title: some subtitle
|
||||
date: 2015-12-08
|
||||
cover: stuff.png
|
||||
|
||||
The content of ``example/second_gallery/second_level_gallery_2/settings.yaml``::
|
||||
|
||||
title: my second level gallery 2
|
||||
sub_title: some subtitle
|
||||
date: 2015-12-08
|
||||
cover: stuff.png
|
||||
sections:
|
||||
- type: full-picture
|
||||
image: stuff.png
|
||||
text:
|
||||
title: Beautiful Title
|
||||
sub_title: pouet pouet
|
||||
date: 2015-12-08
|
||||
- type: full-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
text:
|
||||
title: Beautiful Title
|
||||
sub_title: pouet pouet
|
||||
date: 2015-12-08
|
||||
- type: bordered-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
- type: bordered-picture
|
||||
image: stuff.png
|
||||
- type: bordered-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
text: "plop"
|
||||
- type: bordered-picture
|
||||
image: stuff.png
|
||||
text: "plop"
|
||||
- type: text
|
||||
text: « voici plein de blabla à rajouter et <b>ceci est du gras</b> et encore plein plein plein plein de text car je veux voir comment ça va wrapper car c'est important et il faut pas que j'oublie de mettre des margins en % sinon ça va pas le faire alala là ça devrait aller »
|
||||
- type: pictures-group
|
||||
images:
|
||||
-
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: video.mp4
|
||||
type: video
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
-
|
||||
- stuff.png
|
||||
- name: video.mp4
|
||||
type: video
|
||||
- type: pictures-group
|
||||
images:
|
||||
-
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
-
|
||||
- stuff.png
|
||||
- stuff.png
|
||||
- type: full-picture
|
||||
image: stuff.png
|
||||
- type: full-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
|
@ -2,6 +2,7 @@ title: my first gallery
|
||||
sub_title: some subtitle
|
||||
date: 2015-12-08
|
||||
cover: stuff.png
|
||||
light_mode: true
|
||||
sections:
|
||||
- type: full-picture
|
||||
image: stuff.png
|
||||
|
@ -0,0 +1,7 @@
|
||||
title: my second gallery
|
||||
sub_title: some subtitle
|
||||
date: 2015-12-08
|
||||
cover:
|
||||
type: video
|
||||
name: video.mp4
|
||||
theme: exposure
|
BIN
example/second_gallery/second_level_gallery/stuff.png
Normal file
BIN
example/second_gallery/second_level_gallery/stuff.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
@ -0,0 +1,67 @@
|
||||
title: my third level gallery
|
||||
sub_title: some subtitle
|
||||
date: 2015-12-08
|
||||
cover: stuff.png
|
||||
light_mode: true
|
||||
sections:
|
||||
- type: full-picture
|
||||
image: stuff.png
|
||||
text:
|
||||
title: Beautiful Title
|
||||
sub_title: pouet pouet
|
||||
date: 2015-12-08
|
||||
- type: full-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
text:
|
||||
title: Beautiful Title
|
||||
sub_title: pouet pouet
|
||||
date: 2015-12-08
|
||||
- type: bordered-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
- type: bordered-picture
|
||||
image: stuff.png
|
||||
- type: bordered-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
text: "plop"
|
||||
- type: bordered-picture
|
||||
image: stuff.png
|
||||
text: "plop"
|
||||
- type: text
|
||||
text: « voici plein de blabla à rajouter et <b>ceci est du gras</b> et encore plein plein plein plein de text car je veux voir comment ça va wrapper car c'est important et il faut pas que j'oublie de mettre des margins en % sinon ça va pas le faire alala là ça devrait aller »
|
||||
- type: pictures-group
|
||||
images:
|
||||
-
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: video.mp4
|
||||
type: video
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
-
|
||||
- stuff.png
|
||||
- name: video.mp4
|
||||
type: video
|
||||
- type: pictures-group
|
||||
images:
|
||||
-
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
-
|
||||
- stuff.png
|
||||
- stuff.png
|
||||
- type: full-picture
|
||||
image: stuff.png
|
||||
- type: full-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
Binary file not shown.
BIN
example/second_gallery/second_level_gallery/video.mp4
Normal file
BIN
example/second_gallery/second_level_gallery/video.mp4
Normal file
Binary file not shown.
66
example/second_gallery/second_level_gallery_2/settings.yaml
Normal file
66
example/second_gallery/second_level_gallery_2/settings.yaml
Normal file
@ -0,0 +1,66 @@
|
||||
title: my second level gallery 2
|
||||
sub_title: some subtitle
|
||||
date: 2015-12-08
|
||||
cover: stuff.png
|
||||
sections:
|
||||
- type: full-picture
|
||||
image: stuff.png
|
||||
text:
|
||||
title: Beautiful Title
|
||||
sub_title: pouet pouet
|
||||
date: 2015-12-08
|
||||
- type: full-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
text:
|
||||
title: Beautiful Title
|
||||
sub_title: pouet pouet
|
||||
date: 2015-12-08
|
||||
- type: bordered-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
- type: bordered-picture
|
||||
image: stuff.png
|
||||
- type: bordered-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
||||
text: "plop"
|
||||
- type: bordered-picture
|
||||
image: stuff.png
|
||||
text: "plop"
|
||||
- type: text
|
||||
text: « voici plein de blabla à rajouter et <b>ceci est du gras</b> et encore plein plein plein plein de text car je veux voir comment ça va wrapper car c'est important et il faut pas que j'oublie de mettre des margins en % sinon ça va pas le faire alala là ça devrait aller »
|
||||
- type: pictures-group
|
||||
images:
|
||||
-
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: video.mp4
|
||||
type: video
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
-
|
||||
- stuff.png
|
||||
- name: video.mp4
|
||||
type: video
|
||||
- type: pictures-group
|
||||
images:
|
||||
-
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
- name: stuff.png
|
||||
text: "test"
|
||||
-
|
||||
- stuff.png
|
||||
- stuff.png
|
||||
- type: full-picture
|
||||
image: stuff.png
|
||||
- type: full-picture
|
||||
image:
|
||||
name: video.mp4
|
||||
type: video
|
BIN
example/second_gallery/second_level_gallery_2/stuff.png
Normal file
BIN
example/second_gallery/second_level_gallery_2/stuff.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
BIN
example/second_gallery/second_level_gallery_2/video.mp4
Normal file
BIN
example/second_gallery/second_level_gallery_2/video.mp4
Normal file
Binary file not shown.
4
example/second_gallery/settings.yaml
Normal file
4
example/second_gallery/settings.yaml
Normal file
@ -0,0 +1,4 @@
|
||||
title: my second level gallery
|
||||
sub_title: some subtitle
|
||||
date: 2015-12-08
|
||||
cover: stuff.png
|
BIN
example/second_gallery/stuff.png
Normal file
BIN
example/second_gallery/stuff.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 MiB |
BIN
example/second_gallery/video.mp4
Normal file
BIN
example/second_gallery/video.mp4
Normal file
Binary file not shown.
@ -188,7 +188,7 @@ class Image(object):
|
||||
return self.name
|
||||
|
||||
|
||||
def main():
|
||||
def init():
|
||||
error(os.path.exists(os.path.join(os.getcwd(), "settings.yaml")), "I can't find a "
|
||||
"settings.yaml in the current working directory")
|
||||
|
||||
@ -210,17 +210,17 @@ def main():
|
||||
error(os.system("which gm > /dev/null") == 0, "I can't locate the gm binary, "
|
||||
"please install the 'graphicsmagick' package.\n")
|
||||
|
||||
if os.system("which " + conv_video +" > /dev/null") != 0:
|
||||
if os.system("which " + conv_video + " > /dev/null") != 0:
|
||||
if conv_video == "ffmpeg" and os.system("which avconv > /dev/null") == 0:
|
||||
SETTINGS["ffmpeg"]["binary"] = "avconv"
|
||||
warning("Video", "I couldn't locate ffmpeg but I could find avconv, switching to avconv for video conversion")
|
||||
warning("Video", "I couldn't locate ffmpeg but I could find avconv, "
|
||||
"switching to avconv for video conversion")
|
||||
else:
|
||||
warning("Video", "I can't locate the "+ conv_video +" binary, "
|
||||
warning("Video", "I can't locate the " + conv_video + " binary, "
|
||||
"please install the '" + conv_video + "' package.\n")
|
||||
warning("Video", "I won't be able to encode video and I will stop if I encounter a video to convert")
|
||||
SETTINGS["ffmpeg"] = False
|
||||
|
||||
|
||||
error(settings.get("title"), "You need to specify a title in your main settings.yaml")
|
||||
|
||||
if (settings["rss"] or settings["share"]) and not settings.get("url"):
|
||||
@ -231,10 +231,216 @@ def main():
|
||||
|
||||
if settings["settings"].get("gm"):
|
||||
SETTINGS["gm"].update(settings["settings"]["gm"])
|
||||
return settings
|
||||
|
||||
|
||||
def get_gallery_templates(theme, gallery_path="", parent_templates=None):
|
||||
if theme:
|
||||
theme_path = os.path.exists(
|
||||
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme))
|
||||
available_themes = theme, "', '".join(
|
||||
os.listdir(os.path.join(os.path.split(os.path.realpath(__file__))[0],
|
||||
"themes")))
|
||||
|
||||
error(theme_path, "'%s' is not an existing theme, available themes are '%s'" % available_themes)
|
||||
|
||||
templates_dir = [
|
||||
os.path.realpath(os.path.join(os.getcwd(), "templates")),
|
||||
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "templates")
|
||||
]
|
||||
|
||||
if theme != "exposure":
|
||||
templates_dir.append(os.path.join(os.path.split(os.path.realpath(__file__))[0],
|
||||
"themes", "exposure", "templates"))
|
||||
|
||||
subgallery_templates = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True)
|
||||
else:
|
||||
if parent_templates:
|
||||
theme = "exposure"
|
||||
subgallery_templates = parent_templates
|
||||
else:
|
||||
templates_dir = [
|
||||
os.path.realpath(os.path.join(os.getcwd(), "templates")),
|
||||
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "templates")
|
||||
]
|
||||
subgallery_templates = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True)
|
||||
|
||||
# XXX recursively merge directories
|
||||
if os.path.exists(os.path.join(os.getcwd(), "build", gallery_path, "static")):
|
||||
shutil.rmtree(os.path.join(os.getcwd(), "build", gallery_path, "static"))
|
||||
|
||||
if os.path.exists(os.path.join(os.getcwd(), "static")):
|
||||
shutil.copytree(os.path.join(os.getcwd(), "static"), os.path.join(os.getcwd(), "build", gallery_path, "static"))
|
||||
else:
|
||||
shutil.copytree(
|
||||
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "static"),
|
||||
os.path.join(os.getcwd(), "build", gallery_path, "static"))
|
||||
return subgallery_templates
|
||||
|
||||
|
||||
def process_directory(gallery_name, settings, parent_templates, parent_gallery_path=False):
|
||||
if parent_gallery_path:
|
||||
gallery_path = os.path.join(parent_gallery_path, gallery_name)
|
||||
else:
|
||||
gallery_path = gallery_name
|
||||
|
||||
gallery_settings = yaml.safe_load(open(os.path.join(os.getcwd(), gallery_path, "settings.yaml"), "r"))
|
||||
|
||||
error(isinstance(gallery_settings, dict), "Your %s should be a dict" % (os.path.join(gallery_name, "settings.yaml")))
|
||||
error(gallery_settings.get("title"), "You should specify a title in %s" % (os.path.join(gallery_name, "settings.yaml")))
|
||||
|
||||
gallery_cover = {}
|
||||
|
||||
sub_galleries = filter(lambda x: x not in (".", "..") and os.path.isdir(os.path.join(gallery_path, x)) and
|
||||
os.path.exists(os.path.join(os.getcwd(), gallery_path, x, "settings.yaml")),
|
||||
os.listdir(os.path.join(os.getcwd(), gallery_path)))
|
||||
|
||||
if not os.path.exists(os.path.join("build", gallery_path)):
|
||||
os.makedirs(os.path.join("build", gallery_path))
|
||||
|
||||
|
||||
if not gallery_settings.get("public", True):
|
||||
build_gallery(settings, gallery_settings, gallery_path, parent_templates)
|
||||
else:
|
||||
gallery_cover = create_cover(gallery_name, gallery_settings, gallery_path)
|
||||
|
||||
if sub_galleries:
|
||||
error(gallery_settings.get("sections") is not False,
|
||||
"The gallery in %s can't have both sections and subgalleries" % (os.path.join(gallery_name,
|
||||
"settings.yaml")))
|
||||
|
||||
# Sub galleries found, create index with them instead of a gallery
|
||||
theme = gallery_settings.get("theme", settings.get("theme", "exposure"))
|
||||
|
||||
subgallery_templates = get_gallery_templates(theme, gallery_path, parent_templates)
|
||||
sub_page_galleries_cover = []
|
||||
|
||||
for subgallery in sub_galleries:
|
||||
sub_page_galleries_cover.append(
|
||||
process_directory(subgallery, settings, subgallery_templates, gallery_path)
|
||||
)
|
||||
|
||||
build_index(settings, sub_page_galleries_cover, subgallery_templates, gallery_path)
|
||||
gallery_cover['sub_gallery'] = sub_page_galleries_cover
|
||||
else:
|
||||
# No sub galleries found, create a gallery
|
||||
build_gallery(settings, gallery_settings, gallery_path, parent_templates)
|
||||
|
||||
return gallery_cover
|
||||
|
||||
|
||||
def create_cover(gallery_name, gallery_settings, gallery_path):
|
||||
error(gallery_settings.get("title"), "Your gallery describe in %s need to have a "
|
||||
"title" % (os.path.join(gallery_name, "settings.yaml")))
|
||||
|
||||
error(gallery_settings.get("cover"), "You should specify a path to a cover picture "
|
||||
"in %s" % (os.path.join(gallery_name, "settings.yaml")))
|
||||
|
||||
if isinstance(gallery_settings["cover"], dict):
|
||||
cover_image_path = os.path.join(gallery_path, gallery_settings["cover"]["name"])
|
||||
cover_image_url = os.path.join(gallery_name, gallery_settings["cover"]["name"])
|
||||
cover_image_type = gallery_settings["cover"]["type"]
|
||||
else:
|
||||
cover_image_path = os.path.join(gallery_path, gallery_settings["cover"])
|
||||
cover_image_url = os.path.join(gallery_name, gallery_settings["cover"])
|
||||
cover_image_type = "image"
|
||||
|
||||
error(os.path.exists(cover_image_path), "File for %s cover image doesn't exist at "
|
||||
"%s" % (gallery_name, cover_image_path))
|
||||
|
||||
gallery_cover = {
|
||||
"title": gallery_settings["title"],
|
||||
"link": gallery_name,
|
||||
"sub_title": gallery_settings.get("sub_title", ""),
|
||||
"date": gallery_settings.get("date", ""),
|
||||
"tags": gallery_settings.get("tags", ""),
|
||||
"cover_type": cover_image_type,
|
||||
"cover": cover_image_url,
|
||||
}
|
||||
return gallery_cover
|
||||
|
||||
|
||||
def build_gallery(settings, gallery_settings, gallery_path, template):
|
||||
gallery_index_template = template.get_template("gallery-index.html")
|
||||
page_template = template.get_template("page.html")
|
||||
|
||||
# this should probably be a factory
|
||||
Image.base_dir = os.path.join(os.getcwd(), gallery_path)
|
||||
Image.target_dir = os.path.join(os.getcwd(), "build", gallery_path)
|
||||
|
||||
Video.base_dir = os.path.join(os.getcwd(), gallery_path)
|
||||
Video.target_dir = os.path.join(os.getcwd(), "build", gallery_path)
|
||||
|
||||
template_to_render = page_template if gallery_settings.get("static") else gallery_index_template
|
||||
|
||||
index_html = open(os.path.join("build", gallery_path, "index.html"), "w")
|
||||
|
||||
index_html.write(template_to_render.render(
|
||||
settings=settings,
|
||||
gallery=gallery_settings,
|
||||
Image=Image,
|
||||
Video=Video,
|
||||
link=gallery_path
|
||||
).encode("Utf-8"))
|
||||
|
||||
#Build light mode gallery
|
||||
if gallery_settings.get("light_mode", False) or (
|
||||
settings["settings"].get("light_mode", False) and gallery_settings.get("light_mode") is None):
|
||||
# Prepare light mode
|
||||
if not os.path.exists(os.path.join("build", gallery_path, "light")):
|
||||
os.makedirs(os.path.join("build", gallery_path, "light"))
|
||||
gallery_light_path = os.path.join(gallery_path, "light")
|
||||
light_templates = get_gallery_templates("light", gallery_light_path)
|
||||
|
||||
Image.base_dir = os.path.join(os.getcwd(), gallery_path)
|
||||
Image.target_dir = os.path.join(os.getcwd(), "build", gallery_path)
|
||||
|
||||
Video.base_dir = os.path.join(os.getcwd(), gallery_path)
|
||||
Video.target_dir = os.path.join(os.getcwd(), "build", gallery_path)
|
||||
|
||||
light_template_to_render = light_templates.get_template("gallery-index.html")
|
||||
|
||||
index_html = open(os.path.join("build", gallery_light_path, "index.html"), "w")
|
||||
|
||||
index_html.write(light_template_to_render.render(
|
||||
settings=settings,
|
||||
gallery=gallery_settings,
|
||||
Image=Image,
|
||||
Video=Video,
|
||||
link=gallery_light_path
|
||||
).encode("Utf-8"))
|
||||
|
||||
|
||||
|
||||
def build_index(settings, galleries_cover, templates, gallery_path=''):
|
||||
index_template = templates.get_template("index.html")
|
||||
|
||||
galleries_cover = reversed(sorted(filter(lambda x: x != {}, galleries_cover), key=lambda x: x["date"]))
|
||||
|
||||
# this should probably be a factory
|
||||
Image.base_dir = os.path.join(os.getcwd(), gallery_path)
|
||||
Image.target_dir = os.path.join(os.getcwd(), "build", gallery_path)
|
||||
|
||||
Video.base_dir = os.path.join(os.getcwd(), gallery_path)
|
||||
Video.target_dir = os.path.join(os.getcwd(), "build", gallery_path)
|
||||
|
||||
index_html = open(os.path.join("build", gallery_path, "index.html"), "w")
|
||||
|
||||
index_html.write(index_template.render(
|
||||
settings=settings,
|
||||
galleries=galleries_cover,
|
||||
Image=Image,
|
||||
Video=Video
|
||||
).encode("Utf-8"))
|
||||
|
||||
|
||||
def main():
|
||||
settings = init()
|
||||
|
||||
front_page_galleries_cover = []
|
||||
|
||||
dirs = filter(lambda x: x not in (".", "..") and os.path.isdir(x) and os.path.exists(os.path.join(os.getcwd(), x, "settings.yaml")), os.listdir(os.getcwd()))
|
||||
dirs = filter(lambda x: x not in (".", "..") and os.path.isdir(x) and
|
||||
os.path.exists(os.path.join(os.getcwd(), x, "settings.yaml")), os.listdir(os.getcwd()))
|
||||
|
||||
error(dirs, "I can't find at least one directory with a settings.yaml in the current working "
|
||||
"directory (NOT the settings.yaml in your current directory, but one INSIDE A "
|
||||
@ -244,144 +450,22 @@ def main():
|
||||
os.makedirs("build")
|
||||
|
||||
theme = settings["settings"].get("theme", "exposure")
|
||||
|
||||
theme_path = os.path.exists(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme))
|
||||
available_themes = theme, "', '".join(os.listdir(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes")))
|
||||
|
||||
error(theme_path, "'%s' is not an existing theme, available themes are '%s'" % (available_themes))
|
||||
|
||||
templates_dir = [
|
||||
os.path.realpath(os.path.join(os.getcwd(), "templates")),
|
||||
os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "templates")
|
||||
]
|
||||
|
||||
if theme != "exposure":
|
||||
templates_dir.append(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", "exposure", "templates"))
|
||||
|
||||
|
||||
templates = Environment(loader=FileSystemLoader(templates_dir), trim_blocks=True)
|
||||
|
||||
index_template = templates.get_template("index.html")
|
||||
gallery_index_template = templates.get_template("gallery-index.html")
|
||||
page_template = templates.get_template("page.html")
|
||||
templates = get_gallery_templates(theme)
|
||||
templates.add_extension('jinja2.ext.with_')
|
||||
feed_template = templates.get_template("feed.xml")
|
||||
|
||||
# XXX recursively merge directories
|
||||
if os.path.exists(os.path.join(os.getcwd(), "build", "static")):
|
||||
shutil.rmtree(os.path.join(os.getcwd(), "build", "static"))
|
||||
|
||||
if os.path.exists(os.path.join(os.getcwd(), "static")):
|
||||
shutil.copytree(os.path.join(os.getcwd(), "static"), os.path.join(os.getcwd(), "build", "static"))
|
||||
else:
|
||||
shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", theme, "static"), os.path.join(os.getcwd(), "build", "static"))
|
||||
|
||||
for gallery in dirs:
|
||||
gallery_settings = yaml.safe_load(open(os.path.join(os.getcwd(), gallery, "settings.yaml"), "r"))
|
||||
|
||||
error(isinstance(gallery_settings, dict), "Your %s should be a dict" % (os.path.join(gallery, "settings.yaml")))
|
||||
error(gallery_settings.get("title"), "You should specify a title in %s" % (os.path.join(gallery, "settings.yaml")))
|
||||
|
||||
if gallery_settings.get("public", True):
|
||||
error(gallery_settings.get("title"), "Your gallery describe in %s need to have a "
|
||||
"title" % (os.path.join(gallery, "settings.yaml")))
|
||||
error(gallery_settings.get("cover"), "You should specify a path to a cover picture "
|
||||
"in %s" % (os.path.join(gallery, "settings.yaml")))
|
||||
|
||||
if isinstance(gallery_settings["cover"], dict):
|
||||
cover_image_path = os.path.join(gallery, gallery_settings["cover"]["name"])
|
||||
cover_image_type = gallery_settings["cover"]["type"]
|
||||
else:
|
||||
cover_image_path = os.path.join(gallery, gallery_settings["cover"])
|
||||
cover_image_type = "image"
|
||||
|
||||
error(os.path.exists(cover_image_path), "File for %s cover image doesn't exist at "
|
||||
"%s" % (gallery, cover_image_path))
|
||||
|
||||
front_page_galleries_cover.append({
|
||||
"title": gallery_settings["title"],
|
||||
"link": gallery,
|
||||
"sub_title": gallery_settings.get("sub_title", ""),
|
||||
"date": gallery_settings.get("date", ""),
|
||||
"tags": gallery_settings.get("tags", ""),
|
||||
"cover_type": cover_image_type,
|
||||
"cover": cover_image_path,
|
||||
})
|
||||
|
||||
if not os.path.exists(os.path.join("build", gallery)):
|
||||
os.makedirs(os.path.join("build", gallery))
|
||||
|
||||
# this should probably be a factory
|
||||
Image.base_dir = os.path.join(os.getcwd(), gallery)
|
||||
Image.target_dir = os.path.join(os.getcwd(), "build", gallery)
|
||||
|
||||
Video.base_dir = os.path.join(os.getcwd(), gallery)
|
||||
Video.target_dir = os.path.join(os.getcwd(), "build", gallery)
|
||||
|
||||
template_to_render = page_template if gallery_settings.get("static") else gallery_index_template
|
||||
|
||||
index_html = open(os.path.join("build", gallery, "index.html"), "w")
|
||||
|
||||
index_html.write(template_to_render.render(
|
||||
settings=settings,
|
||||
gallery=gallery_settings,
|
||||
Image=Image,
|
||||
Video=Video,
|
||||
link=gallery
|
||||
).encode("Utf-8"))
|
||||
|
||||
if settings["settings"].get("light_mode"):
|
||||
if not os.path.exists(os.path.join("build", gallery, "light")):
|
||||
os.makedirs(os.path.join("build", gallery, "light"))
|
||||
|
||||
if os.path.exists(os.path.join(os.getcwd(), "build", gallery, "light", "static")):
|
||||
shutil.rmtree(os.path.join(os.getcwd(), "build", gallery, "light", "static"))
|
||||
|
||||
shutil.copytree(os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", "light", "static"),
|
||||
os.path.join(os.getcwd(), "build", gallery, "light","static"))
|
||||
|
||||
light_templates_dir = os.path.join(os.path.split(os.path.realpath(__file__))[0], "themes", "light", "templates")
|
||||
light_templates = Environment(loader=FileSystemLoader(light_templates_dir))
|
||||
light_gallery_index_template = light_templates.get_template("gallery-index.html")
|
||||
|
||||
light_template_to_render = light_gallery_index_template
|
||||
|
||||
index_html = open(os.path.join("build", gallery, "light", "index.html"), "w")
|
||||
|
||||
index_html.write(light_template_to_render.render(
|
||||
settings=settings,
|
||||
gallery=gallery_settings,
|
||||
Image=Image,
|
||||
Video=Video,
|
||||
link=gallery
|
||||
).encode("Utf-8"))
|
||||
|
||||
|
||||
front_page_galleries_cover.append(process_directory(gallery, settings, templates))
|
||||
|
||||
if settings["rss"]:
|
||||
feed_xml = open(os.path.join("build", "feed.xml"), "w")
|
||||
|
||||
feed_xml.write(feed_template.render(
|
||||
settings=settings,
|
||||
galleries=reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"]))
|
||||
galleries=reversed(sorted(filter(lambda x: x != {}, front_page_galleries_cover), key=lambda x: x["date"]))
|
||||
).encode("Utf-8"))
|
||||
|
||||
front_page_galleries_cover = reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"]))
|
||||
|
||||
# this should probably be a factory
|
||||
Image.base_dir = os.getcwd()
|
||||
Image.target_dir = os.path.join(os.getcwd(), "build")
|
||||
|
||||
Video.base_dir = os.getcwd()
|
||||
Video.target_dir = os.path.join(os.getcwd(), "build")
|
||||
|
||||
index_html = open(os.path.join("build", "index.html"), "w")
|
||||
|
||||
index_html.write(index_template.render(
|
||||
settings=settings,
|
||||
galleries=front_page_galleries_cover,
|
||||
Image=Image,
|
||||
Video=Video
|
||||
).encode("Utf-8"))
|
||||
build_index(settings, front_page_galleries_cover, templates)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
@ -5,19 +5,9 @@
|
||||
<description>{{ settings.sub_title }}</description>
|
||||
<link>{{ settings.url }}</link>
|
||||
<atom:link href="{{ settings.url }}/feed.xml" rel="self" type="application/rss+xml" />
|
||||
|
||||
{% for gallery in galleries %}
|
||||
{% set absolute_url = settings.url + "/" + gallery.link -%}
|
||||
<item>
|
||||
<title>{{ gallery.title }}</title>
|
||||
<link>{{ absolute_url }}</link>
|
||||
<guid>{{ gallery.link }}</guid>
|
||||
{% if gallery.sub_title -%}
|
||||
<description>{{ gallery.sub_title }}</description>
|
||||
{% endif -%}
|
||||
<pubDate>{{ gallery.date }}</pubDate>
|
||||
</item>
|
||||
{% set absolute_url = settings.url + "/" %}
|
||||
{% include "item.html" %}
|
||||
{% endfor %}
|
||||
|
||||
</channel>
|
||||
</rss>
|
||||
|
16
prosopopee/themes/exposure/templates/item.html
Normal file
16
prosopopee/themes/exposure/templates/item.html
Normal file
@ -0,0 +1,16 @@
|
||||
{% set absolute_url = absolute_url+ gallery.link+"/" -%}
|
||||
<item>
|
||||
<title>{{ gallery.title }}</title>
|
||||
<link>{{ absolute_url }}</link>
|
||||
<guid>{{ gallery.link }}</guid>
|
||||
{% if gallery.sub_title -%}
|
||||
<description>{{ gallery.sub_title }}</description>
|
||||
{% endif -%}
|
||||
<pubDate>{{ gallery.date }}</pubDate>
|
||||
</item>
|
||||
{% for sub_gallery in gallery.sub_gallery %}
|
||||
{% with gallery=sub_gallery %}
|
||||
{% include "item.html" %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
|
@ -5,19 +5,9 @@
|
||||
<description>{{ settings.sub_title }}</description>
|
||||
<link>{{ settings.url }}</link>
|
||||
<atom:link href="{{ settings.url }}/feed.xml" rel="self" type="application/rss+xml" />
|
||||
|
||||
{% for gallery in galleries %}
|
||||
{% set absolute_url = settings.url + "/" + gallery.link -%}
|
||||
<item>
|
||||
<title>{{ gallery.title }}</title>
|
||||
<link>{{ absolute_url }}</link>
|
||||
<guid>{{ gallery.link }}</guid>
|
||||
{% if gallery.sub_title -%}
|
||||
<description>{{ gallery.sub_title }}</description>
|
||||
{% endif -%}
|
||||
<pubDate>{{ gallery.date }}</pubDate>
|
||||
</item>
|
||||
{% set absolute_url = settings.url + "/" %}
|
||||
{% include "item.html" %}
|
||||
{% endfor %}
|
||||
|
||||
</channel>
|
||||
</rss>
|
||||
|
16
prosopopee/themes/material/templates/item.html
Normal file
16
prosopopee/themes/material/templates/item.html
Normal file
@ -0,0 +1,16 @@
|
||||
{% set absolute_url = absolute_url+ gallery.link+"/" -%}
|
||||
<item>
|
||||
<title>{{ gallery.title }}</title>
|
||||
<link>{{ absolute_url }}</link>
|
||||
<guid>{{ gallery.link }}</guid>
|
||||
{% if gallery.sub_title -%}
|
||||
<description>{{ gallery.sub_title }}</description>
|
||||
{% endif -%}
|
||||
<pubDate>{{ gallery.date }}</pubDate>
|
||||
</item>
|
||||
{% for sub_gallery in gallery.sub_gallery %}
|
||||
{% with gallery=sub_gallery %}
|
||||
{% include "item.html" %}
|
||||
{% endwith %}
|
||||
{% endfor %}
|
||||
|
Loading…
x
Reference in New Issue
Block a user