Skip to content

Commit

Permalink
support adding standalone entry without opening in reader
Browse files Browse the repository at this point in the history
  • Loading branch information
facundoolano committed Jan 8, 2024
1 parent 62f73d8 commit 674cb5a
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 6 deletions.
5 changes: 3 additions & 2 deletions feedi/filters.py
Expand Up @@ -67,9 +67,10 @@ def sanitize_content(html, truncate=True):
for a in soup.find_all('a', href=True):
# prevent link clicks triggering the container's click event
# add kb modifiers to open in reader
read_url = flask.url_for("entry_add", url=a["href"], redirect=1)
a['_'] = f"""
on click[shiftKey and not metaKey] go to url {flask.url_for("entry_add", url=a["href"])} then halt
then on click[shiftKey and metaKey] go to url {flask.url_for("entry_add", url=a["href"])} in new window then halt
on click[shiftKey and not metaKey] go to url {read_url} then halt
then on click[shiftKey and metaKey] go to url {read_url} in new window then halt
then on click halt the event's bubbling
"""

Expand Down
9 changes: 7 additions & 2 deletions feedi/routes.py
Expand Up @@ -124,7 +124,8 @@ def autocomplete():
# we can reasonably assume this is a url

options += [
('Read article', flask.url_for('entry_add', url=term), 'far fa-eye'),
('Add to feed', flask.url_for('entry_add', url=term), 'fas fa-download'),
('View in reader', flask.url_for('entry_add', url=term, redirect=1), 'fas fa-book-reader'),
('Discover feed', flask.url_for('feed_add', url=term), 'fas fa-rss'),
]
if current_user.has_kindle:
Expand Down Expand Up @@ -434,7 +435,11 @@ def entry_add():

db.session.add(entry)
db.session.commit()
return redirect_response(flask.url_for('entry_view', id=entry.id))

if flask.request.args.get('redirect'):
return redirect_response(flask.url_for('entry_view', id=entry.id))
else:
return '', 204


@app.get("/entries/<int:id>")
Expand Down
6 changes: 4 additions & 2 deletions tests/test_routes.py
Expand Up @@ -267,14 +267,16 @@ def test_add_external_entry(client):
mock_request(content_url, body=body)

# add a standalone entry for that url, check that browser redirects to view content
response = client.get('/entries/', query_string={'url': content_url}, follow_redirects=True)
response = client.get(
'/entries/', query_string={'url': content_url, 'redirect': 1}, follow_redirects=True)
assert response.status_code == 200
assert 'reclaiming-the-web' in response.text
assert 'I had some ideas of what I wanted' in response.text

# add same url again, verify that redirected entry url is the same as before
previous_entry_url = response.request.path
response = client.get('/entries/', query_string={'url': content_url}, follow_redirects=True)
response = client.get(
'/entries/', query_string={'url': content_url, 'redirect': 1}, follow_redirects=True)
assert response.status_code == 200
assert response.request.path == previous_entry_url

Expand Down

0 comments on commit 674cb5a

Please sign in to comment.