2020-09-12 17:02:29 +02:00
|
|
|
from django.conf import settings
|
|
|
|
|
2020-12-24 17:49:47 +01:00
|
|
|
from articles.models import Article
|
2020-11-28 20:09:37 +01:00
|
|
|
from attachments.models import Attachment
|
2020-08-17 09:57:24 +02:00
|
|
|
|
2020-09-05 09:04:45 +02:00
|
|
|
IGNORED_PATHS = [
|
|
|
|
"/robots.txt",
|
|
|
|
]
|
|
|
|
|
2020-08-17 09:57:24 +02:00
|
|
|
|
2020-08-18 14:23:51 +02:00
|
|
|
def drafts_count(request):
|
2020-09-05 09:04:45 +02:00
|
|
|
if request.path in IGNORED_PATHS:
|
|
|
|
return {}
|
2021-03-20 11:26:44 +01:00
|
|
|
if not request.user.is_authenticated:
|
|
|
|
return {}
|
2020-09-03 22:00:28 +02:00
|
|
|
return {"drafts_count": Article.objects.filter(status=Article.DRAFT).count()}
|
2020-08-25 23:11:15 +02:00
|
|
|
|
|
|
|
|
|
|
|
def date_format(request):
|
2020-09-05 09:04:45 +02:00
|
|
|
if request.path in IGNORED_PATHS:
|
|
|
|
return {}
|
2020-12-06 16:51:49 +01:00
|
|
|
return {"CUSTOM_ISO": r"Y-m-d\TH:i:sO", "ISO_DATE": "Y-m-d"}
|
2020-09-09 18:32:46 +02:00
|
|
|
|
|
|
|
|
|
|
|
def git_version(request):
|
|
|
|
if request.path in IGNORED_PATHS:
|
|
|
|
return {}
|
|
|
|
try:
|
|
|
|
with open("/app/.version") as f:
|
2020-09-12 17:02:29 +02:00
|
|
|
version = f.read().strip()
|
|
|
|
url = settings.BLOG["repo"]["commit_url"].format(commit_sha=version)
|
|
|
|
version = version[:8]
|
2020-09-09 18:32:46 +02:00
|
|
|
except FileNotFoundError:
|
|
|
|
version = "latest"
|
2020-09-12 17:02:29 +02:00
|
|
|
url = settings.BLOG["repo"]["log"]
|
|
|
|
return {"git_version": version, "git_version_url": url}
|
2020-11-10 15:44:05 +01:00
|
|
|
|
|
|
|
|
2021-01-04 21:32:03 +01:00
|
|
|
def analytics(request):
|
|
|
|
return {
|
|
|
|
"goatcounter_domain": settings.GOATCOUNTER_DOMAIN,
|
|
|
|
}
|
2020-11-28 20:09:37 +01:00
|
|
|
|
|
|
|
|
2020-11-28 20:26:37 +01:00
|
|
|
def open_graph_image_url(request):
|
2020-11-28 20:29:55 +01:00
|
|
|
if request.path in IGNORED_PATHS:
|
|
|
|
return {}
|
2020-11-28 20:26:37 +01:00
|
|
|
open_graph_image = Attachment.objects.get_open_graph_image()
|
2020-11-28 20:29:55 +01:00
|
|
|
url = ""
|
|
|
|
if open_graph_image:
|
|
|
|
url = open_graph_image.processed_file.get_full_absolute_url(request)
|
|
|
|
return {"open_graph_image_url": url}
|
2020-12-24 17:49:47 +01:00
|
|
|
|
|
|
|
|
|
|
|
def blog_metadata(request):
|
|
|
|
context = {}
|
|
|
|
context["blog_title"] = settings.BLOG["title"]
|
|
|
|
context["blog_description"] = settings.BLOG["description"]
|
|
|
|
context["blog_author"] = settings.BLOG["author"]
|
2021-02-07 07:31:40 +01:00
|
|
|
context["blog_repo_homepage"] = settings.BLOG["repo"]["homepage"]
|
2021-07-31 09:48:08 +02:00
|
|
|
context["blog_status_url"] = settings.BLOG["status_url"]
|
2020-12-24 17:49:47 +01:00
|
|
|
return context
|