mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-22 03:13:02 +00:00
prefer html snapshots when internet archive integration is disabled
This commit is contained in:
parent
c3149409b0
commit
d932b6257b
5 changed files with 47 additions and 1 deletions
30
bookmarks/migrations/0043_bookmark_latest_snapshot_id.py
Normal file
30
bookmarks/migrations/0043_bookmark_latest_snapshot_id.py
Normal file
|
@ -0,0 +1,30 @@
|
|||
# Generated by Django 5.1.1 on 2024-11-12 00:16
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
def update_latest_snapshots(apps, schema_editor):
|
||||
Bookmark = apps.get_model("bookmarks", "bookmark")
|
||||
for bookmark in Bookmark.objects.all():
|
||||
snapshots = bookmark.bookmarkasset_set.filter(status="complete").order_by(
|
||||
"-date_created"
|
||||
)
|
||||
if snapshots:
|
||||
bookmark.latest_snapshot_id = snapshots[0].id
|
||||
bookmark.save()
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
("bookmarks", "0042_userprofile_custom_css_hash"),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name="bookmark",
|
||||
name="latest_snapshot_id",
|
||||
field=models.IntegerField(blank=True, null=True),
|
||||
),
|
||||
migrations.RunPython(update_latest_snapshots),
|
||||
]
|
|
@ -62,6 +62,7 @@ class Bookmark(models.Model):
|
|||
# Obsolete field, kept to not remove column when generating migrations
|
||||
website_description = models.TextField(blank=True, null=True)
|
||||
web_archive_snapshot_url = models.CharField(max_length=2048, blank=True)
|
||||
latest_snapshot_id = models.IntegerField(blank=True, null=True)
|
||||
favicon_file = models.CharField(max_length=512, blank=True)
|
||||
preview_image_file = models.CharField(max_length=512, blank=True)
|
||||
unread = models.BooleanField(default=False)
|
||||
|
|
|
@ -320,6 +320,8 @@ def _create_html_snapshot_task(asset_id: int):
|
|||
asset.file = filename
|
||||
asset.gzip = True
|
||||
asset.save()
|
||||
asset.bookmark.latest_snapshot_id = asset.id
|
||||
asset.bookmark.save()
|
||||
logger.info(
|
||||
f"Successfully created HTML snapshot for bookmark. url={asset.bookmark.url}"
|
||||
)
|
||||
|
|
|
@ -64,7 +64,14 @@
|
|||
{% endif %}
|
||||
<div class="actions">
|
||||
{% if bookmark_item.display_date %}
|
||||
{% if bookmark_item.web_archive_snapshot_url %}
|
||||
{% if bookmark_item.show_html_snapshot %}
|
||||
<a href="{% url 'bookmarks:assets.view' bookmark_item.latest_snapshot_id %}"
|
||||
title="Show HTML snapshot"
|
||||
target="{{ bookmark_list.link_target }}"
|
||||
rel="noopener">
|
||||
{{ bookmark_item.display_date }}
|
||||
</a>
|
||||
{% elif bookmark_item.web_archive_snapshot_url %}
|
||||
<a href="{{ bookmark_item.web_archive_snapshot_url }}"
|
||||
title="Show snapshot on the Internet Archive Wayback Machine"
|
||||
target="{{ bookmark_list.link_target }}"
|
||||
|
|
|
@ -134,6 +134,7 @@ class BookmarkItem:
|
|||
self.web_archive_snapshot_url = generate_fallback_webarchive_url(
|
||||
bookmark.url, bookmark.date_added
|
||||
)
|
||||
self.latest_snapshot_id = bookmark.latest_snapshot_id
|
||||
self.favicon_file = bookmark.favicon_file
|
||||
self.preview_image_file = bookmark.preview_image_file
|
||||
self.is_archived = bookmark.is_archived
|
||||
|
@ -164,6 +165,11 @@ class BookmarkItem:
|
|||
self.show_notes_button or self.show_mark_as_read or self.show_unshare
|
||||
)
|
||||
|
||||
self.show_html_snapshot = self.latest_snapshot_id and (
|
||||
profile.web_archive_integration
|
||||
== UserProfile.WEB_ARCHIVE_INTEGRATION_DISABLED
|
||||
)
|
||||
|
||||
|
||||
class BookmarkListContext:
|
||||
request_context = RequestContext
|
||||
|
|
Loading…
Reference in a new issue