Commit a7fc579a authored by Pietro Albini's avatar Pietro Albini

Add basic rendering of the archive

parent 8ca71e1d
# Copyright (c) 2018 Pietro Albini <pietroalbini@ubuntu-it.org>
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
DIR_BUILD = build
DIR_STATIC = www/static
DIR_QUESTIONS = data/questions
DIR_IMAGES = data/images
HTML_TEMPLATE = www/template.html
images = $(patsubst $(DIR_IMAGES)/%,$(DIR_BUILD)/images/%,$(shell find $(DIR_IMAGES) -type f))
questions = $(patsubst $(DIR_QUESTIONS)/%.json,$(DIR_BUILD)/questions/%.html,$(shell find $(DIR_QUESTIONS) -type f))
static = $(patsubst $(DIR_STATIC)/%,$(DIR_BUILD)/static/%,$(shell find $(DIR_STATIC) -type f))
.PHONY: build clean
build: $(images) $(questions) $(static)
clean:
@rm -rf $(DIR_BUILD)
$(DIR_BUILD)/images/%: $(DIR_IMAGES)/%
@mkdir -p $(dir $@)
cp $< $@
$(DIR_BUILD)/questions/%.html: $(DIR_QUESTIONS)/%.json $(HTML_TEMPLATE)
@mkdir -p $(dir $@)
cat $< | www/build-question.py > $@
$(DIR_BUILD)/static/%: $(DIR_STATIC)/%
@mkdir -p $(dir $@)
cp $< $@
#!/usr/bin/env python3
import sys
import json
import dateutil.parser
import jinja2
import markdown
data = json.load(sys.stdin)
template = jinja2.Template(open("www/template.html").read())
print(template.render(**{
"markdown": markdown.markdown,
"question": data,
"date": dateutil.parser.parse,
}))
<!-- Copyright (c) 2016 Luca Lumetti <lumetti.luca@gmail.com> -->
<!-- Released under the GNU-AGPL v3+ license. See LICENSE for details -->
<svg xmlns="http://www.w3.org/2000/svg" width="14" height="14" viewBox="0 0 14 14">
<circle fill="#0f8420" cx="7" cy="7" r="7"/>
<path fill="#fff" d="M6 11 L2.5 8 l1.5,-1.5 L6,8 l4.2,-3.7 1.5,1.5z"/>
</svg>
\ No newline at end of file
img {
max-width: 100%;
display: block;
margin: 1em 0;
}
h1 {
margin-top: 0;
margin-bottom: 0.3em;
font-size: 2em;
}
.text-center {
text-align: center;
}
div.metadata {
display: flex;
justify-content: space-between;
align-items: center;
margin: 1em 0;
}
div.metadata ul.tags {
margin: 0;
padding: 0;
}
div.metadata ul.tags li {
display: inline-block;
padding: 0.3em 1em;
margin-right: 0.3em;
background: #ddd;
border-radius: 9000px;
}
div.metadata div.data {
text-align: right;
}
div.metadata div.data b {
font-size: 1.2em;
}
div.accepted-answer {
width: 975px;
margin: 1em auto 0.5em;
display: flex;
align-items: center;
color: #0f8420;
font-weight: 700;
}
div.accepted-answer img {
display: inline-block;
margin: 0;
margin-right: 0.4em;
}
div.comments {
display: flex;
flex-direction: column;
align-items: flex-end;
}
div.comments div.comment {
width: 80%;
font-size: 0.9em;
margin-top: 1em;
}
div.comments div.comment:first-child {
margin-top: 0;
}
div.comments div.comment div.author {
margin-bottom: 0.1em;
}
div.comments div.comment div.body {
background: #eee;
border-radius: 0.4em;
padding: 1em;
}
div.body > *:first-child {
margin-top: 0 !important;
}
div.body > *:last-child {
margin-bottom: 0 !important;
}
{% macro render_comments(comments) %}
<div class="comments">
{% for comment in comments %}
<div class="comment">
<div class="author">
{% set d = date(comment.created_at) %}
<b>{{ comment.author }}</b> ha commentato
il {{ d.strftime("%d/%m/%Y") }}:
</div>
<div class="body">
{{ markdown(comment.body) }}
</div>
</div>
{% endfor %}
</div>
{% endmacro %}
<!DOCTYPE html>
<html lang="it">
<head>
<meta charset="utf-8">
<title>{{ question.title }}</title>
<!-- Accessibility ubuntu-it -->
<script type="text/javascript" src="https://static.ubuntu-it.org/themes/light/accessibility.min.js"></script>
<script type="text/javascript" src="https://static.ubuntu-it.org/themes/light/cookies.min.js"></script>
<link rel="stylesheet" href="https://static.ubuntu-it.org/fonts/ubuntu/include.min.css">
<link rel="stylesheet" href="https://static.ubuntu-it.org/themes/light/common.min.css">
<link rel="stylesheet" href="/static/chiedi.css">
<link rel="shortcut icon" href="/static/favicon.ico">
<script type="text/javascript">accessibility();</script>
</head>
<body>
<div id="fixed-header">
<!-- Header -->
<div id="header" class="shadowed curved-bottom">
<div class="container">
<ul class="links">
<li><a href="https://www.ubuntu-it.org/supporto">
Supporto di Ubuntu-it
</a></li>
</ul>
<div id="logo">
<div id="ubuntu-it-sites">
<a href="http://www.ubuntu-it.org" target="_blank">web</a>
<a href="http://wiki.ubuntu-it.org" target="_blank">wiki</a>
<a href="http://forum.ubuntu-it.org" target="_blank">forum</a>
<a href="http://chat.ubuntu-it.org" target="_blank">chat</a>
<a href="http://cerca.ubuntu-it.org" target="_blank">cerca</a>
<a href="http://planet.ubuntu-it.org" target="_blank">planet</a>
</div>
<span class="title">ubuntu-it</span>
<span class="description">comunità italiana</span>
</div>
<div class="buttons">
<div id="accessibility" title="Maggiore focus ai contenuti" onclick='accessibility_toggle();'></div>
</div>
</div>
</div>
<!-- Sub Header -->
<div id="subheader">
<div class="container">
<div class="container-inside">
<ul class="links secondary-links">
<li>
Il portale Chiedi è stato chiuso, e stai guardando
una sua copia d'archivio.
<b>Le risposte potrebbero non essere più accurate.</b>
</li>
</ul>
</div>
</div>
</div>
<div id="content">
<div id="content-top"></div>
<div class="container">
<div>
<h1>{{ question.title }}</h1>
<div class="body">
{{ markdown(question.body)|safe }}
</div>
<div class="metadata">
<ul class="tags">
{% for tag in question.tags %}
<li>{{ tag }}</li>
{% endfor %}
</ul>
<div class="data">
{% set d = date(question.created_at) %}
Chiesto il {{ d.strftime("%d/%m/%Y") }} da<br>
<b>{{ question.author }}</b>
</div>
</div>
{{ render_comments(question.comments) }}
</div>
</div>
<div id="content-bottom"></div>
{% for answer in question.answers %}
{% if answer.accepted %}
<div class="accepted-answer">
<img class="accepted" src="/static/accepted.svg">
<span>Risposta accettata:</span>
</div>
{% endif %}
<div id="content-top"></div>
<div class="container">
<div class="answer">
<div class="answer-container">
<div class="body">
{{ markdown(answer.body)|safe }}
</div>
<div class="metadata">
<ul class="tags"></ul>
<div class="data">
{% set d = date(question.created_at) %}
Risposta del {{ d.strftime("%d/%m/%Y") }} di<br>
<b>{{ answer.author }}</b>
</div>
</div>
{{ render_comments(answer.comments) }}
</div>
</div>
</div>
<div id="content-bottom"></div>
{% endfor %}
<div id="footer">
<p class="text-center">
Ubuntu e Canonical sono marchi registrati da Canonical Ltd.
</p>
</div>
</div>
</body>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment