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:
Samuel Clay 2022-11-24 12:53:40 -05:00
parent 855a96d633
commit 6095bd709d
9 changed files with 2349 additions and 1870 deletions

View file

@ -8,7 +8,7 @@
], ],
"python.pythonPath": "~/.virtualenvs/newsblur3/bin/python", "python.pythonPath": "~/.virtualenvs/newsblur3/bin/python",
"editor.bracketPairColorization.enabled": true, "editor.bracketPairColorization.enabled": true,
"editor.guides.bracketPairs":"active", "editor.guides.bracketPairs": "active",
"git.ignoreLimitWarning": true, "git.ignoreLimitWarning": true,
"search.exclude": { "search.exclude": {
"clients": true, "clients": true,
@ -27,7 +27,6 @@
"docker/volumes": true, "docker/volumes": true,
"requirements.txt": true, // It's just a symlink to config/requirements.txt, which has git history "requirements.txt": true, // It's just a symlink to config/requirements.txt, which has git history
}, },
"python.formatting.provider": "black",
"python.formatting.blackArgs": [ "python.formatting.blackArgs": [
"--line-length=110", "--line-length=110",
"--skip-string-normalization" "--skip-string-normalization"
@ -37,4 +36,5 @@
}, },
"nrf-connect.toolchain.path": "${nrf-connect.toolchain:1.9.1}", "nrf-connect.toolchain.path": "${nrf-connect.toolchain:1.9.1}",
"C_Cpp.default.configurationProvider": "nrf-connect", "C_Cpp.default.configurationProvider": "nrf-connect",
"editor.formatOnSave": false,
} }

View file

@ -206,6 +206,11 @@ def check_share_on_site(request, token):
usersub = None usersub = None
message = None message = None
user = None user = None
users = {}
your_story = None
same_stories = None
other_stories = None
previous_stories = None
if not story_url: if not story_url:
code = -1 code = -1
@ -239,34 +244,34 @@ def check_share_on_site(request, token):
usersub = UserSubscription.objects.filter(user=user, feed=feed) usersub = UserSubscription.objects.filter(user=user, feed=feed)
except UserSubscription.DoesNotExist: except UserSubscription.DoesNotExist:
usersub = None usersub = None
feed_id = feed and feed.pk if user:
your_story, same_stories, other_stories = MSharedStory.get_shared_stories_from_site(feed_id, feed_id = feed and feed.pk
user_id=user_profile.user.pk, story_url=story_url) your_story, same_stories, other_stories = MSharedStory.get_shared_stories_from_site(feed_id,
previous_stories = MSharedStory.objects.filter(user_id=user_profile.user.pk).order_by('-shared_date').limit(3) user_id=user.pk, story_url=story_url)
previous_stories = [{ previous_stories = MSharedStory.objects.filter(user_id=user.pk).order_by('-shared_date').limit(3)
"user_id": story.user_id, previous_stories = [{
"story_title": story.story_title, "user_id": story.user_id,
"comments": story.comments, "story_title": story.story_title,
"shared_date": story.shared_date, "comments": story.comments,
"relative_date": relative_timesince(story.shared_date), "shared_date": story.shared_date,
"blurblog_permalink": story.blurblog_permalink(), "relative_date": relative_timesince(story.shared_date),
} for story in previous_stories] "blurblog_permalink": story.blurblog_permalink(),
} for story in previous_stories]
user_ids = set([user_profile.user.pk]) user_ids = set([user_profile.user.pk])
for story in same_stories: for story in same_stories:
user_ids.add(story['user_id']) user_ids.add(story['user_id'])
for story in other_stories: for story in other_stories:
user_ids.add(story['user_id']) user_ids.add(story['user_id'])
users = {} profiles = MSocialProfile.profiles(user_ids)
profiles = MSocialProfile.profiles(user_ids) for profile in profiles:
for profile in profiles: users[profile.user_id] = {
users[profile.user_id] = { "username": profile.username,
"username": profile.username, "photo_url": profile.photo_url,
"photo_url": profile.photo_url, }
}
logging.user(user_profile.user, "~BM~FCChecking share from site: ~SB%s" % (story_url), logging.user(user, "~BM~FCChecking share from site: ~SB%s" % (story_url),
request=request) request=request)
response = HttpResponse(callback + '(' + json.encode({ response = HttpResponse(callback + '(' + json.encode({
@ -285,12 +290,12 @@ def check_share_on_site(request, token):
return response return response
@required_params('story_url', 'comments', 'title') @required_params('story_url')
def share_story(request, token=None): def share_story(request, token=None):
code = 0 code = 0
story_url = request.POST['story_url'] story_url = request.POST['story_url']
comments = request.POST['comments'] comments = request.POST.get('comments', "")
title = request.POST['title'] title = request.POST.get('title', None)
content = request.POST.get('content', None) content = request.POST.get('content', None)
rss_url = request.POST.get('rss_url', None) rss_url = request.POST.get('rss_url', None)
feed_id = request.POST.get('feed_id', None) or 0 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 = lxml.html.fromstring(content)
content.make_links_absolute(story_url) content.make_links_absolute(story_url)
content = lxml.html.tostring(content) 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) importer = TextImporter(story=None, story_url=story_url, request=request, debug=settings.DEBUG)
document = importer.fetch(skip_save=True, return_document=True) document = importer.fetch(skip_save=True, return_document=True)
content = document['content'] if not content:
content = document['content']
if not title: if not title:
title = document['title'] title = document['title']

View file

@ -225,9 +225,9 @@ class TextImporter:
content = str(soup) 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: 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) content = content.replace(image_url, abs_image_url)
return content return content
@ -242,9 +242,11 @@ class TextImporter:
headers["content-type"] = "application/json" headers["content-type"] = "application/json"
headers["x-api-key"] = mercury_api_key headers["x-api-key"] = mercury_api_key
domain = Site.objects.get_current().domain domain = Site.objects.get_current().domain
protocol = "https"
if settings.DOCKERBUILD: if settings.DOCKERBUILD:
domain = 'haproxy' 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: try:
r = requests.get(url, headers=headers, timeout=15) r = requests.get(url, headers=headers, timeout=15)

View file

@ -320,16 +320,12 @@
margin-left: 0; margin-left: 0;
width: 220px; 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-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; padding: 0 12px;
} }
.NB-bookmarklet .NB-bookmarklet-comment-submit .NB-bookmarklet-accept img, .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; vertical-align: top;
margin: 0; margin: 0;
} }

