fix: ✏️ improve meta tags
This commit is contained in:
parent
71a09a1cfd
commit
ab34546528
6 changed files with 48 additions and 7 deletions
|
|
@ -3,7 +3,15 @@
|
||||||
<head>
|
<head>
|
||||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<meta charset="utf-8">
|
<meta charset="utf-8">
|
||||||
<title>moku.blog</title>
|
<title>{% if page_title %}{{ page_title }} — {% endif %}moku.blog</title>
|
||||||
|
{% if page_title %}<meta property="og:title" content="{{ page_title }}">{% endif %}
|
||||||
|
<meta property="og:site_name" content="moku.blog">
|
||||||
|
<meta property="og:type" content="{{ opengraph_type or "website" }}">
|
||||||
|
<meta property="og:description" content="a lightweight food blogging website">
|
||||||
|
<meta name="description" content="a lightweight food blogging website">
|
||||||
|
<meta property="og:url" content="{{ site_root_url }}{{ request.path }}">
|
||||||
|
<link rel="canonical" href="{{ site_root_url }}{{ request.path }}">
|
||||||
|
<meta name="theme-color" content="#c94c10">
|
||||||
<link rel="stylesheet" href="{{ static('css/reset.css') }}" type="text/css">
|
<link rel="stylesheet" href="{{ static('css/reset.css') }}" type="text/css">
|
||||||
<link rel="stylesheet" href="{{ static('css/moku.css') }}" type="text/css">
|
<link rel="stylesheet" href="{{ static('css/moku.css') }}" type="text/css">
|
||||||
<link rel="shortcut icon" href="{{ static('images/favicon.png') }}" type="image/png">
|
<link rel="shortcut icon" href="{{ static('images/favicon.png') }}" type="image/png">
|
||||||
|
|
|
||||||
|
|
@ -12,6 +12,7 @@ class LoginView(View, BaseLoginView):
|
||||||
"""Allows users to log in by username and password."""
|
"""Allows users to log in by username and password."""
|
||||||
|
|
||||||
template_name = "moku/login.jinja"
|
template_name = "moku/login.jinja"
|
||||||
|
page_title = "log in"
|
||||||
|
|
||||||
def get(self, request, *args, **kwargs):
|
def get(self, request, *args, **kwargs):
|
||||||
if self.request.user.is_authenticated:
|
if self.request.user.is_authenticated:
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,23 @@
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
from django.conf import settings
|
||||||
from django.views import generic
|
from django.views import generic
|
||||||
|
|
||||||
|
|
||||||
class View(generic.TemplateView):
|
class View(generic.TemplateView):
|
||||||
"""Defines a common set of data to be passed to the template context."""
|
"""Defines a common set of data to be passed to the template context."""
|
||||||
|
|
||||||
|
page_title = None
|
||||||
|
"""The title of the current page. Should be overridden by subclasses."""
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
return {
|
return {
|
||||||
**super().get_context_data(**kwargs),
|
**super().get_context_data(**kwargs),
|
||||||
"header_emoji": random.choice(
|
"header_emoji": random.choice(
|
||||||
["🍔", "🍕", "🍟", "🥪", "🥘", "🍰", "🍻", "🧁", "🍞", "🥯", "🥐"]
|
["🍔", "🍕", "🍟", "🥪", "🥘", "🍰", "🍻", "🧁", "🍞", "🥯", "🥐"]
|
||||||
),
|
),
|
||||||
|
"site_root_url": settings.SITE_ROOT_URL,
|
||||||
|
"page_title": self.page_title,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ from django.contrib import messages
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin, UserPassesTestMixin
|
||||||
from django.shortcuts import get_object_or_404, redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils.functional import cached_property
|
from django.utils.functional import cached_property
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.translation import gettext as _, gettext_lazy as _l
|
||||||
|
|
||||||
from moku.forms.recipe import RecipeForm, RecipeStepForm
|
from moku.forms.recipe import RecipeForm, RecipeStepForm
|
||||||
from moku.models.recipe import Recipe, RecipeStep
|
from moku.models.recipe import Recipe, RecipeStep
|
||||||
|
|
@ -56,6 +56,10 @@ class EditStepView(LoginRequiredMixin, UserPassesTestMixin, FormView):
|
||||||
template_name = "moku/recipe/edit_step.jinja"
|
template_name = "moku/recipe/edit_step.jinja"
|
||||||
form_class = RecipeStepForm
|
form_class = RecipeStepForm
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_title(self):
|
||||||
|
return f"edit: step #{self.step.order + 1} of {self.step.recipe.title}"
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.save()
|
form.save()
|
||||||
messages.success(self.request, _("step updated!"))
|
messages.success(self.request, _("step updated!"))
|
||||||
|
|
@ -80,6 +84,7 @@ class IndexRecipeView(LoginRequiredMixin, View):
|
||||||
"""Shows a list of recipes created by the authenticated user."""
|
"""Shows a list of recipes created by the authenticated user."""
|
||||||
|
|
||||||
template_name = "moku/recipe/index.jinja"
|
template_name = "moku/recipe/index.jinja"
|
||||||
|
page_title = _l("my recipes")
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
return {
|
return {
|
||||||
|
|
@ -95,6 +100,7 @@ class NewRecipeView(LoginRequiredMixin, FormView):
|
||||||
|
|
||||||
template_name = "moku/recipe/form.jinja"
|
template_name = "moku/recipe/form.jinja"
|
||||||
form_class = RecipeForm
|
form_class = RecipeForm
|
||||||
|
page_title = _l("new recipe")
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.created_by = self.request.user
|
form.instance.created_by = self.request.user
|
||||||
|
|
@ -115,6 +121,10 @@ class ShowRecipeView(FormView):
|
||||||
template_name = "moku/recipe/show.jinja"
|
template_name = "moku/recipe/show.jinja"
|
||||||
form_class = RecipeStepForm
|
form_class = RecipeStepForm
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_title(self):
|
||||||
|
return self.recipe.title
|
||||||
|
|
||||||
@cached_property
|
@cached_property
|
||||||
def recipe(self):
|
def recipe(self):
|
||||||
return Recipe.objects.get(uuid=self.kwargs.get("uuid"))
|
return Recipe.objects.get(uuid=self.kwargs.get("uuid"))
|
||||||
|
|
|
||||||
|
|
@ -1,3 +1,5 @@
|
||||||
|
from django.utils.translation import gettext_lazy as _l
|
||||||
|
|
||||||
from moku.views.base import View
|
from moku.views.base import View
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -5,15 +7,18 @@ class ChangelogView(View):
|
||||||
"""Displays the static changelog page."""
|
"""Displays the static changelog page."""
|
||||||
|
|
||||||
template_name = "moku/changelog.jinja"
|
template_name = "moku/changelog.jinja"
|
||||||
|
page_title = _l("changelog")
|
||||||
|
|
||||||
|
|
||||||
class PrivacyView(View):
|
class PrivacyView(View):
|
||||||
"""Displays the static privacy policy page."""
|
"""Displays the static privacy policy page."""
|
||||||
|
|
||||||
template_name = "moku/privacy.jinja"
|
template_name = "moku/privacy.jinja"
|
||||||
|
page_title = _l("privacy policy")
|
||||||
|
|
||||||
|
|
||||||
class TermsView(View):
|
class TermsView(View):
|
||||||
"""Displays the static terms of use page."""
|
"""Displays the static terms of use page."""
|
||||||
|
|
||||||
template_name = "moku/terms.jinja"
|
template_name = "moku/terms.jinja"
|
||||||
|
page_title = _l("terms of use")
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,9 @@
|
||||||
from django.contrib import messages
|
from django.contrib import messages
|
||||||
from django.contrib.auth.mixins import LoginRequiredMixin
|
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||||
from django.db import IntegrityError
|
from django.db import IntegrityError
|
||||||
from django.shortcuts import redirect
|
from django.shortcuts import get_object_or_404, redirect
|
||||||
from django.utils.translation import gettext as _
|
from django.utils.functional import cached_property
|
||||||
|
from django.utils.translation import gettext as _, gettext_lazy as _l
|
||||||
|
|
||||||
from moku.forms.user import ProfileForm, UserForm, UserSettingsForm
|
from moku.forms.user import ProfileForm, UserForm, UserSettingsForm
|
||||||
from moku.images import process_avatar_image
|
from moku.images import process_avatar_image
|
||||||
|
|
@ -15,6 +16,7 @@ class EditProfileView(LoginRequiredMixin, FormView):
|
||||||
|
|
||||||
template_name = "moku/profile/edit.jinja"
|
template_name = "moku/profile/edit.jinja"
|
||||||
form_class = ProfileForm
|
form_class = ProfileForm
|
||||||
|
page_title = _l("edit profile")
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
if "avatar" in form.changed_data and form.instance.avatar is not None:
|
if "avatar" in form.changed_data and form.instance.avatar is not None:
|
||||||
|
|
@ -32,6 +34,7 @@ class EditSettingsView(LoginRequiredMixin, FormView):
|
||||||
|
|
||||||
template_name = "moku/settings.jinja"
|
template_name = "moku/settings.jinja"
|
||||||
form_class = UserSettingsForm
|
form_class = UserSettingsForm
|
||||||
|
page_title = _("settings")
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.user = self.request.user
|
form.instance.user = self.request.user
|
||||||
|
|
@ -58,12 +61,19 @@ class ProfileView(View):
|
||||||
|
|
||||||
template_name = "moku/profile/show.jinja"
|
template_name = "moku/profile/show.jinja"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def page_title(self):
|
||||||
|
return f"@{self.profile.username}"
|
||||||
|
|
||||||
|
@cached_property
|
||||||
|
def profile(self):
|
||||||
|
return get_object_or_404(User, username=self.kwargs.get("username"))
|
||||||
|
|
||||||
def get_context_data(self, **kwargs):
|
def get_context_data(self, **kwargs):
|
||||||
user = User.objects.get(username=self.kwargs.get("username"))
|
|
||||||
return {
|
return {
|
||||||
**super().get_context_data(**kwargs),
|
**super().get_context_data(**kwargs),
|
||||||
"profile": user,
|
"profile": self.profile,
|
||||||
"posts": user.posts.order_by("-created_at").all(),
|
"posts": self.profile.posts.order_by("-created_at").all(),
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -72,6 +82,7 @@ class SignupView(FormView):
|
||||||
|
|
||||||
template_name = "moku/signup.jinja"
|
template_name = "moku/signup.jinja"
|
||||||
form_class = UserForm
|
form_class = UserForm
|
||||||
|
page_title = _("sign up")
|
||||||
|
|
||||||
def form_valid(self, form):
|
def form_valid(self, form):
|
||||||
form.instance.username = form.instance.username.lower()
|
form.instance.username = form.instance.username.lower()
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue