embed quoted tweets

This commit is contained in:
Kyle Mahan 2015-12-07 08:52:31 -08:00
parent bca07e2178
commit 6e5038e282
4 changed files with 45 additions and 18 deletions

View file

@ -11,8 +11,11 @@ $(function(){
function clickOlderLink(evt) {
evt.preventDefault();
$.get(this.href, function(result) {
$(".pager").replaceWith(
$("article,.pager", $(result)));
var $newElements = $("article,.pager", $(result));
$(".pager").replaceWith($newElements);
$newElements.each(function () {
twttr.widgets.load(this);
});
attachListeners();
});
}
@ -65,11 +68,11 @@ $(function(){
$("#older-link").off('click').click(clickOlderLink);
$(".micropub-form button[type='submit']").off('click').click(submitMicropubForm);
$(".reply-area.closed").hide();
$("article").off('click').click(function(evt) {
var $target = $(evt.target);
if ($target.closest("form, a, video, audio").length == 0) {
$(".reply-area", this).toggleClass("closed");
$(".reply-area", this).slideToggle(200);
}
@ -89,6 +92,9 @@ $(function(){
$('#unfold-link').text($('#fold>article:not(.reply-context)').length + " New Posts");
$('#unfold-link').off('click').click(clickUnfoldLink);
$('#unfold-link').show();
// load twitter embeds
twttr.widgets.load($('#fold').get(0));
}
// topic will be user:id or feed:id
@ -118,11 +124,11 @@ $(function(){
clickUnfoldLink();
}
});
if (WS_TOPIC) {
webSocketSubscribe(WS_TOPIC);
}
updateTimestamps();
window.setInterval(updateTimestamps, 60 * 1000);

View file

@ -462,10 +462,17 @@ def hentry_to_entry(hentry, feed, backfill, now):
published = hentry.get('published')
updated = hentry.get('updated')
# make sure published timezone aware
if published and hasattr(published, 'tzinfo') and published.tzinfo:
published = published.astimezone(datetime.timezone.utc)\
.replace(tzinfo=None)
if published:
# make sure published is in UTC and strip the timezone
if hasattr(published, 'tzinfo') and published.tzinfo:
published = published.astimezone(datetime.timezone.utc)\
.replace(tzinfo=None)
# convert datetime.date to datetime.datetime
elif not hasattr(published, 'hour'):
published = datetime.datetime(
year=published.year,
month=published.month,
day=published.day)
# retrieved time is now unless we're backfilling old posts
retrieved = now

View file

@ -80,7 +80,6 @@ $("input[type='url']").blur(function() {
}
});
$("input[type='url']").on("invalid", function() {
if (this.value.trim() == '') {
console.log('value is empty');
@ -104,5 +103,9 @@ $("input[type='url']").on("invalid", function() {
}
});
</script>
<!-- load Tweet embeds -->
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
</body>
</html>

View file

@ -573,10 +573,11 @@ def add_preview(content):
# don't add a preview to a post that already has one
return content
instagram_regex = 'https?://instagram.com/p/[\w\-]+/?'
vimeo_regex = 'https?://vimeo.com/(\d+)/?'
youtube_regex = 'https?://(?:www.)youtube.com/watch\?v=([\w\-]+)'
youtube_short_regex = 'https://youtu.be/([\w\-]+)'
instagram_regex = r'https?://(?:www\.)?instagram.com/p/[\w\-]+/?'
vimeo_regex = r'https?://(?:www\.)?vimeo.com/(\d+)/?'
youtube_regex = r'https?://(?:www\.)?youtube.com/watch\?v=([\w\-]+)'
youtube_short_regex = r'https://youtu.be/([\w\-]+)'
twitter_regex = r'https?://(?:www\.)?twitter.com/(\w+)/status/(\d+)'
m = re.search(instagram_regex, content)
if m:
@ -607,9 +608,19 @@ def add_preview(content):
'allowfullscreen></iframe>'
).format(content, youtube_id)
# flatten links
flat = re.sub(r'<a[^>]+href="([^"]*)"[^>]*>[^<]*</a>', r'\1', content)
m = re.search(twitter_regex + '$', flat)
if m:
tweet_url = m.group()
return content + (
'<blockquote class="twitter-tweet" lang="en" data-cards="hidden">'
'<a href="{}"></a></blockquote>'
).format(tweet_url)
return content
@views.app_template_filter()
def proxy_image(url):
proxy_url = flask.current_app.config.get('IMAGEPROXY_URL')
@ -635,8 +646,8 @@ def proxy_image(url):
return (urllib.parse.urljoin(camo_url, digest)
+ '?url=' + urllib.parse.quote_plus(url))
return url
@views.app_template_filter()
def proxy_all(content):
def repl(m):