File diff suppressed because it is too large Load diff

View file

@ -106,7 +106,6 @@ javascripts:
- js/newsblur/payments/stripe_form.js - js/newsblur/payments/stripe_form.js
bookmarklet: bookmarklet:
- js/vendor/jquery-3.6.0.min.js - js/vendor/jquery-3.6.0.min.js
# - js/vendor/jquery.migrate-*.js
- js/vendor/jquery.noConflict.js - js/vendor/jquery.noConflict.js
- js/vendor/jquery.browser.js - js/vendor/jquery.browser.js
- js/vendor/jquery.newsblur.js - js/vendor/jquery.newsblur.js
@ -121,7 +120,6 @@ javascripts:
- js/vendor/readability-*.js - js/vendor/readability-*.js
blurblog: blurblog:
- js/vendor/jquery-3.6.0.js - js/vendor/jquery-3.6.0.js
# - js/vendor/jquery.migrate-*.js
- js/vendor/jquery.browser.js - js/vendor/jquery.browser.js
- js/vendor/jquery.color.js - js/vendor/jquery.color.js
- js/vendor/underscore-*.js - js/vendor/underscore-*.js

View file

@ -4,7 +4,7 @@
"description": "Servers used in running NewsBlur", "description": "Servers used in running NewsBlur",
"main": "favicons.js", "main": "favicons.js",
"dependencies": { "dependencies": {
"@postlight/mercury-parser": "^2.2.1", "@postlight/mercury-parser": "^2.2.3",
"@sentry/browser": "^6.12.0", "@sentry/browser": "^6.12.0",
"@sentry/node": "^6.12.0", "@sentry/node": "^6.12.0",
"@sentry/tracing": "^6.12.0", "@sentry/tracing": "^6.12.0",

View file

@ -588,10 +588,11 @@
this.story_content = selected; this.story_content = selected;
console.log(["content selected", this.story_title, this.story_content]); console.log(["content selected", this.story_title, this.story_content]);
} else { } else {
var $readability = $(window.readability.init()); var documentClone = document.cloneNode(true);
var article = new Readability(documentClone).parse();
this.story_title = $readability.children("h1").text(); this.story_title = article.title;
this.story_content = $("#readability-content", $readability).html(); this.story_content = article.content;
} }
this.find_video_embeds(); this.find_video_embeds();

View file

@ -3,6 +3,7 @@ import re
import struct import struct
import datetime import datetime
import random import random
from utils import log as logging
from django.contrib.sites.models import Site from django.contrib.sites.models import Site
from django.conf import settings from django.conf import settings
from django import template from django import template
@ -299,12 +300,13 @@ def include_javascripts(parser, token):
class RawJSNode(JavascriptNode): class RawJSNode(JavascriptNode):
def render(self, context): def render(self, context):
output = super(RawJSNode, self).render(context) output = super(RawJSNode, self).render(context)
path = re.search(r"src=\"/(.*?)\"", output) paths = re.findall(r"src=\"/(.*?)\"", output, re.MULTILINE)
assert path assert paths
filename = path.group(1) output = ""
abs_filename = os.path.join(settings.NEWSBLUR_DIR, filename) for filename in paths:
f = open(abs_filename, 'r') abs_filename = os.path.join(settings.NEWSBLUR_DIR, filename)
output = f.read() f = open(abs_filename, 'r')
output += f.read()
return output return output
@register.tag @register.tag
@ -317,12 +319,13 @@ def include_javascripts_raw(parser, token):
class RawStylesheetNode(StylesheetNode): class RawStylesheetNode(StylesheetNode):
def render(self, context): def render(self, context):
output = super(RawStylesheetNode, self).render(context) output = super(RawStylesheetNode, self).render(context)
path = re.search(r"href=\"/(.*?)\"", output) paths = re.findall(r"href=\"/(.*?)\"", output, re.MULTILINE)
assert path assert paths
filename = path.group(1) output = ""
abs_filename = os.path.join(settings.NEWSBLUR_DIR, filename) for filename in paths:
f = open(abs_filename, 'r') abs_filename = os.path.join(settings.NEWSBLUR_DIR, filename)
output = f.read().replace('"', '\\"').replace('\n', '') f = open(abs_filename, 'r')
output += f.read().replace('"', '\\"').replace('\n', '')
return output return output
@register.tag @register.tag