mirror of
https://github.com/viq/NewsBlur.git
synced 2025-04-13 09:38:09 +00:00
Fixing relative image urls to be absolute urls. Looks like a BeautifulSoup4 upgrade didn't catch the new attrs syntax. Also fixing bookmarklet loading wrong JS/CSS in development.
This commit is contained in:
parent
855a96d633
commit
6095bd709d
9 changed files with 2349 additions and 1870 deletions
4
.vscode/settings.json
vendored
4
.vscode/settings.json
vendored
|
@ -8,7 +8,7 @@
|
|||
],
|
||||
"python.pythonPath": "~/.virtualenvs/newsblur3/bin/python",
|
||||
"editor.bracketPairColorization.enabled": true,
|
||||
"editor.guides.bracketPairs":"active",
|
||||
"editor.guides.bracketPairs": "active",
|
||||
"git.ignoreLimitWarning": true,
|
||||
"search.exclude": {
|
||||
"clients": true,
|
||||
|
@ -27,7 +27,6 @@
|
|||
"docker/volumes": true,
|
||||
"requirements.txt": true, // It's just a symlink to config/requirements.txt, which has git history
|
||||
},
|
||||
"python.formatting.provider": "black",
|
||||
"python.formatting.blackArgs": [
|
||||
"--line-length=110",
|
||||
"--skip-string-normalization"
|
||||
|
@ -37,4 +36,5 @@
|
|||
},
|
||||
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:1.9.1}",
|
||||
"C_Cpp.default.configurationProvider": "nrf-connect",
|
||||
"editor.formatOnSave": false,
|
||||
}
|
||||
|
|
|
@ -206,6 +206,11 @@ def check_share_on_site(request, token):
|
|||
usersub = None
|
||||
message = None
|
||||
user = None
|
||||
users = {}
|
||||
your_story = None
|
||||
same_stories = None
|
||||
other_stories = None
|
||||
previous_stories = None
|
||||
|
||||
if not story_url:
|
||||
code = -1
|
||||
|
@ -239,34 +244,34 @@ def check_share_on_site(request, token):
|
|||
usersub = UserSubscription.objects.filter(user=user, feed=feed)
|
||||
except UserSubscription.DoesNotExist:
|
||||
usersub = None
|
||||
feed_id = feed and feed.pk
|
||||
your_story, same_stories, other_stories = MSharedStory.get_shared_stories_from_site(feed_id,
|
||||
user_id=user_profile.user.pk, story_url=story_url)
|
||||
previous_stories = MSharedStory.objects.filter(user_id=user_profile.user.pk).order_by('-shared_date').limit(3)
|
||||
previous_stories = [{
|
||||
"user_id": story.user_id,
|
||||
"story_title": story.story_title,
|
||||
"comments": story.comments,
|
||||
"shared_date": story.shared_date,
|
||||
"relative_date": relative_timesince(story.shared_date),
|
||||
"blurblog_permalink": story.blurblog_permalink(),
|
||||
} for story in previous_stories]
|
||||
if user:
|
||||
feed_id = feed and feed.pk
|
||||
your_story, same_stories, other_stories = MSharedStory.get_shared_stories_from_site(feed_id,
|
||||
user_id=user.pk, story_url=story_url)
|
||||
previous_stories = MSharedStory.objects.filter(user_id=user.pk).order_by('-shared_date').limit(3)
|
||||
previous_stories = [{
|
||||
"user_id": story.user_id,
|
||||
"story_title": story.story_title,
|
||||
"comments": story.comments,
|
||||
"shared_date": story.shared_date,
|
||||
"relative_date": relative_timesince(story.shared_date),
|
||||
"blurblog_permalink": story.blurblog_permalink(),
|
||||
} for story in previous_stories]
|
||||
|
||||
user_ids = set([user_profile.user.pk])
|
||||
for story in same_stories:
|
||||
user_ids.add(story['user_id'])
|
||||
for story in other_stories:
|
||||
user_ids.add(story['user_id'])
|
||||
|
||||
users = {}
|
||||
profiles = MSocialProfile.profiles(user_ids)
|
||||
for profile in profiles:
|
||||
users[profile.user_id] = {
|
||||
"username": profile.username,
|
||||
"photo_url": profile.photo_url,
|
||||
}
|
||||
|
||||
logging.user(user_profile.user, "~BM~FCChecking share from site: ~SB%s" % (story_url),
|
||||
user_ids = set([user_profile.user.pk])
|
||||
for story in same_stories:
|
||||
user_ids.add(story['user_id'])
|
||||
for story in other_stories:
|
||||
user_ids.add(story['user_id'])
|
||||
|
||||
profiles = MSocialProfile.profiles(user_ids)
|
||||
for profile in profiles:
|
||||
users[profile.user_id] = {
|
||||
"username": profile.username,
|
||||
"photo_url": profile.photo_url,
|
||||
}
|
||||
|
||||
logging.user(user, "~BM~FCChecking share from site: ~SB%s" % (story_url),
|
||||
request=request)
|
||||
|
||||
response = HttpResponse(callback + '(' + json.encode({
|
||||
|
@ -285,12 +290,12 @@ def check_share_on_site(request, token):
|
|||
|
||||
return response
|
||||
|
||||
@required_params('story_url', 'comments', 'title')
|
||||
@required_params('story_url')
|
||||
def share_story(request, token=None):
|
||||
code = 0
|
||||
story_url = request.POST['story_url']
|
||||
comments = request.POST['comments']
|
||||
title = request.POST['title']
|
||||
comments = request.POST.get('comments', "")
|
||||
title = request.POST.get('title', None)
|
||||
content = request.POST.get('content', None)
|
||||
rss_url = request.POST.get('rss_url', None)
|
||||
feed_id = request.POST.get('feed_id', None) or 0
|
||||
|
@ -333,10 +338,12 @@ def share_story(request, token=None):
|
|||
content = lxml.html.fromstring(content)
|
||||
content.make_links_absolute(story_url)
|
||||
content = lxml.html.tostring(content)
|
||||
else:
|
||||
|
||||
if not content or not title:
|
||||
importer = TextImporter(story=None, story_url=story_url, request=request, debug=settings.DEBUG)
|
||||
document = importer.fetch(skip_save=True, return_document=True)
|
||||
content = document['content']
|
||||
if not content:
|
||||
content = document['content']
|
||||
if not title:
|
||||
title = document['title']
|
||||
|
||||
|
|
|
@ -225,9 +225,9 @@ class TextImporter:
|
|||
|
||||
content = str(soup)
|
||||
|
||||
images = set([img['src'] for img in soup.findAll('img') if 'src' in img])
|
||||
images = set([img.attrs['src'] for img in soup.findAll('img') if 'src' in img.attrs])
|
||||
for image_url in images:
|
||||
abs_image_url = urljoin(self.story.story_permalink, image_url)
|
||||
abs_image_url = urljoin(self.story_url, image_url)
|
||||
content = content.replace(image_url, abs_image_url)
|
||||
|
||||
return content
|
||||
|
@ -242,9 +242,11 @@ class TextImporter:
|
|||
headers["content-type"] = "application/json"
|
||||
headers["x-api-key"] = mercury_api_key
|
||||
domain = Site.objects.get_current().domain
|
||||
protocol = "https"
|
||||
if settings.DOCKERBUILD:
|
||||
domain = 'haproxy'
|
||||
url = f"https://{domain}/rss_feeds/original_text_fetcher?url={url}"
|
||||
protocol = "http"
|
||||
url = f"{protocol}://{domain}/rss_feeds/original_text_fetcher?url={url}"
|
||||
|
||||
try:
|
||||
r = requests.get(url, headers=headers, timeout=15)
|
||||
|
|
|
@ -320,16 +320,12 @@
|
|||
margin-left: 0;
|
||||
width: 220px;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-comment-submit.NB-disabled,
|
||||
.NB-bookmarklet .NB-bookmarklet-save.NB-disabled {
|
||||
padding: 14px 0 0;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-comment-submit .NB-bookmarklet-accept,
|
||||
.NB-bookmarklet .NB-bookmarklet-save .NB-bookmarklet-accept {
|
||||
.NB-bookmarklet .NB-bookmarklet-save-button .NB-bookmarklet-accept {
|
||||
padding: 0 12px;
|
||||
}
|
||||
.NB-bookmarklet .NB-bookmarklet-comment-submit .NB-bookmarklet-accept img,
|
||||
.NB-bookmarklet .NB-bookmarklet-save .NB-bookmarklet-accept img {
|
||||
.NB-bookmarklet .NB-bookmarklet-save-button .NB-bookmarklet-accept img {
|
||||
vertical-align: top;
|
||||
margin: 0;
|
||||
}
|
||||
|
@ -488,4 +484,4 @@
|
|||
.NB-bookmarklet .NB-bookmarklet-side {
|
||||
width: 90%;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
4086
media/js/vendor/readability-1.7.1.modified.js
vendored
4086
media/js/vendor/readability-1.7.1.modified.js
vendored
File diff suppressed because it is too large
Load diff
|
@ -106,7 +106,6 @@ javascripts:
|
|||
- js/newsblur/payments/stripe_form.js
|
||||
bookmarklet:
|
||||
- js/vendor/jquery-3.6.0.min.js
|
||||
# - js/vendor/jquery.migrate-*.js
|
||||
- js/vendor/jquery.noConflict.js
|
||||
- js/vendor/jquery.browser.js
|
||||
- js/vendor/jquery.newsblur.js
|
||||
|
@ -121,7 +120,6 @@ javascripts:
|
|||
- js/vendor/readability-*.js
|
||||
blurblog:
|
||||
- js/vendor/jquery-3.6.0.js
|
||||
# - js/vendor/jquery.migrate-*.js
|
||||
- js/vendor/jquery.browser.js
|
||||
- js/vendor/jquery.color.js
|
||||
- js/vendor/underscore-*.js
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"description": "Servers used in running NewsBlur",
|
||||
"main": "favicons.js",
|
||||
"dependencies": {
|
||||
"@postlight/mercury-parser": "^2.2.1",
|
||||
"@postlight/mercury-parser": "^2.2.3",
|
||||
"@sentry/browser": "^6.12.0",
|
||||
"@sentry/node": "^6.12.0",
|
||||
"@sentry/tracing": "^6.12.0",
|
||||
|
|
|
@ -588,10 +588,11 @@
|
|||
this.story_content = selected;
|
||||
console.log(["content selected", this.story_title, this.story_content]);
|
||||
} else {
|
||||
var $readability = $(window.readability.init());
|
||||
|
||||
this.story_title = $readability.children("h1").text();
|
||||
this.story_content = $("#readability-content", $readability).html();
|
||||
var documentClone = document.cloneNode(true);
|
||||
var article = new Readability(documentClone).parse();
|
||||
|
||||
this.story_title = article.title;
|
||||
this.story_content = article.content;
|
||||
}
|
||||
|
||||
this.find_video_embeds();
|
||||
|
|
|
@ -3,6 +3,7 @@ import re
|
|||
import struct
|
||||
import datetime
|
||||
import random
|
||||
from utils import log as logging
|
||||
from django.contrib.sites.models import Site
|
||||
from django.conf import settings
|
||||
from django import template
|
||||
|
@ -299,12 +300,13 @@ def include_javascripts(parser, token):
|
|||
class RawJSNode(JavascriptNode):
|
||||
def render(self, context):
|
||||
output = super(RawJSNode, self).render(context)
|
||||
path = re.search(r"src=\"/(.*?)\"", output)
|
||||
assert path
|
||||
filename = path.group(1)
|
||||
abs_filename = os.path.join(settings.NEWSBLUR_DIR, filename)
|
||||
f = open(abs_filename, 'r')
|
||||
output = f.read()
|
||||
paths = re.findall(r"src=\"/(.*?)\"", output, re.MULTILINE)
|
||||
assert paths
|
||||
output = ""
|
||||
for filename in paths:
|
||||
abs_filename = os.path.join(settings.NEWSBLUR_DIR, filename)
|
||||
f = open(abs_filename, 'r')
|
||||
output += f.read()
|
||||
return output
|
||||
|
||||
@register.tag
|
||||
|
@ -317,12 +319,13 @@ def include_javascripts_raw(parser, token):
|
|||
class RawStylesheetNode(StylesheetNode):
|
||||
def render(self, context):
|
||||
output = super(RawStylesheetNode, self).render(context)
|
||||
path = re.search(r"href=\"/(.*?)\"", output)
|
||||
assert path
|
||||
filename = path.group(1)
|
||||
abs_filename = os.path.join(settings.NEWSBLUR_DIR, filename)
|
||||
f = open(abs_filename, 'r')
|
||||
output = f.read().replace('"', '\\"').replace('\n', '')
|
||||
paths = re.findall(r"href=\"/(.*?)\"", output, re.MULTILINE)
|
||||
assert paths
|
||||
output = ""
|
||||
for filename in paths:
|
||||
abs_filename = os.path.join(settings.NEWSBLUR_DIR, filename)
|
||||
f = open(abs_filename, 'r')
|
||||
output += f.read().replace('"', '\\"').replace('\n', '')
|
||||
return output
|
||||
|
||||
@register.tag
|
||||
|
|
Loading…
Add table
Reference in a new issue