diff --git a/Dockerfile b/Dockerfile index 6d36b35..d3a2695 100644 --- a/Dockerfile +++ b/Dockerfile @@ -62,7 +62,6 @@ ENV DB_BASE_DIR "/db" #ENV SHORTPIXEL_API_KEY='YOURAPIKEY' #ENV SHORTPIXEL_RESIZE_WIDTH='750' #ENV SHORTPIXEL_RESIZE_HEIGHT='10000' -#ENV PLAUSIBLE_DOMAIN='url-of-your-blog.example.com' #ENV GOATCOUNTER_DOMAIN='blog.goatcounter.example.com' #ENV MEMCACHED_LOCATION='memcached:11211' diff --git a/articles/assets.py b/articles/assets.py deleted file mode 100644 index 1518af0..0000000 --- a/articles/assets.py +++ /dev/null @@ -1,19 +0,0 @@ -from django_assets import Bundle, register - -public_no_code = Bundle( - "vendor/newcss.css", - "public.css", - "admonitions.css", - filters="rcssmin", - output="public_bundled.css", -) -public_with_code = Bundle( - "vendor/newcss.css", - "vendor/codehilite.css", - "public.css", - "admonitions.css", - filters="rcssmin", - output="public_code_bundled.css", -) -register("public_no_code", public_no_code) -register("public_with_code", public_with_code) diff --git a/articles/context_processors.py b/articles/context_processors.py index baf16e5..cb18c25 100644 --- a/articles/context_processors.py +++ b/articles/context_processors.py @@ -36,7 +36,6 @@ def git_version(request): def analytics(request): return { - "plausible_domain": settings.PLAUSIBLE_DOMAIN, "goatcounter_domain": settings.GOATCOUNTER_DOMAIN, } diff --git a/articles/templates/articles/snippets/analytics.html b/articles/templates/articles/snippets/analytics.html index bc7cc12..387b1ff 100644 --- a/articles/templates/articles/snippets/analytics.html +++ b/articles/templates/articles/snippets/analytics.html @@ -1,25 +1,17 @@ {% load static compress %} -{% if not user.is_authenticated %} - {% if plausible_domain is not None %} - - {% endif %} - - {% if goatcounter_domain is not None %} - {% compress js inline %} - - - {% endcompress %} - - {% endif %} + + {% endcompress %} + {% endif %} diff --git a/articles/templates/articles/snippets/analytics_head.html b/articles/templates/articles/snippets/analytics_head.html index e931159..7fceb82 100644 --- a/articles/templates/articles/snippets/analytics_head.html +++ b/articles/templates/articles/snippets/analytics_head.html @@ -1,9 +1,3 @@ -{% if not user.is_authenticated %} - {% if plausible_domain is not None %} - - {% endif %} - - {% if goatcounter_domain is not None %} - - {% endif %} +{% if not user.is_authenticated and goatcounter_domain is not None %} + {% endif %} diff --git a/articles/tests/conftest.py b/articles/tests/conftest.py index f79088a..c995265 100644 --- a/articles/tests/conftest.py +++ b/articles/tests/conftest.py @@ -1,3 +1,4 @@ +import os import uuid import pytest diff --git a/articles/tests/test_html_views.py b/articles/tests/test_html_views.py index 3c4db23..0e13bb8 100644 --- a/articles/tests/test_html_views.py +++ b/articles/tests/test_html_views.py @@ -102,29 +102,31 @@ def test_user_can_access_drafts_list( @pytest.mark.django_db -def test_has_plausible_if_set(client: Client, settings): - settings.PLAUSIBLE_DOMAIN = "gabnotes.org" +def test_has_goatcounter_if_set(client: Client, settings): + settings.GOATCOUNTER_DOMAIN = "gc.gabnotes.org" res = client.get(reverse("articles-list")) content = res.content.decode("utf-8") - assert "https://plausible.augendre.info/js/plausible.js" in content - assert 'data-domain="gabnotes.org"' in content + assert "window.goatcounter" in content + assert f"{settings.GOATCOUNTER_DOMAIN}/count" in content @pytest.mark.django_db -def test_doesnt_have_plausible_if_unset(client: Client, settings): - settings.PLAUSIBLE_DOMAIN = None +def test_doesnt_have_goatcounter_if_unset(client: Client, settings): + settings.GOATCOUNTER_DOMAIN = None res = client.get(reverse("articles-list")) content = res.content.decode("utf-8") - assert "https://plausible.augendre.info/js/plausible.js" not in content + assert "window.goatcounter" not in content + assert f"{settings.GOATCOUNTER_DOMAIN}/count" not in content @pytest.mark.django_db -def test_logged_in_user_doesnt_have_plausible(client: Client, author: User, settings): +def test_logged_in_user_doesnt_have_goatcounter(client: Client, author: User, settings): client.force_login(author) - settings.PLAUSIBLE_DOMAIN = "gabnotes.org" + settings.GOATCOUNTER_DOMAIN = "gc.gabnotes.org" res = client.get(reverse("articles-list")) content = res.content.decode("utf-8") - assert "https://plausible.augendre.info/js/plausible.js" not in content + assert "window.goatcounter" not in content + assert f"{settings.GOATCOUNTER_DOMAIN}/count" not in content @pytest.mark.django_db diff --git a/blog/settings.py b/blog/settings.py index b2b7b93..7091723 100644 --- a/blog/settings.py +++ b/blog/settings.py @@ -205,7 +205,6 @@ SHORTPIXEL_API_KEY = os.getenv("SHORTPIXEL_API_KEY") SHORTPIXEL_RESIZE_WIDTH = int(os.getenv("SHORTPIXEL_RESIZE_WIDTH", 750)) SHORTPIXEL_RESIZE_HEIGHT = int(os.getenv("SHORTPIXEL_RESIZE_HEIGHT", 10000)) -PLAUSIBLE_DOMAIN = os.getenv("PLAUSIBLE_DOMAIN") GOATCOUNTER_DOMAIN = os.getenv("GOATCOUNTER_DOMAIN") LOGIN_URL = "admin:login" diff --git a/docker/nginx-dev.conf b/docker/nginx-dev.conf index c08b5e8..efe2c2a 100644 --- a/docker/nginx-dev.conf +++ b/docker/nginx-dev.conf @@ -42,7 +42,7 @@ server { } add_header Content-Security-Policy "frame-ancestors 'none'; default-src 'none'; img-src 'self' https:; script-src 'self' - https://plausible.augendre.info; connect-src https://plausible.augendre.info; style-src 'self' 'unsafe-inline'; + https://gc.gabnotes.org; connect-src https://gc.gabnotes.org; style-src 'self' 'unsafe-inline'; font-src 'self'; manifest-src 'self';" always; add_header X-Frame-Options "DENY" always; add_header X-XSS-Protection "1; mode=block" always; diff --git a/docker/nginx.conf b/docker/nginx.conf index 8177943..a110608 100644 --- a/docker/nginx.conf +++ b/docker/nginx.conf @@ -43,7 +43,7 @@ server { } add_header Content-Security-Policy "frame-ancestors 'none'; default-src 'none'; img-src https:; script-src 'self' - https://plausible.augendre.info; connect-src https://plausible.augendre.info; style-src 'self' 'unsafe-inline'; + https://gc.gabnotes.org; connect-src https://gc.gabnotes.org; style-src 'self' 'unsafe-inline'; font-src 'self'; manifest-src 'self';" always; add_header X-Frame-Options "DENY" always; add_header X-XSS-Protection "1; mode=block" always; diff --git a/poetry.lock b/poetry.lock index 5190b62..a8dc58e 100644 --- a/poetry.lock +++ b/poetry.lock @@ -457,6 +457,17 @@ pytest = ">=3.6" docs = ["sphinx", "sphinx-rtd-theme"] testing = ["django", "django-configurations (>=2.0)", "six"] +[[package]] +name = "pytest-env" +version = "0.6.2" +description = "py.test plugin that allows you to add environment variables." +category = "dev" +optional = false +python-versions = "*" + +[package.dependencies] +pytest = ">=2.6.0" + [[package]] name = "pytest-recording" version = "0.11.0" @@ -644,7 +655,7 @@ multidict = ">=4.0" [metadata] lock-version = "1.1" python-versions = "^3.8" -content-hash = "54f79231676e4ef08e19081303d6bdf9c18bd2db967b7df46bc489a056046d41" +content-hash = "474725a38a18e88a99712701d8558105c9466aaddf5a309afda23b04c3a7741f" [metadata.files] appdirs = [ @@ -967,6 +978,9 @@ pytest-django = [ {file = "pytest-django-3.10.0.tar.gz", hash = "sha256:4de6dbd077ed8606616958f77655fed0d5e3ee45159475671c7fa67596c6dba6"}, {file = "pytest_django-3.10.0-py2.py3-none-any.whl", hash = "sha256:c33e3d3da14d8409b125d825d4e74da17bb252191bf6fc3da6856e27a8b73ea4"}, ] +pytest-env = [ + {file = "pytest-env-0.6.2.tar.gz", hash = "sha256:7e94956aef7f2764f3c147d216ce066bf6c42948bb9e293169b1b1c880a580c2"}, +] pytest-recording = [ {file = "pytest-recording-0.11.0.tar.gz", hash = "sha256:deea1ae6a129c9d8f8669ed7d12539748f00c8f9ef4de4f563055263e47bed08"}, {file = "pytest_recording-0.11.0-py3-none-any.whl", hash = "sha256:c2cc321f93ceffb2146ead0c51198e4ce86986723265ce6d4a87d3b16071eb85"}, diff --git a/pyproject.toml b/pyproject.toml index fa40b4d..f5ac325 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,9 @@ testpaths = [ "blog", "attachments", ] +env = [ + "GOATCOUNTER_DOMAIN=gc.gabnotes.org" +] [tool.poetry] name = "blog" @@ -45,6 +48,7 @@ model-bakery = "^1.1" pytest-cov = "^2.10.1" pytest-recording = "^0.11.0" pytest-rerunfailures = "^9.1.1" +pytest-env = "^0.6.2" [build-system] requires = ["poetry-core>=1.0.0"]