add external link in menu and more easier config

This commit is contained in:
Adrien Beudin 2016-02-13 11:21:51 +01:00
parent 4bb171b91a
commit 55def9c4a8
8 changed files with 57 additions and 60 deletions

View File

@ -58,44 +58,30 @@ sub_title: it's a scary place, don't go there
```
#### Menu
It is possible to add a menu to your homepage that links to static pages. To do so, add a `menu` key to your `settings.yaml`, for example:
```yaml
menu:
name: "About"
type: "page"
url: "about"
- name: "My first gallery"
type: "folder"
url: "first_gallery"
- name: "Twitter"
type: "external"
url: "http://twitter.com"
- about: "About"
- first_gallery: "My first gallery"
- http://twitter.com: "Twitter"
```
You can use 3 type of item in the menu:
* page
* folder
* external
For page, the url is the files (without the `.yaml`)
For folder, the url is the name of the folder (like first_gallery in exemple)
And for the external, the url is the full url of the website. You can
use it too for make home in the menu.
So, here, you'll need to create a ``about.yaml`` files in the root directory.
Their content are similar to galleries (see [bellow](#gallery-settingsyaml)).
For example, this could be the content of `about.yaml`:
For example, this could be the content of `settings.yaml` in `about` folder:
```yaml
title: "About"
static: true
public: false
sections:
- type: text
text: Some text, HTML <b>is allowed</b>.
```
The `static` option is use it for don't need to give date and cover at the static page.
If you don't want see the page in front page you can use the `public` option.
### Gallery settings.yaml
This settings.yaml will describe:

View File

@ -1,5 +0,0 @@
title: "Menu 1"
sections:
- 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 »

View File

@ -0,0 +1,6 @@
title: "About"
static: true
public: false
sections:
- type: text
text: Some text, HTML <b>is allowed</b>.

View File

@ -149,11 +149,11 @@ def main():
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")))
error(gallery_settings.get("cover"), "You should specify a path to a cover picture in %s" % (os.path.join(gallery, "settings.yaml")))
cover_image_path = os.path.join(gallery, gallery_settings["cover"])
error(os.path.exists(cover_image_path), "File for %s cover image doesn't exists at %s" % (gallery, cover_image_path))
if gallery_settings.get("public", True):
error(gallery_settings.get("cover"), "You should specify a path to a cover picture in %s" % (os.path.join(gallery, "settings.yaml")))
cover_image_path = os.path.join(gallery, gallery_settings["cover"])
error(os.path.exists(cover_image_path), "File for %s cover image doesn't exists at %s" % (gallery, cover_image_path))
gallery_title = gallery_settings["title"]
gallery_sub_title = gallery_settings.get("sub_title", "")
@ -176,17 +176,14 @@ def main():
# 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)
open(os.path.join("build", gallery, "index.html"), "w").write(gallery_index_template.render(settings=settings, gallery=gallery_settings, Image=Image).encode("Utf-8"))
if gallery_settings.get("static") == True:
open(os.path.join("build", gallery, "index.html"), "w").write(page_template.render(settings=settings, gallery=gallery_settings, Image=Image).encode("Utf-8"))
else:
open(os.path.join("build", gallery, "index.html"), "w").write(gallery_index_template.render(settings=settings, gallery=gallery_settings, Image=Image).encode("Utf-8"))
front_page_galleries_cover = reversed(sorted(front_page_galleries_cover, key=lambda x: x["date"]))
for item in settings.get("menu"):
if item.get("type") == "page":
file_name = item.get("url")
error(os.path.exists(os.path.join(os.getcwd(), file_name + ".yaml")), "I can't find a " + file_name + ".yaml in the current working directory as specified by your menu description in your root settings.yaml")
open(os.path.join("build", file_name + ".html"), "w").write(page_template.render(settings=settings, pages=yaml.safe_load(open(file_name + ".yaml", "r")), galleries=front_page_galleries_cover).encode("Utf-8"))
Image.base_dir = os.getcwd()
Image.target_dir = os.path.join(os.getcwd(), "build")

View File

@ -2,8 +2,6 @@
<html>
<head>
<meta charset="UTF-8">
<link type="text/css" rel="stylesheet" href="static/css/fonts.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="static/css/style.css" media="screen,projection"/>
{% block css %}
{% endblock %}
@ -15,7 +13,8 @@
<body>
<div class="gallery-header">
<img id="logo" src="static/img/logo.svg" />
{% block logo %}
{% endblock %}
<h1>{{ settings.title }}</h1>
{% if settings.sub_title -%}<h4>{{ settings.sub_title }}</h4>{% endif -%}
<hr>

View File

@ -1,5 +1,14 @@
{% extends "base.html" %}
{% block css %}
<link type="text/css" rel="stylesheet" href="static/css/fonts.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="static/css/style.css" media="screen,projection"/>
{% endblock %}
{% block logo %}
<img id="logo" src="static/img/logo.svg" />
{% endblock %}
{% block content %}
<div class="galleries-grid">
{% for galleries_line in galleries|reverse|batch(3)|reverse %}

View File

@ -2,17 +2,16 @@
<div class="nav-wrapper">
<ul>
{%- for line in settings.menu -%}
{%- if line.type == "folder" -%}
{%- set file_name = line.url+"/" -%}
{%- elif line.type == "external" -%}
{%- set file_name = line.url -%}
{%- else -%}
{%- set file_name = line.url+".html" -%}
{%- endif -%}
{% set file_name, menu_name = line.items()[0] %}
{% if file_name.startswith('http') %}
{% set file_name = file_name %}
{% elif gallery %}
{% set file_name = "../"+file_name %}
{%- endif -%}
{%- if loop.first -%}
<li><a href={{ file_name }} class=first-item-menu>{{ line.name }}</a></li>
<li><a href={{ file_name }} class=first-item-menu>{{ menu_name }}</a></li>
{% else %}
<li><a href={{ file_name }} class=item-menu>{{ line.name }}</a></li>
<li><a href={{ file_name }} class=item-menu>{{ menu_name }}</a></li>
{%- endif -%}
{%- endfor -%}
</ul>

View File

@ -1,26 +1,32 @@
{% extends "base.html" %}
{% block css %}
<link type="text/css" rel="stylesheet" href="static/css/style-page.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="../static/css/fonts.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="../static/css/style.css" media="screen,projection"/>
<link type="text/css" rel="stylesheet" href="../static/css/style-page.css" media="screen,projection"/>
{% endblock %}
{% block logo %}
<img id="logo" src="../static/img/logo.svg" />
{% endblock %}
{% block content %}
<section class="text">
<h2>{{ pages.title }}</h2>
<h2>{{ gallery.title }}</h2>
</section>
{% for section in pages.sections %}
{% for section in gallery.sections %}
{% include "sections/" + section.type + ".html" %}
{% endfor %}
<div class="back-to-home">
<hr>
<a href="./index.html">
<div id="logo" src="static/img/logo.svg"/>
<a href="../index.html">
<div id="logo" src="../static/img/logo.svg"/>
HOME
</div>
</a>
</div>
<script type="text/javascript" src="static/js/jquery-2.1.4.min.js" charset="utf-8"></script>
<script type="text/javascript" src="../static/js/jquery-2.1.4.min.js" charset="utf-8"></script>
{% endblock %}