diff --git a/bookmarks/frontend/behaviors/index.js b/bookmarks/frontend/behaviors/index.js index 0ddbde38..3368f7e7 100644 --- a/bookmarks/frontend/behaviors/index.js +++ b/bookmarks/frontend/behaviors/index.js @@ -16,9 +16,13 @@ const mutationObserver = new MutationObserver((mutations) => { }); }); -mutationObserver.observe(document.body, { - childList: true, - subtree: true, +window.addEventListener("turbo:load", () => { + mutationObserver.observe(document.body, { + childList: true, + subtree: true, + }); + + applyBehaviors(document.body); }); export class Behavior { diff --git a/bookmarks/frontend/index.js b/bookmarks/frontend/index.js index af81505c..4e35403e 100644 --- a/bookmarks/frontend/index.js +++ b/bookmarks/frontend/index.js @@ -1,3 +1,4 @@ +import "@hotwired/turbo"; import "./behaviors/bookmark-page"; import "./behaviors/bulk-edit"; import "./behaviors/confirm-button"; diff --git a/bookmarks/middlewares.py b/bookmarks/middlewares.py index af7ff12a..7469d2e6 100644 --- a/bookmarks/middlewares.py +++ b/bookmarks/middlewares.py @@ -8,28 +8,33 @@ class CustomRemoteUserMiddleware(RemoteUserMiddleware): header = settings.LD_AUTH_PROXY_USERNAME_HEADER +default_global_settings = GlobalSettings() + standard_profile = UserProfile() standard_profile.enable_favicons = True -class UserProfileMiddleware: +class LinkdingMiddleware: def __init__(self, get_response): self.get_response = get_response def __call__(self, request): + # add global settings to request + try: + global_settings = GlobalSettings.get() + except: + global_settings = default_global_settings + request.global_settings = global_settings + + # add user profile to request if request.user.is_authenticated: request.user_profile = request.user.profile else: # check if a custom profile for guests exists, otherwise use standard profile - guest_profile = None - try: - global_settings = GlobalSettings.get() - if global_settings.guest_profile_user: - guest_profile = global_settings.guest_profile_user.profile - except: - pass - - request.user_profile = guest_profile or standard_profile + if global_settings.guest_profile_user: + request.user_profile = global_settings.guest_profile_user.profile + else: + request.user_profile = standard_profile response = self.get_response(request) diff --git a/bookmarks/migrations/0039_globalsettings_enable_link_prefetch.py b/bookmarks/migrations/0039_globalsettings_enable_link_prefetch.py new file mode 100644 index 00000000..b18ec957 --- /dev/null +++ b/bookmarks/migrations/0039_globalsettings_enable_link_prefetch.py @@ -0,0 +1,18 @@ +# Generated by Django 5.0.8 on 2024-09-14 07:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("bookmarks", "0038_globalsettings_guest_profile_user"), + ] + + operations = [ + migrations.AddField( + model_name="globalsettings", + name="enable_link_prefetch", + field=models.BooleanField(default=False), + ), + ] diff --git a/bookmarks/models.py b/bookmarks/models.py index a8d5a81e..aa8990d0 100644 --- a/bookmarks/models.py +++ b/bookmarks/models.py @@ -514,6 +514,7 @@ class GlobalSettings(models.Model): guest_profile_user = models.ForeignKey( get_user_model(), on_delete=models.SET_NULL, null=True, blank=True ) + enable_link_prefetch = models.BooleanField(default=False, null=False) @classmethod def get(cls): @@ -532,7 +533,7 @@ def save(self, *args, **kwargs): class GlobalSettingsForm(forms.ModelForm): class Meta: model = GlobalSettings - fields = ["landing_page", "guest_profile_user"] + fields = ["landing_page", "guest_profile_user", "enable_link_prefetch"] def __init__(self, *args, **kwargs): super(GlobalSettingsForm, self).__init__(*args, **kwargs) diff --git a/bookmarks/styles/components.css b/bookmarks/styles/components.css index f485f0e3..9df1bdfe 100644 --- a/bookmarks/styles/components.css +++ b/bookmarks/styles/components.css @@ -57,4 +57,9 @@ span.confirmation { .divider { border-bottom: solid 1px var(--secondary-border-color); margin: var(--unit-5) 0; -} \ No newline at end of file +} + +/* Turbo progress bar */ +.turbo-progress-bar { + background-color: var(--primary-color); +} diff --git a/bookmarks/templates/bookmarks/bookmark_list.html b/bookmarks/templates/bookmarks/bookmark_list.html index ae04219d..71d0adae 100644 --- a/bookmarks/templates/bookmarks/bookmark_list.html +++ b/bookmarks/templates/bookmarks/bookmark_list.html @@ -26,7 +26,7 @@ {% if bookmark_list.show_url %}
@@ -66,9 +66,9 @@ {% if bookmark_item.display_date %} {% if bookmark_item.web_archive_snapshot_url %} + title="Show snapshot on the Internet Archive Wayback Machine" + target="{{ bookmark_list.link_target }}" + rel="noopener"> {{ bookmark_item.display_date }} {% else %} @@ -79,8 +79,9 @@ {# View link is visible for both owned and shared bookmarks #} {% if bookmark_list.show_view_action %} View + ld-on="click" ld-target="body|append" + data-turbo-prefetch="false" + href="{% url 'bookmarks:details' bookmark_item.id %}">View {% endif %} {% if bookmark_item.is_editable %} {# Bookmark owner actions #} diff --git a/bookmarks/templates/bookmarks/layout.html b/bookmarks/templates/bookmarks/layout.html index 03ff4e30..c05e2216 100644 --- a/bookmarks/templates/bookmarks/layout.html +++ b/bookmarks/templates/bookmarks/layout.html @@ -35,6 +35,11 @@ {% if request.user_profile.custom_css %} {% endif %} + + {% if not request.global_settings.enable_link_prefetch %} + + {% endif %} + @@ -129,6 +134,5 @@