recommended articles ignore bad paths
This commit is contained in:
+10
-6
@@ -1,13 +1,13 @@
|
||||
import datetime, os, re
|
||||
from bottle import error, response, route, run, static_file, template, TEMPLATE_PATH
|
||||
|
||||
# List up to 3 recommended articles for current article
|
||||
def list_rec(page):
|
||||
loc = 'diary/entries/'
|
||||
result = []
|
||||
rec = []
|
||||
comment = ""
|
||||
if isinstance(page, int):
|
||||
# Collect recommended articles from comment line
|
||||
with open('diary/entries/' + str(page)) as f:
|
||||
comment = f.readline()
|
||||
comment = comment.replace('<!--','')
|
||||
@@ -15,14 +15,18 @@ def list_rec(page):
|
||||
comment = comment.replace(' ','')
|
||||
comment = clean(comment)
|
||||
rec = comment.split(',')
|
||||
# Convert into array for template to display
|
||||
for article in rec:
|
||||
path = loc + article
|
||||
data = []
|
||||
with open(path) as f:
|
||||
f.readline()
|
||||
data.append(clean(f.readline().replace('<br>','')))
|
||||
data.append(path)
|
||||
result.append(data)
|
||||
try:
|
||||
with open(path) as f:
|
||||
f.readline()
|
||||
data.append(clean(f.readline().replace('<br>','')))
|
||||
data.append(path)
|
||||
result.append(data)
|
||||
except EnvironmentError:
|
||||
print("No article @ " + path)
|
||||
return result
|
||||
|
||||
# List latest 5 articles as headline links
|
||||
|
||||
@@ -16,8 +16,10 @@
|
||||
<h1>latest</h1>
|
||||
<div class="latest-text">
|
||||
<ul>
|
||||
% for l in latest:
|
||||
<li>	<a href=/{{l[0]}} rel="nofollow">{{!l[1]}}</a></li>
|
||||
% if len(latest) > 0:
|
||||
% print(str(len(latest)))
|
||||
% for l in latest:
|
||||
<li>	<a href=/{{l[0]}} rel="nofollow">{{!l[1]}}</a></li>
|
||||
% end
|
||||
</ul>
|
||||
<br>
|
||||
|
||||
@@ -13,12 +13,14 @@
|
||||
<div class="more"><h1>more like this...</h1></div>
|
||||
% end
|
||||
<div class="rec-box">
|
||||
% for s in recommends:
|
||||
% if len(recommends) > 0:
|
||||
% for s in recommends:
|
||||
<div class="snip">
|
||||
<div class="snippet-title">
|
||||
<a href=/{{s[1]}} rel="nofollow"><b>{{!s[0]}}</b></a>
|
||||
</div>
|
||||
</div>
|
||||
% end
|
||||
% end
|
||||
</div>
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user