Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update cached styles and scripts after version change #510

Merged
merged 1 commit into from
Aug 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions bookmarks/context_processors.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from bookmarks import queries
from bookmarks.models import Toast
from bookmarks import utils


def toasts(request):
Expand All @@ -23,3 +24,9 @@ def public_shares(request):
}

return {}


def app_version(request):
return {
'app_version': utils.app_version
}
2 changes: 1 addition & 1 deletion bookmarks/templates/bookmarks/archive.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ <h2>Tags</h2>
</section>
</div>

<script src="{% static "bundle.js" %}"></script>
<script src="{% static "bundle.js" %}?v={{ app_version }}"></script>
{% endblock %}
3 changes: 1 addition & 2 deletions bookmarks/templates/bookmarks/form.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,7 @@
<a href="{{ cancel_url }}" class="btn">Nevermind</a>
</div>

{# Replace tag input with auto-complete component #}
<script src="{% static "bundle.js" %}"></script>
<script src="{% static "bundle.js" %}?v={{ app_version }}"></script>
<script type="application/javascript">
/**
* - Pre-fill title and description placeholders with metadata from website as soon as URL changes
Expand Down
2 changes: 1 addition & 1 deletion bookmarks/templates/bookmarks/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -41,5 +41,5 @@ <h2>Tags</h2>
</section>
</div>

<script src="{% static "bundle.js" %}"></script>
<script src="{% static "bundle.js" %}?v={{ app_version }}"></script>
{% endblock %}
8 changes: 4 additions & 4 deletions bookmarks/templates/bookmarks/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,14 @@
{# Include SASS styles, files are resolved from bookmarks/styles #}
{# Include specific theme variant based on user profile setting #}
{% if request.user_profile.theme == 'light' %}
<link href="{% sass_src 'theme-light.scss' %}" rel="stylesheet" type="text/css"/>
<link href="{% sass_src 'theme-light.scss' %}?v={{ app_version }}" rel="stylesheet" type="text/css"/>
{% elif request.user_profile.theme == 'dark' %}
<link href="{% sass_src 'theme-dark.scss' %}" rel="stylesheet" type="text/css"/>
<link href="{% sass_src 'theme-dark.scss' %}?v={{ app_version }}" rel="stylesheet" type="text/css"/>
{% else %}
{# Use auto theme as fallback #}
<link href="{% sass_src 'theme-dark.scss' %}" rel="stylesheet" type="text/css"
<link href="{% sass_src 'theme-dark.scss' %}?v={{ app_version }}" rel="stylesheet" type="text/css"
media="(prefers-color-scheme: dark)"/>
<link href="{% sass_src 'theme-light.scss' %}" rel="stylesheet" type="text/css"
<link href="{% sass_src 'theme-light.scss' %}?v={{ app_version }}" rel="stylesheet" type="text/css"
media="(prefers-color-scheme: light)"/>
{% endif %}
</head>
Expand Down
2 changes: 1 addition & 1 deletion bookmarks/templates/bookmarks/shared.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,5 +45,5 @@ <h2>Tags</h2>
</section>
</div>

<script src="{% static "bundle.js" %}"></script>
<script src="{% static "bundle.js" %}?v={{ app_version }}"></script>
{% endblock %}
8 changes: 8 additions & 0 deletions bookmarks/utils.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import re
from datetime import datetime
from typing import Optional
Expand All @@ -6,6 +7,13 @@
from django.template.defaultfilters import pluralize
from django.utils import timezone, formats

try:
with open("version.txt", "r") as f:
app_version = f.read().strip("\n")
except Exception as exc:
logging.exception(exc)
app_version = ''


def unique(elements, key):
return list({key(element): element for element in elements}.values())
Expand Down
8 changes: 1 addition & 7 deletions bookmarks/views/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,10 @@
from bookmarks.queries import query_bookmarks
from bookmarks.services import exporter, tasks
from bookmarks.services import importer
from bookmarks.utils import app_version

logger = logging.getLogger(__name__)

try:
with open("version.txt", "r") as f:
app_version = f.read().strip("\n")
except Exception as exc:
logging.exception(exc)
pass


@login_required
def general(request):
Expand Down
1 change: 1 addition & 0 deletions siteroot/settings/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
'django.contrib.messages.context_processors.messages',
'bookmarks.context_processors.toasts',
'bookmarks.context_processors.public_shares',
'bookmarks.context_processors.app_version',
],
},
},
Expand Down