embed quoted tweets
This commit is contained in:
parent
bca07e2178
commit
6e5038e282
4 changed files with 45 additions and 18 deletions
|
@ -11,8 +11,11 @@ $(function(){
|
||||||
function clickOlderLink(evt) {
|
function clickOlderLink(evt) {
|
||||||
evt.preventDefault();
|
evt.preventDefault();
|
||||||
$.get(this.href, function(result) {
|
$.get(this.href, function(result) {
|
||||||
$(".pager").replaceWith(
|
var $newElements = $("article,.pager", $(result));
|
||||||
$("article,.pager", $(result)));
|
$(".pager").replaceWith($newElements);
|
||||||
|
$newElements.each(function () {
|
||||||
|
twttr.widgets.load(this);
|
||||||
|
});
|
||||||
attachListeners();
|
attachListeners();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -65,11 +68,11 @@ $(function(){
|
||||||
$("#older-link").off('click').click(clickOlderLink);
|
$("#older-link").off('click').click(clickOlderLink);
|
||||||
$(".micropub-form button[type='submit']").off('click').click(submitMicropubForm);
|
$(".micropub-form button[type='submit']").off('click').click(submitMicropubForm);
|
||||||
$(".reply-area.closed").hide();
|
$(".reply-area.closed").hide();
|
||||||
|
|
||||||
$("article").off('click').click(function(evt) {
|
$("article").off('click').click(function(evt) {
|
||||||
var $target = $(evt.target);
|
var $target = $(evt.target);
|
||||||
if ($target.closest("form, a, video, audio").length == 0) {
|
if ($target.closest("form, a, video, audio").length == 0) {
|
||||||
|
|
||||||
$(".reply-area", this).toggleClass("closed");
|
$(".reply-area", this).toggleClass("closed");
|
||||||
$(".reply-area", this).slideToggle(200);
|
$(".reply-area", this).slideToggle(200);
|
||||||
}
|
}
|
||||||
|
@ -89,6 +92,9 @@ $(function(){
|
||||||
$('#unfold-link').text($('#fold>article:not(.reply-context)').length + " New Posts");
|
$('#unfold-link').text($('#fold>article:not(.reply-context)').length + " New Posts");
|
||||||
$('#unfold-link').off('click').click(clickUnfoldLink);
|
$('#unfold-link').off('click').click(clickUnfoldLink);
|
||||||
$('#unfold-link').show();
|
$('#unfold-link').show();
|
||||||
|
|
||||||
|
// load twitter embeds
|
||||||
|
twttr.widgets.load($('#fold').get(0));
|
||||||
}
|
}
|
||||||
|
|
||||||
// topic will be user:id or feed:id
|
// topic will be user:id or feed:id
|
||||||
|
@ -118,11 +124,11 @@ $(function(){
|
||||||
clickUnfoldLink();
|
clickUnfoldLink();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if (WS_TOPIC) {
|
if (WS_TOPIC) {
|
||||||
webSocketSubscribe(WS_TOPIC);
|
webSocketSubscribe(WS_TOPIC);
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTimestamps();
|
updateTimestamps();
|
||||||
window.setInterval(updateTimestamps, 60 * 1000);
|
window.setInterval(updateTimestamps, 60 * 1000);
|
||||||
|
|
||||||
|
|
|
@ -462,10 +462,17 @@ def hentry_to_entry(hentry, feed, backfill, now):
|
||||||
published = hentry.get('published')
|
published = hentry.get('published')
|
||||||
updated = hentry.get('updated')
|
updated = hentry.get('updated')
|
||||||
|
|
||||||
# make sure published timezone aware
|
if published:
|
||||||
if published and hasattr(published, 'tzinfo') and published.tzinfo:
|
# make sure published is in UTC and strip the timezone
|
||||||
published = published.astimezone(datetime.timezone.utc)\
|
if hasattr(published, 'tzinfo') and published.tzinfo:
|
||||||
.replace(tzinfo=None)
|
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 time is now unless we're backfilling old posts
|
||||||
retrieved = now
|
retrieved = now
|
||||||
|
|
|
@ -80,7 +80,6 @@ $("input[type='url']").blur(function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
$("input[type='url']").on("invalid", function() {
|
$("input[type='url']").on("invalid", function() {
|
||||||
if (this.value.trim() == '') {
|
if (this.value.trim() == '') {
|
||||||
console.log('value is empty');
|
console.log('value is empty');
|
||||||
|
@ -104,5 +103,9 @@ $("input[type='url']").on("invalid", function() {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
|
<!-- load Tweet embeds -->
|
||||||
|
<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|
|
@ -573,10 +573,11 @@ def add_preview(content):
|
||||||
# don't add a preview to a post that already has one
|
# don't add a preview to a post that already has one
|
||||||
return content
|
return content
|
||||||
|
|
||||||
instagram_regex = 'https?://instagram.com/p/[\w\-]+/?'
|
instagram_regex = r'https?://(?:www\.)?instagram.com/p/[\w\-]+/?'
|
||||||
vimeo_regex = 'https?://vimeo.com/(\d+)/?'
|
vimeo_regex = r'https?://(?:www\.)?vimeo.com/(\d+)/?'
|
||||||
youtube_regex = 'https?://(?:www.)youtube.com/watch\?v=([\w\-]+)'
|
youtube_regex = r'https?://(?:www\.)?youtube.com/watch\?v=([\w\-]+)'
|
||||||
youtube_short_regex = 'https://youtu.be/([\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)
|
m = re.search(instagram_regex, content)
|
||||||
if m:
|
if m:
|
||||||
|
@ -607,9 +608,19 @@ def add_preview(content):
|
||||||
'allowfullscreen></iframe>'
|
'allowfullscreen></iframe>'
|
||||||
).format(content, youtube_id)
|
).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
|
return content
|
||||||
|
|
||||||
|
|
||||||
@views.app_template_filter()
|
@views.app_template_filter()
|
||||||
def proxy_image(url):
|
def proxy_image(url):
|
||||||
proxy_url = flask.current_app.config.get('IMAGEPROXY_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)
|
return (urllib.parse.urljoin(camo_url, digest)
|
||||||
+ '?url=' + urllib.parse.quote_plus(url))
|
+ '?url=' + urllib.parse.quote_plus(url))
|
||||||
return url
|
return url
|
||||||
|
|
||||||
|
|
||||||
@views.app_template_filter()
|
@views.app_template_filter()
|
||||||
def proxy_all(content):
|
def proxy_all(content):
|
||||||
def repl(m):
|
def repl(m):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue