mirror of
https://github.com/sissbruecker/linkding
synced 2024-11-10 06:04:15 +00:00
Show web archive fallback link in details modal
This commit is contained in:
parent
0fe6304328
commit
1122d18e18
3 changed files with 30 additions and 15 deletions
|
@ -23,8 +23,8 @@
|
||||||
<span>Reader mode</span>
|
<span>Reader mode</span>
|
||||||
</a>
|
</a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if details.bookmark.web_archive_snapshot_url %}
|
{% if details.web_archive_snapshot_url %}
|
||||||
<a class="weblink" href="{{ details.bookmark.web_archive_snapshot_url }}"
|
<a class="weblink" href="{{ details.web_archive_snapshot_url }}"
|
||||||
target="{{ details.profile.bookmark_link_target }}">
|
target="{{ details.profile.bookmark_link_target }}">
|
||||||
{% if details.show_link_icons %}
|
{% if details.show_link_icons %}
|
||||||
<svg class="favicon" viewBox="0 0 76 86" xmlns="http://www.w3.org/2000/svg">
|
<svg class="favicon" viewBox="0 0 76 86" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
|
import datetime
|
||||||
import re
|
import re
|
||||||
from unittest.mock import patch
|
from unittest.mock import patch
|
||||||
|
|
||||||
from django.core.files.uploadedfile import SimpleUploadedFile
|
from django.core.files.uploadedfile import SimpleUploadedFile
|
||||||
from django.test import TestCase, override_settings
|
from django.test import TestCase, override_settings
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
from django.utils import formats
|
from django.utils import formats, timezone
|
||||||
|
|
||||||
from bookmarks.models import BookmarkAsset, UserProfile
|
from bookmarks.models import BookmarkAsset, UserProfile
|
||||||
from bookmarks.services import bookmarks, tasks
|
from bookmarks.services import bookmarks, tasks
|
||||||
|
@ -180,7 +181,7 @@ class BookmarkDetailsModalTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
||||||
# no latest snapshot
|
# no latest snapshot
|
||||||
bookmark = self.setup_bookmark()
|
bookmark = self.setup_bookmark()
|
||||||
soup = self.get_details(bookmark)
|
soup = self.get_details(bookmark)
|
||||||
self.assertEqual(self.count_weblinks(soup), 1)
|
self.assertEqual(self.count_weblinks(soup), 2)
|
||||||
|
|
||||||
# snapshot is not complete
|
# snapshot is not complete
|
||||||
self.setup_asset(
|
self.setup_asset(
|
||||||
|
@ -194,7 +195,7 @@ class BookmarkDetailsModalTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
||||||
status=BookmarkAsset.STATUS_FAILURE,
|
status=BookmarkAsset.STATUS_FAILURE,
|
||||||
)
|
)
|
||||||
soup = self.get_details(bookmark)
|
soup = self.get_details(bookmark)
|
||||||
self.assertEqual(self.count_weblinks(soup), 1)
|
self.assertEqual(self.count_weblinks(soup), 2)
|
||||||
|
|
||||||
# not a snapshot
|
# not a snapshot
|
||||||
self.setup_asset(
|
self.setup_asset(
|
||||||
|
@ -203,7 +204,7 @@ class BookmarkDetailsModalTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
||||||
status=BookmarkAsset.STATUS_COMPLETE,
|
status=BookmarkAsset.STATUS_COMPLETE,
|
||||||
)
|
)
|
||||||
soup = self.get_details(bookmark)
|
soup = self.get_details(bookmark)
|
||||||
self.assertEqual(self.count_weblinks(soup), 1)
|
self.assertEqual(self.count_weblinks(soup), 2)
|
||||||
|
|
||||||
# snapshot is complete
|
# snapshot is complete
|
||||||
asset = self.setup_asset(
|
asset = self.setup_asset(
|
||||||
|
@ -212,20 +213,13 @@ class BookmarkDetailsModalTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
||||||
status=BookmarkAsset.STATUS_COMPLETE,
|
status=BookmarkAsset.STATUS_COMPLETE,
|
||||||
)
|
)
|
||||||
soup = self.get_details(bookmark)
|
soup = self.get_details(bookmark)
|
||||||
self.assertEqual(self.count_weblinks(soup), 2)
|
self.assertEqual(self.count_weblinks(soup), 3)
|
||||||
|
|
||||||
reader_mode_url = reverse("bookmarks:assets.read", args=[asset.id])
|
reader_mode_url = reverse("bookmarks:assets.read", args=[asset.id])
|
||||||
link = self.find_weblink(soup, reader_mode_url)
|
link = self.find_weblink(soup, reader_mode_url)
|
||||||
self.assertIsNotNone(link)
|
self.assertIsNotNone(link)
|
||||||
|
|
||||||
def test_internet_archive_link(self):
|
def test_internet_archive_link_with_snapshot_url(self):
|
||||||
# without snapshot url
|
|
||||||
bookmark = self.setup_bookmark()
|
|
||||||
soup = self.get_details(bookmark)
|
|
||||||
link = self.find_weblink(soup, bookmark.web_archive_snapshot_url)
|
|
||||||
self.assertIsNone(link)
|
|
||||||
|
|
||||||
# with snapshot url
|
|
||||||
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com/")
|
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com/")
|
||||||
soup = self.get_details(bookmark)
|
soup = self.get_details(bookmark)
|
||||||
link = self.find_weblink(soup, bookmark.web_archive_snapshot_url)
|
link = self.find_weblink(soup, bookmark.web_archive_snapshot_url)
|
||||||
|
@ -264,6 +258,21 @@ class BookmarkDetailsModalTestCase(TestCase, BookmarkFactoryMixin, HtmlTestMixin
|
||||||
image = link.select_one("svg")
|
image = link.select_one("svg")
|
||||||
self.assertIsNotNone(image)
|
self.assertIsNotNone(image)
|
||||||
|
|
||||||
|
def test_internet_archive_link_with_fallback_url(self):
|
||||||
|
date_added = timezone.datetime(
|
||||||
|
2023, 8, 11, 21, 45, 11, tzinfo=datetime.timezone.utc
|
||||||
|
)
|
||||||
|
bookmark = self.setup_bookmark(url="https://example.com/", added=date_added)
|
||||||
|
fallback_web_archive_url = (
|
||||||
|
"https://web.archive.org/web/20230811214511/https://example.com/"
|
||||||
|
)
|
||||||
|
|
||||||
|
soup = self.get_details(bookmark)
|
||||||
|
link = self.find_weblink(soup, fallback_web_archive_url)
|
||||||
|
self.assertIsNotNone(link)
|
||||||
|
self.assertEqual(link["href"], fallback_web_archive_url)
|
||||||
|
self.assertEqual(link.text.strip(), "Internet Archive")
|
||||||
|
|
||||||
def test_weblinks_respect_target_setting(self):
|
def test_weblinks_respect_target_setting(self):
|
||||||
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com/")
|
bookmark = self.setup_bookmark(web_archive_snapshot_url="https://example.com/")
|
||||||
|
|
||||||
|
|
|
@ -417,6 +417,12 @@ class BookmarkDetailsContext:
|
||||||
# For now hide files section if snapshots are not supported
|
# For now hide files section if snapshots are not supported
|
||||||
self.show_files = settings.LD_ENABLE_SNAPSHOTS
|
self.show_files = settings.LD_ENABLE_SNAPSHOTS
|
||||||
|
|
||||||
|
self.web_archive_snapshot_url = bookmark.web_archive_snapshot_url
|
||||||
|
if not self.web_archive_snapshot_url:
|
||||||
|
self.web_archive_snapshot_url = generate_fallback_webarchive_url(
|
||||||
|
bookmark.url, bookmark.date_added
|
||||||
|
)
|
||||||
|
|
||||||
self.assets = [
|
self.assets = [
|
||||||
BookmarkAssetItem(asset) for asset in bookmark.bookmarkasset_set.all()
|
BookmarkAssetItem(asset) for asset in bookmark.bookmarkasset_set.all()
|
||||||
]
|
]
|
||||||
|
|
Loading…
Reference in a new issue