add page leaderboard, fix issue with spoilers by monkey-patching
This commit is contained in:
parent
78d938e266
commit
f50511759b
2 changed files with 56 additions and 1 deletions
17
app.py
17
app.py
|
|
@ -109,6 +109,10 @@ class StrikethroughPostprocessor(markdown.postprocessors.Postprocessor):
|
||||||
def convert(self, match):
|
def convert(self, match):
|
||||||
return '<del>' + match.group(1) + '</del>'
|
return '<del>' + match.group(1) + '</del>'
|
||||||
|
|
||||||
|
# XXX ugly monkeypatch to make spoilers prevail over blockquotes
|
||||||
|
from markdown.blockprocessors import BlockQuoteProcessor
|
||||||
|
BlockQuoteProcessor.RE = re.compile(r'(^|\n)[ ]{0,3}>(?!!)[ ]?(.*)')
|
||||||
|
|
||||||
### XXX it currently only detects spoilers that are not at the beginning of the line. To be fixed.
|
### XXX it currently only detects spoilers that are not at the beginning of the line. To be fixed.
|
||||||
class SpoilerExtension(markdown.extensions.Extension):
|
class SpoilerExtension(markdown.extensions.Extension):
|
||||||
def extendMarkdown(self, md, md_globals):
|
def extendMarkdown(self, md, md_globals):
|
||||||
|
|
@ -685,6 +689,19 @@ def view_random():
|
||||||
continue
|
continue
|
||||||
return redirect(page.get_url())
|
return redirect(page.get_url())
|
||||||
|
|
||||||
|
@app.route('/p/leaderboard/')
|
||||||
|
def page_leaderboard():
|
||||||
|
headers = {
|
||||||
|
'Cache-Control': 'max-age=180, stale-while-revalidate=1800'
|
||||||
|
}
|
||||||
|
|
||||||
|
pages = []
|
||||||
|
for p in Page.select():
|
||||||
|
score = (p.latest.length >> 10) + p.forward_links.count() + p.back_links.count()
|
||||||
|
pages.append((p, score, p.back_links.count(), p.forward_links.count(), p.latest.length))
|
||||||
|
pages.sort(key = lambda x: (x[1], x[2], x[4], x[3]), reverse = True)
|
||||||
|
|
||||||
|
return render_template('leaderboard.html', pages=pages)
|
||||||
|
|
||||||
@app.route('/<slug:name>/')
|
@app.route('/<slug:name>/')
|
||||||
def view_named(name):
|
def view_named(name):
|
||||||
|
|
|
||||||
38
templates/leaderboard.html
Normal file
38
templates/leaderboard.html
Normal file
|
|
@ -0,0 +1,38 @@
|
||||||
|
{% extends "base.html" %}
|
||||||
|
|
||||||
|
{% block title %}Best pages - {{ app_name }}{% endblock %}
|
||||||
|
|
||||||
|
{% block meta %}
|
||||||
|
<meta name="robots" content="noindex,nofollow" />
|
||||||
|
{% endblock %}
|
||||||
|
|
||||||
|
{% block content %}
|
||||||
|
<h1>Best pages</h1>
|
||||||
|
|
||||||
|
<table>
|
||||||
|
<thead>
|
||||||
|
<tr>
|
||||||
|
<th>#</th>
|
||||||
|
<th>Page Name</th>
|
||||||
|
<th>Score</th>
|
||||||
|
<th><abbr title="Length in bytes">Len</abbr></th>
|
||||||
|
<th><abbr title="Backlinks">BL</abbr></th>
|
||||||
|
<th><abbr title="Forward links">FL</abbr></th>
|
||||||
|
</tr>
|
||||||
|
</thead>
|
||||||
|
<tbody>
|
||||||
|
{% set counters = namespace(row = 0) %}
|
||||||
|
{% for p, score, bklinks, fwlinks, length in pages %}
|
||||||
|
<tr>
|
||||||
|
{% set counters.row = counters.row + 1 %}
|
||||||
|
<th style="text-align: right">{{ counters.row }}</th>
|
||||||
|
<td><a href="{{ p.get_url() }}">{{ p.title }}</a> (#{{ p.id }})</td>
|
||||||
|
<td><strong>{{ score }}</strong></td>
|
||||||
|
<td>{{ length }}</td>
|
||||||
|
<td>{{ bklinks }}</td>
|
||||||
|
<td>{{ fwlinks }}</td>
|
||||||
|
</tr>
|
||||||
|
{% endfor %}
|
||||||
|
</tbody>
|
||||||
|
</table>
|
||||||
|
{% endblock %}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue