From 31b8ec72361eff11ab7d3efe602df32dffffaa45 Mon Sep 17 00:00:00 2001 From: seedgou Date: Thu, 15 Nov 2018 01:27:00 +0800 Subject: [PATCH] index page --- app.py | 8 +++++-- game_infos.py | 5 +++++ templates/index-imgs.html | 45 +++++++++++++++++++++++++++++++++++++++ 3 files changed, 56 insertions(+), 2 deletions(-) create mode 100644 templates/index-imgs.html diff --git a/app.py b/app.py index e3801b8..d659b4b 100644 --- a/app.py +++ b/app.py @@ -1,14 +1,18 @@ from flask import Flask from flask import render_template, redirect, url_for -from game_infos import game_infos +from game_infos import game_infos, game_infos_with_cover +import json + +number_to_show_on_index = 42 app = Flask(__name__) @app.route('/') def index(): - return render_template('index.html', games=game_infos['games']) + game_infos_to_show = game_infos_with_cover[:number_to_show_on_index - 1] + return render_template('index-imgs.html', game_infos=game_infos_to_show, game_count=len(game_infos['games'])) @app.route('/about') diff --git a/game_infos.py b/game_infos.py index 98c2683..0ba320e 100644 --- a/game_infos.py +++ b/game_infos.py @@ -7,3 +7,8 @@ root = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) with open(os.path.join(root, 'static', 'games', 'games.json'), encoding='utf8') as f: content = f.read() game_infos = json.loads(content) + +game_infos_with_cover = list() +for identifier, game_info in game_infos['games'].items(): + if 'coverFilename' in game_info.keys(): + game_infos_with_cover.append(game_info) diff --git a/templates/index-imgs.html b/templates/index-imgs.html new file mode 100644 index 0000000..59e890f --- /dev/null +++ b/templates/index-imgs.html @@ -0,0 +1,45 @@ +{% extends 'base.html' %} + +{% block main %} +
+ {% if game_infos %} + {% for game_info in game_infos %} +
+ + {{ game_info['name']['zh-Hans'] }} + +
+
{{ game_info['name']['zh-Hans'] }}
+
+
+ {% endfor %} + {% endif %} +
+
+
更多游戏
+
目前共有 {{ game_count }} 款游戏
+ 游戏列表 +
+
+
+
+
+{% endblock %} + +{% block footer %} + + + +{% endblock %}