From e58da4dd1ff8ff4aa4e896bb5eb3d6df74764cea Mon Sep 17 00:00:00 2001 From: chimchooree Date: Sun, 4 Oct 2020 18:31:22 -0500 Subject: [PATCH] news on index shows 9 latest headlines as links to their articles --- src/entries/raw/news/100504.html | 1 + src/entries/raw/news/200811.html | 1 + src/entries/raw/news/201004.html | 1 + src/index.py | 27 ++++++++++++++++++--------- src/views/index.tpl | 6 +++++- 5 files changed, 26 insertions(+), 10 deletions(-) create mode 100644 src/entries/raw/news/100504.html create mode 100644 src/entries/raw/news/200811.html create mode 100644 src/entries/raw/news/201004.html diff --git a/src/entries/raw/news/100504.html b/src/entries/raw/news/100504.html new file mode 100644 index 0000000..63266f5 --- /dev/null +++ b/src/entries/raw/news/100504.html @@ -0,0 +1 @@ +ancient text diff --git a/src/entries/raw/news/200811.html b/src/entries/raw/news/200811.html new file mode 100644 index 0000000..85feb50 --- /dev/null +++ b/src/entries/raw/news/200811.html @@ -0,0 +1 @@ +nothing new sorry diff --git a/src/entries/raw/news/201004.html b/src/entries/raw/news/201004.html new file mode 100644 index 0000000..a66bb2d --- /dev/null +++ b/src/entries/raw/news/201004.html @@ -0,0 +1 @@ +1 sample news whoa diff --git a/src/index.py b/src/index.py index 90683c2..efc59c2 100644 --- a/src/index.py +++ b/src/index.py @@ -6,15 +6,24 @@ from bottle import error, route, run, static_file, template # write diary -def make_latest(): - # for article in array (just 5 or something) - # link to webpage - return "latest" +def list_headlines(articles): + head = count_lines('entries/raw/res/head.txt') + result = [] + text = [] + + for article in articles: + path = 'entries/' + article + + with open(path) as f: + text = f.readlines() + + b = [] + b.append(path) + b.append(clean(text[head].replace('
',''), path)) + result.append(b) + return result def list_snippets(articles): - # take articles between 0-4, 5-8, 9-13,...) based on current page - # for each one of those articles, - # snip_article(article) limit = 4 total = len(articles) head = count_lines('entries/raw/res/head.txt') @@ -99,7 +108,7 @@ def error404(error): @route('/') def index(): """home page""" - info = {'css': 'index', 'news': 'News goes here', 'title': 'chimchooree\'s dev space - blessfrey', 'year': datetime.datetime.now()} + info = {'css': 'index', 'news': list_headlines(sort_files(gather_files())[0:10]), 'title': 'chimchooree\'s dev space - blessfrey', 'year': datetime.datetime.now()} return template('index.tpl', info) @route('/game') @@ -122,7 +131,7 @@ def diary2(): def diary(page): """diary page""" assert isinstance(page, int) - info = {'css': 'diary', 'title': 'blessfrey - developer diary', 'year': datetime.datetime.now(), 'snippets': list_snippets(sort_files(gather_files())), 'latest': make_latest(), 'total': len(gather_files()), 'limit': 4, 'cluster': 3, 'page': page} + info = {'css': 'diary', 'title': 'blessfrey - developer diary', 'year': datetime.datetime.now(), 'snippets': list_snippets(sort_files(gather_files())), 'latest': list_headlines(sort_files(gather_files())[0:5]), 'total': len(gather_files()), 'limit': 4, 'cluster': 3, 'page': page} return template('diary.tpl', info) if __name__ == '__main__': diff --git a/src/views/index.tpl b/src/views/index.tpl index 7e5ca37..03edd8d 100644 --- a/src/views/index.tpl +++ b/src/views/index.tpl @@ -14,7 +14,11 @@
.      •        . news ☆            ..   .

- {{news}} +
.            ★            ..             •           .            ☆