Add about page and list of feeds, template parts

This commit is contained in:
mdivecky 2022-08-27 12:48:40 +02:00
parent 1304ef1a83
commit 0157afbf52
9 changed files with 199 additions and 85 deletions

View file

@ -4,9 +4,15 @@ import sqlite3
from flask import Flask, request, render_template
from flask import g
from flask_paginate import Pagination, get_page_parameter
import confuse
DATABASE = "../data/diffs.db"
CONFIG_FILE = "../data/config.yaml"
config = confuse.Configuration('headline', __name__)
config.set_file(CONFIG_FILE)
app = Flask(__name__)
@ -38,7 +44,7 @@ def index():
#flask-paginate
page = request.args.get(get_page_parameter(), type=int, default=1)
pagination = Pagination(page=page, total=diff_count, record_name='diffs')
pagination = Pagination(page=page, total=diff_count, record_name='diffs', css_framework='bootstrap5')
page_skip = pagination.skip
@ -49,8 +55,25 @@ def index():
return render_template('./index.html',
diffs=diffs,
pagination=pagination,
diff_count = diff_count
)
@app.route('/about')
def about():
return render_template('about.html')
@app.route('/feeds')
def feed_list():
feeds = []
for conf in config['feeds']:
feed = {
'rss_source' : str(conf['rss_source']),
'unique_tag' : str(conf['unique_tag']),
'feed_name' : str(conf['name'])
}
feeds.append(feed)
return render_template('feeds.html', feeds=feeds)
if __name__ == "__main__":
app.run(host="0.0.0.0")

View file

@ -1,2 +1,3 @@
flask
flask-paginate
confuse

BIN
view/static/favicon.ico Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 15 KiB

9
view/static/main.css Normal file
View file

@ -0,0 +1,9 @@
body {
margin-bottom: 60px; /* Margin bottom by footer height */
}
.footer {
position: absolute;
bottom: 0;
width: 100%;
}

26
view/templates/about.html Normal file
View file

@ -0,0 +1,26 @@
<!DOCTYPE html>
<html lang="en" class="h100">
<head>
{% include 'parts/head.html' %}
</head>
<body class="d-flex flex-column h-100">
<!-- Begin page content -->
<main class="flex-shrink-0">
<div class="container">
<h1 class="mt-5">Headliner</h1>
<p class="lead">Headliner is monitoring rss feeds of czech news websites for changes in article headlines. Just
because it might be interesting.</p>
<p>See <a href="https://git.nolog.cz/mdivecky/headline">the source code</a>, but be aware that it's not too nice.
Feel free to improve it.</p>
<p>If you want to access the raw data collected by this tool, write us an e-mail, you can find the contact on our
website below.</p>
</div>
</main>
{% include 'parts/footer.html' %}
</body>
</html>

35
view/templates/feeds.html Normal file
View file

@ -0,0 +1,35 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% include 'parts/head.html' %}
</head>
<body>
<div class="container">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>Name</th>
<th>RSS/Atom URL</th>
<th>Unique tag</th>
</tr>
</thead>
<tbody>
{% for feed in feeds %}
<tr>
<td>{{ feed.feed_name }}</td>
<td>{{ feed.rss_source | urlize(target="_blank") }}</td>
<td>{{ feed.unique_tag }}</td>
{% endfor %}
</tbody>
</table>
</div>
</div>
{% include 'parts/footer.html' %}
</body>
</html>

View file

@ -1,38 +1,36 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Headliner</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<style>
/* .expanded {
width: 100%;
} */
<head>
{% include 'parts/head.html' %}
<style>
/* Longer name hidden by default */
span.long {
display: none;
}
/* On hover, hide the short name */
.expanded:hover span.short {
display: none;
}
/* On hover, display the longer name. */
.expanded:hover span.long {
display: block;
}
</style>
</head>
<body>
<div class="container">
<div class="table-responsive">
<table class="table table-hover">
<thead>
<tr>
<th>#</th>
<th>Detection time</th>
<th>Source</th>
<th>Diff</th>
@ -43,7 +41,6 @@ span.long{
<tbody>
{% for diff in diffs %}
<tr>
<td>{{ diff.diff_id }}</td>
<td>{{ diff.diff_time }}</td>
<td><a href='{{ diff.article_url }}' target="_blank">{{ diff.feed_name }}</a></td>
<td>{{ diff.diff_html|safe }}</td>
@ -60,7 +57,18 @@ span.long{
</tbody>
</table>
</div>
<div class="container text-center">
<div class="row">
<div class="col">
{{ pagination.links }}
</div>
<div class="col">
{{ pagination.info }}
</div>
</div>
</div>
</div>
{% include 'parts/footer.html' %}
</body>
</html>

View file

@ -0,0 +1,6 @@
<footer class="footer mt-auto py-3 bg-light">
<div class="container">
<span class="text-muted"> <a href="{{ url_for('index') }}">Headliner</a> | <a
href="{{ url_for('feed_list') }}">Feed list</a> | <a href="{{ url_for('about') }}">About</a></span>
</div>
</footer>

View file

@ -0,0 +1,6 @@
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Headliner</title>
<link rel="shortcut icon" href="{{ url_for('static', filename='favicon.ico') }}">
<link rel="stylesheet" href="{{ url_for('static', filename='main.css') }}">
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-1BmE4kWBq78iYhFldvKuhfTAU6auU8tT94WrHftjDbrCEXSU1oBoqyl2QvZ6jIW3" crossorigin="anonymous">