Skip to content

Commit

Permalink
embedded links and is unwrappable entry helpers
Browse files Browse the repository at this point in the history
  • Loading branch information
facundoolano committed Feb 1, 2024
1 parent 4d416b3 commit 4a1c414
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 29 deletions.
10 changes: 10 additions & 0 deletions feedi/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,16 @@ def fetch_content(self):
except Exception as e:
logger.debug("failed to fetch content %s", e)

def embedded_links(self):
if self.content_short:
return [url for (url, text) in scraping.extract_links(self.target_url, self.content_short)
# skip hashtag and profile links
if not text.startswith('#') and not text.startswith('@')]
return []

def is_unwrappable(self):
return bool(self.embedded_links())

def backlog(self):
self.backlogged = datetime.datetime.utcnow()
self.pinned = None
Expand Down
26 changes: 11 additions & 15 deletions feedi/routes.py
Original file line number Diff line number Diff line change
Expand Up @@ -496,28 +496,24 @@ def entry_add():

@app.post("/entries/<int:id>")
@login_required
def entry_unwrap(id_):
def entry_unwrap(id):
entry = db.get_or_404(models.Entry, id)
if entry.user_id != current_user.id:
flask.abort(404)

if entry.content_short:
# If there's an inline link, "unwrap it", e.g. remove the old entry and put the linked
# article entry in its place
links = [url for (url, text) in scraping.extract_links(entry.target_url, entry.content_short)
# skip hashtag and profile links
if not text.startswith('#') and not text.startswith('@')]
if links:
for link in links:
try:
subentry = models.Entry.from_url(current_user.id, link)
entry.viewed = datetime.datetime.now()
db.session.add(subentry)
db.session.commit()
return flask.render_template('entry_list_page.html',
entries=[subentry])
except Exception:
continue
for link in entry.embedded_links():
try:
subentry = models.Entry.from_url(current_user.id, link)
entry.viewed = datetime.datetime.now()
db.session.add(subentry)
db.session.commit()
return flask.render_template('entry_list_page.html',
entries=[subentry])
except Exception:
continue
return "Couldn't unwrap", 400


Expand Down
7 changes: 0 additions & 7 deletions feedi/templates/entry_content.html
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,6 @@
<i class="fas fa-external-link-alt"></i>
</a>
{% endif %}
{% if not entry.backlogged %}
<a class="level-item icon is-white is-rounded" title="Unwrap"
hx-put="{{ url_for('entry_unwrap', id=entry.id )}}"
_="on htmx:afterRequest if history.length == 1 go to url '{{ url_for("entry_list")}}' else go back end"
><i class="fas fa-envelope-open-text"></i></a>
{% endif %}


<a class="level-item icon hover-icon is-white is-rounded {% if entry.pinned %}toggled{% endif %} pin-button" title="Pin"
hx-put="{{ url_for('entry_pin', id=entry.id, **filters) }}"
Expand Down
10 changes: 5 additions & 5 deletions feedi/templates/entry_header.html
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,14 @@
</p>
</div>
<div class="is-hidden compact-actions is-hidden">
{%if entry.backlogged %}
{% if entry.backlogged %}
<a tabindex="-1" class="is-marginless level-item icon hover-icon is-white is-rounded" title="Pop from backlog"
_="on htmx:afterRequest remove the closest .feed-entry"
hx-delete="{{ url_for('entry_backlog_pop', id=entry.id )}}"
><i class="fas fa-undo"></i></a>
{% else %}
{% elif entry.is_unwrappable() %}
<a tabindex="-1" class="is-marginless level-item icon hover-icon is-white is-rounded" title="Unwrap"
hx-put="{{ url_for('entry_unwrap', id=entry.id )}}"
hx-post="{{ url_for('entry_unwrap', id=entry.id )}}"
hx-target="closest .feed-entry"
hx-swap="outerHTML"
_ = "on click set x to the closest .feed-entry then set x.style.opacity to 0.5"
Expand Down Expand Up @@ -101,9 +101,9 @@
_="on htmx:afterRequest remove the closest .feed-entry"
hx-delete="{{ url_for('entry_backlog_pop', id=entry.id )}}"
><i class="fas fa-undo"></i></a>
{% else %}
{% elif entry.is_unwrappable() %}
<a tabindex="-1" class="level-item icon hover-icon is-white is-rounded" title="Unwrap"
hx-put="{{ url_for('entry_unwrap', id=entry.id )}}"
hx-post="{{ url_for('entry_unwrap', id=entry.id )}}"
hx-target="closest .feed-entry"
hx-swap="outerHTML"
_ = "on click set x to the closest .feed-entry then set x.style.opacity to 0.5"
Expand Down
4 changes: 2 additions & 2 deletions feedi/templates/entry_list_page.html
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@
_="on htmx:afterRequest remove the closest .feed-entry"
hx-delete="{{ url_for('entry_backlog_pop', id=entry.id )}}"
><i class="fas fa-undo"></i></a>
{% else %}
{% elif entry.is_unwrappable() %}
<a tabindex="-1" class="level-item icon is-white is-rounded" title="Unwrap"
hx-put="{{ url_for('entry_unwrap', id=entry.id )}}"
hx-post="{{ url_for('entry_unwrap', id=entry.id )}}"
hx-target="closest .feed-entry"
hx-swap="outerHTML"
_ = "on click set x to the closest .feed-entry then set x.style.opacity to 0.5"
Expand Down

0 comments on commit 4a1c414

Please sign in to comment.