Permalink
Browse files

Added Reader's corner

  • Loading branch information...
mhlakhani committed Feb 8, 2014
1 parent c1ff554 commit 30d97b721e6ded25795b18d018b554bf548d0038
Showing with 174 additions and 7 deletions.
  1. +2 −0 .gitignore
  2. +68 −2 config.py
  3. +23 −0 content/readerscornerhome.haml
  4. +64 −0 content/readerscornerpage.haml
  5. +17 −5 templates/base.haml
@@ -15,3 +15,5 @@ sync.sh
cache
env/*
*.pyc
filterdata.py
links.txt
@@ -1,5 +1,65 @@
import sys
import re
from functools import partial
from collections import OrderedDict

def namefilter(forbidden_urls, forbidden_domains, names, extra_names, whitelist, nameset_ignores, placeholders, entry):

link = entry.get('link')
if link is None:
return None

if entry['type'] == 'photo' or entry['type'] == 'status':
return None

names = names + extra_names
nameset = set(s for s in ' '.join(names).split(' ') if len(s) > 2) - nameset_ignores

for url in forbidden_urls:
if link.find(url) != -1:
return None

if 'caption' in entry:
for domain in forbidden_domains:
if entry['caption'].find(domain) != -1:
return None

holder = 0

message = entry.get('message', '')
if message is not None:
for name in names:
if message.find(name) != -1:
#print('Removing name %s' % name)
message = message.replace(name, placeholders[holder])
holder = holder + 1
for name in nameset:
if message.find(name) != -1:
fp = False
for placeholder in placeholders:
if message.find(placeholder) != -1 and placeholder.find(name) != -1:
fp = True
st = re.findall("[\w']+|[.,!?;]", message)
if name not in st:
fp = True
if not fp and entry['id'] not in whitelist:
message = message.replace(name, placeholders[holder])
holder = holder + 1
#print('Removing name substring match %s in %s' % (name, entry['id']))
entry['message'] = message

return entry

try:
sys.path.insert(0, '.')
import filterdata
_filter = partial(namefilter, filterdata.forbidden_urls, filterdata.forbidden_domains, filterdata.names, filterdata.extra_names, filterdata.whitelist, filterdata.nameset_ignores, filterdata.placeholders)
except Exception:
print('WARNING: Could not import filter data, ReadersCorner may contain personal info! ABORTING!')
import traceback
traceback.print_exc()
sys.exit(1)

routes = {
'index' : '/',
'blogindex' : '/blog/',
@@ -8,11 +68,14 @@
'sitemap' : '/sitemap.xml',
'post' : '/blog/{year}/{month}/{slug}/',
'tag' : '/blog/tag/{tag}/',
'resume' : '/resume/'
'resume' : '/resume/',
'readerscornerhome' : '/readers-corner/',
'readerscornerpage' : '/readers-corner/{year}/{month}/'
}

base_deps = ['templates/base.haml', 'templates/macros.haml']
post_deps = ['templates/base.haml', 'templates/macros.haml', 'templates/blogpost.haml', 'tags']
readers_corner_deps = base_deps + ['readerscorner', 'readerscornersidebar']

sources = [
('Page', 'content/index.haml', {}, base_deps),
@@ -26,6 +89,8 @@
('StaticContent', 'static/js/*.js', {}, []),
('StaticContent', 'static/pdf/*.pdf', {}, []),
('StaticContent', 'static/img/*/*/*', {}, []),
('Page', 'content/readerscornerhome.haml', {'readerscornersidebar' : 'sidebar'}, readers_corner_deps),
('ReadersCornerPage', 'content/readerscornerpage.haml', {'readerscornersidebar' : 'sidebar', 'readerscorner' : 'readerscorner'}, readers_corner_deps),
]

processors = [
@@ -37,7 +102,8 @@
'filters' : [], 'reverse' : True, 'exclude' : 'featuredposts'}),
('PostArchives', {'key' : 'blogarchives'}),
('RSSFeed', {'key' : 'rss', 'count' : 5, 'title' : "Hasnain Lakhani's Blog", 'link': 'http://mhlakhani.com/blog/', 'description': "Hasnain Lakhani's Blog", 'sortkey': 'date'}),
('Sitemap', {'key' : 'sitemap', 'root' : 'http://mhlakhani.com'})
('Sitemap', {'key' : 'sitemap', 'root' : 'http://mhlakhani.com'}),
('ReadersCorner', {'key' : 'readerscorner', 'filename' : 'links.txt', 'sidebarkey' : 'readerscornersidebar', 'route' : 'readerscornerpage', 'filter' : _filter})
]

data = {
@@ -0,0 +1,23 @@
{
"route": "readerscornerhome",
"title": "Hasnain Lakhani's Blog - Reader's Corner",
"readerscornerpage": true
}

-extends "base.haml"
-block content

.row-fluid

%h1 << Reader's Corner

%p
This is a collection of links that I've shared over the years (along with my comments where present), as an easily browsable archive.

-for (header, links) in sidebar.items()
%h2 << {{ header }}

%ul.nav.nav-pills
-for (blurb,link) in links.items()
%li
%a href="{{ link }}" << {{ blurb }}
@@ -0,0 +1,64 @@
{
"route": "readerscornerpage",
"title": "Hasnain Lakhani's Blog - Reader's Corner",
"readerscornerpage": true,
"monthnames": ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]
}

-extends "base.haml"
-block content

.row-fluid

%h1 << Reader's Corner for {{ monthname }} {{ year }}
.pagination
%ul
-if (year+1) in readerscorner
%li
%a.permalink href="{{ url_for("readerscornerpage", year=year+1, month=1) }}"
&laquo; {{ year + 1 }}
-for (month, ac) in readerscorner[year].items()
%li class="{% if monthnames[month-1] == monthname %} active {% endif %}"
%a.permalink href="{{ url_for("readerscornerpage", year=year, month=month) }}"
{{ monthnames[month-1] }}
-if (year-1) in readerscorner
%li
%a.permalink href="{{ url_for("readerscornerpage", year=year-1, month=12) }}"
{{ year - 1 }} &raquo;

-for (day, dayarchive) in montharchive.items()
%h2 << {{ monthname }} {{ day }}, {{ year }}
%br
-for entry in dayarchive
.alert.alert-info
%h3
%a.permalink href="{{ entry.link }}" title="Full article" rel="nofollow" << &raquo; {{ entry.name }}
-if entry.caption
%p << {{ entry.caption }}
-if entry.description
%p
%em << {{ entry.description }}

-if entry.message
%blockquote
%p << {{ entry.message | replace("\n", "<br>") }}

-if not loop.last
%br

%br
.pagination
%ul
-if (year+1) in readerscorner
%li
%a.permalink href="{{ url_for("readerscornerpage", year=year+1, month=1) }}"
&laquo; {{ year + 1 }}
-for (month, ac) in readerscorner[year].items()
%li class="{% if monthnames[month-1] == monthname %} active {% endif %}"
%a.permalink href="{{ url_for("readerscornerpage", year=year, month=month) }}"
{{ monthnames[month-1] }}
-if (year-1) in readerscorner
%li
%a.permalink href="{{ url_for("readerscornerpage", year=year-1, month=12) }}"
{{ year - 1 }} &raquo;

@@ -35,11 +35,23 @@
%a href="/" << Home
%li
%a href="{{ url_for("blogindex") }}" << Blog
-else
%li
%a href="/" << Home
%li.active
%a href="{{ url_for("blogindex") }}" << Blog
%a href="{{ url_for("readerscornerhome") }}" << Reader's Corner
-else
-if readerscornerpage
%li
%a href="/" << Home
%li
%a href="{{ url_for("blogindex") }}" << Blog
%li.active
%a href="{{ url_for("readerscornerhome") }}" << Reader's Corner
-else
%li
%a href="/" << Home
%li.active
%a href="{{ url_for("blogindex") }}" << Blog
%li
%a href="{{ url_for("readerscornerhome") }}" << Reader's Corner

.container-fluid
.row-fluid
@@ -60,4 +72,4 @@
%hr

%footer
%p << &copy; Muhammad Hasnain Lakhani 2013
%p << &copy; Muhammad Hasnain Lakhani 2014

0 comments on commit 30d97b7

Please sign in to comment.