diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e8ef8ee --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.vscode/* +.idea/* +dist/* \ No newline at end of file diff --git a/LICENCE b/LICENCE new file mode 100644 index 0000000..1417789 --- /dev/null +++ b/LICENCE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 Antti Rummukainen + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. \ No newline at end of file diff --git a/README.md b/README.md new file mode 100644 index 0000000..6d6af4d --- /dev/null +++ b/README.md @@ -0,0 +1,41 @@ +## Django Simple Plausible + +A dead simple package to add Plausible Analytics html tag to your HTML. Tested with Python 2.7 and 3.8. Tested with Django 1.11 and 3.2. + +### Usage + +1. Install package: `pip install django_simple_plausible` + +2. Add `django_simple_plausible` to your `INSTALLED_APPS` in settings.py + +3. ADD `PLAUSIBLE_SITES` and `PLAUSIBLE_SCRIPT_URL` keys and values to your settings.py. Without these settings, default values for Plausible will be used. +``` +... + +PLAUSIBLE_SITES = "example.com" +PLAUSIBLE_SCRIPT_URL = "https://example.com/js/plausible.js" + +... +``` + +4. add the following template tags to your site html: +``` +{% load plausible %} +{% plausible %} +``` + +--- + +### Configuring details + +- PLAUSIBLE_SITES can be a comma separated list without spaces, if you want to use that feature of Plausible + +``` +PLAUSIBLE_SITES = "example.com,yoursite.com" +``` + +- Systemwide settings can be overridden giving the template tag some optional parameters: + +``` +{% plausible plausible_sites="mysite.com" script_url="https://mysite.com/plausible.js" %} +``` \ No newline at end of file diff --git a/build.sh b/build.sh new file mode 100755 index 0000000..2885a0c --- /dev/null +++ b/build.sh @@ -0,0 +1,5 @@ +#!/bin/bash +python -m build +rm -rf *.egg-info +echo "Upload to TestPyPi: python -m twine upload --repository testpypi dist/*" +printf "Upload to PyPi: python -m twine upload dist/*\n\n" \ No newline at end of file diff --git a/django_simple_plausible/__init__.py b/django_simple_plausible/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_simple_plausible/templatetags/__init__.py b/django_simple_plausible/templatetags/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/django_simple_plausible/templatetags/plausible.py b/django_simple_plausible/templatetags/plausible.py new file mode 100644 index 0000000..cc94bbb --- /dev/null +++ b/django_simple_plausible/templatetags/plausible.py @@ -0,0 +1,21 @@ +from django import template +from django.conf import settings +from django.forms.utils import flatatt +from django.utils.safestring import mark_safe + +register = template.Library() + + +@register.simple_tag() +def plausible(site_domains=None, script_url=None): + if site_domains is None: + site_domains = getattr(settings, "PLAUSIBLE_SITES", "plausible.io") + if script_url is None: + script_url = getattr(settings, "PLAUSIBLE_SCRIPT_URL", "https://plausible.io/js/plausible.js") + + attrs = { + "data-domain": site_domains, + "src": script_url, + } + + return mark_safe("".format(flatatt(attrs))) diff --git a/pyproject.toml b/pyproject.toml new file mode 100644 index 0000000..b5a3c46 --- /dev/null +++ b/pyproject.toml @@ -0,0 +1,6 @@ +[build-system] +requires = [ + "setuptools>=42", + "wheel" +] +build-backend = "setuptools.build_meta" \ No newline at end of file diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..51e16c7 --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +build +twine \ No newline at end of file diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..70ae7e5 --- /dev/null +++ b/setup.py @@ -0,0 +1,28 @@ +import codecs +import setuptools + +with codecs.open("README.md", "r", encoding="utf-8") as fh: + long_description = fh.read() + +setuptools.setup( + name="django_simple_plausible", + # name="django_simple_plausible-T-101-0.0.2-3", + version="0.0.3", + author="T-101", + description="A simple Django package to render Plausible Analytics html tag", + long_description=long_description, + long_description_content_type="text/markdown", + url="https://github.com/T-101/django-simple-plausible", + project_urls={}, + classifiers=[ + "Programming Language :: Python :: 2", + "Programming Language :: Python :: 3", + "License :: OSI Approved :: MIT License", + "Operating System :: OS Independent", + "Framework :: Django", + "Environment :: Web Environment", + ], + packages=setuptools.find_packages(exclude=["tests"]), + python_requires=">=2.7", + options={"bdist_wheel": {"universal": True}}, +)