Skip to content

Commit

Permalink
Added webactions
Browse files Browse the repository at this point in the history
  • Loading branch information
kylewm committed May 15, 2014
1 parent 47083d3 commit 4ceb0e7
Show file tree
Hide file tree
Showing 7 changed files with 59 additions and 14 deletions.
4 changes: 4 additions & 0 deletions redwind/static/css/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,10 @@ nav li {
float: right;
}

.webactions {
float: right;
}

form .heading {
width: 150px;
display: inline-block;
Expand Down
2 changes: 2 additions & 0 deletions redwind/templates/_like_context.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
{% if post.like_contexts %}
<div class="like-context">
{% for like in post.like_contexts %}

<i class="fa fa-thumbs-up"></i> Liked
<a class="u-like u-like-of" href="{{ like.permalink }}">
{% if like.title or like.content %}
Expand All @@ -9,6 +10,7 @@
{{ like.permalink | prettify_url }}
{% endif %}
</a>

{% endfor %}
</div>
{% endif %}
21 changes: 20 additions & 1 deletion redwind/templates/_single_post_links.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,25 @@
{% endif %}

<a class="u-url" href="{{ post.permalink }}"><time class="dt-published" datetime="{{ post.pub_date | isotime }}">{{ post.pub_date | human_time }}</time></a>

{% if post.location %}
at <a href="http://www.openstreetmap.org/#map=18/{{post.location.latitude}}/{{post.location.longitude}}">{{post.location.name or 'Unnamed place'}}</a>
at <a class="p-location h-geo" href="http://www.openstreetmap.org/#map=18/{{post.location.latitude}}/{{post.location.longitude}}" title="{{post.location.latitude}},{{post.location.longitude}}">
<data class="p-latitude" value="{{post.location.latitude}}"></data>
<data class="p-longitude" value="{{post.location.longitude}}"></data>
<span class="p-name">
{{post.location.name or 'an unnamed location'}}
</span>
</a>
{% endif %}

<div class="webactions">
<action do="reply" with="{{post.permalink}}">
<a href="https://twitter.com/intent/tweet?in_reply_to={{post.tweet_id}}">reply</a>
</action>
<action do="repost" with="{{post.permalink}}">
<a href="https://twitter.com/intent/retweet?tweet_id={{post.tweet_id}}">retweet</a>
</action>
<action do="favorite" with="{{post.permalink}}">
<a href="https://twitter.com/intent/favorite?tweet_id={{post.tweet_id}}">favorite</a>
</action>
</div>
2 changes: 1 addition & 1 deletion redwind/templates/base.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,6 @@
{% if current_user.is_anonymous() %}
<form id="indie_auth_form" action="http://indieauth.com/auth" method="get">
<input id="indie_auth_url" type="text" name="me" placeholder="yourdomain.com" />
<!-- <input id="indie_auth_url" type="hidden" name="me" value="http://kylewm.com"/> -->
<button id="sign_in_button" type="submit">Sign In</button>
<input type="hidden" name="redirect_uri" value="{{ url_for('indieauth', _external=True) }}" />
</form>
Expand All @@ -59,6 +58,7 @@
<li><span class="site-name">kylewm.com</span></li>
<li><a href="{{ url_for('index') }}">stream</a></li>
<li><a href="{{ url_for('articles') }}">articles</a></li>
<li><a href="{{ url_for('everything') }}">everything</a></li>
<li><a href="{{ url_for('archive') }}">archive</a></li>
</ul>

Expand Down
2 changes: 1 addition & 1 deletion redwind/templates/share_on_twitter.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@

<textarea name="preview" id="preview" style="height: 75px; width:100%; background-color: #eeeeff">{% if post.title %}
{{ post.title }} {{ post.permalink }}{% else %}
{{ post.content | format_markdown_as_text }}{% endif %}
{{ post.content | format_markdown_as_text(link_twitter_names=False) }}{% endif %}
</textarea><br/>

<span size="8" type="text" name="char_count" id="char_count">&nbsp;</span>
Expand Down
7 changes: 4 additions & 3 deletions redwind/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,12 @@ def download_resource(url, path):
LINK_REGEX = r'\b(?<!=.)https?://([a-zA-Z0-9/\.\-_:%?@$#&=]+)'


def autolink(plain):
def autolink(plain, twitter_names=True):
plain = re.sub(LINK_REGEX,
r'<a href="\g<0>">\g<1></a>', plain)
plain = re.sub(TWITTER_USERNAME_REGEX,
r'<a href="http://twitter.com/\g<1>">\g<0></a>', plain)
if twitter_names:
plain = re.sub(TWITTER_USERNAME_REGEX,
r'<a href="http://twitter.com/\g<1>">\g<0></a>', plain)
return plain


Expand Down
35 changes: 27 additions & 8 deletions redwind/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,14 @@ def get_share_preview(self):
text += '<div>' + preview + '</div>'
return text

@property
@reraise_attribute_errors
def tweet_id(self):
for url in self.syndication:
match = TWITTER_RE.match(url)
if match:
return match.group(2)

@property
@reraise_attribute_errors
def reply_contexts(self):
Expand Down Expand Up @@ -242,7 +250,13 @@ def __init__(self, url):
blob = archiver.load_json_from_archive(url)
if not blob:
return
self.entry = mf2util.interpret(blob, url)

try:
self.entry = mf2util.interpret(blob, url)
except:
app.logger.exception('error interpreting {}', url)
return

if not self.entry:
return

Expand Down Expand Up @@ -284,7 +298,12 @@ def __init__(self, post, url):
else:
target_urls = []

self.entry = mf2util.interpret_comment(blob, url, target_urls)
try:
self.entry = mf2util.interpret_comment(blob, url, target_urls)
except:
app.logger.exception('error interpreting {}', url)
return

if not self.entry:
return

Expand Down Expand Up @@ -710,8 +729,8 @@ def bleach_html(html):


@app.template_filter('format_markdown_as_text')
def format_markdown_as_text(content, remove_imgs=True):
html = markdown_filter(content)
def format_markdown_as_text(content, remove_imgs=True, link_twitter_names=True):
html = markdown_filter(content, link_twitter_names=link_twitter_names)
return format_as_text(html, remove_imgs)


Expand All @@ -734,19 +753,19 @@ def format_as_text(html, remove_imgs=True):


@app.template_filter('markdown')
def markdown_filter(data):
def markdown_filter(data, link_twitter_names=True):
from markdown import markdown
from smartypants import smartypants

result = markdown(data, extensions=['codehilite', 'fenced_code'])
result = util.autolink(result)
result = util.autolink(result, twitter_names=link_twitter_names)
result = smartypants(result)
return result


@app.template_filter('autolink')
def autolink(plain):
return util.autolink(plain)
def autolink(plain, twitter_names=True):
return util.autolink(plain, twitter_names)


@app.template_filter('prettify_url')
Expand Down

0 comments on commit 4ceb0e7

Please sign in to comment.