Skip to content
Snippets Groups Projects
Commit 665b8fc8 authored by jan.bednarik's avatar jan.bednarik
Browse files

donate: SEO stuff

parent cc803952
No related branches found
No related tags found
No related merge requests found
# Generated by Django 3.0.6 on 2020-06-01 21:24
import django.db.models.deletion
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
("wagtailimages", "0022_uploadedimage"),
("donate", "0001_initial"),
]
operations = [
migrations.AddField(
model_name="donatehomepage",
name="search_image",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.Image",
verbose_name="Search image",
),
),
migrations.AddField(
model_name="donateprojectindexpage",
name="search_image",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.Image",
verbose_name="Search image",
),
),
migrations.AddField(
model_name="donateregionindexpage",
name="search_image",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.Image",
verbose_name="Search image",
),
),
migrations.AddField(
model_name="donateregionpage",
name="search_image",
field=models.ForeignKey(
blank=True,
null=True,
on_delete=django.db.models.deletion.SET_NULL,
related_name="+",
to="wagtailimages.Image",
verbose_name="Search image",
),
),
]
...@@ -10,6 +10,22 @@ from wagtail.core.fields import RichTextField, StreamField ...@@ -10,6 +10,22 @@ from wagtail.core.fields import RichTextField, StreamField
from wagtail.core.models import Page from wagtail.core.models import Page
from wagtail.images.blocks import ImageChooserBlock from wagtail.images.blocks import ImageChooserBlock
from wagtail.images.edit_handlers import ImageChooserPanel from wagtail.images.edit_handlers import ImageChooserPanel
from wagtailmetadata.models import MetadataPageMixin
from tuning import help
class SubpageMixin:
"""Must be used in class definition before MetadataPageMixin!"""
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_parent().specific
return self._root_page
def get_meta_image(self):
return self.search_image or self.root_page.get_meta_image()
def get_url(page, request, dest_page_type): def get_url(page, request, dest_page_type):
...@@ -19,7 +35,7 @@ def get_url(page, request, dest_page_type): ...@@ -19,7 +35,7 @@ def get_url(page, request, dest_page_type):
return "#" return "#"
class DonateHomePage(Page): class DonateHomePage(Page, MetadataPageMixin):
# lead section # lead section
lead_title = models.CharField("hlavní nadpis", max_length=250, blank=True) lead_title = models.CharField("hlavní nadpis", max_length=250, blank=True)
lead_body = models.TextField("hlavní popis", blank=True) lead_body = models.TextField("hlavní popis", blank=True)
...@@ -75,12 +91,10 @@ class DonateHomePage(Page): ...@@ -75,12 +91,10 @@ class DonateHomePage(Page):
promote_panels = [ promote_panels = [
MultiFieldPanel( MultiFieldPanel(
[ [
HelpPanel(
"Název stránky na předchozím tabu slouží k rozlišení stránek "
"v Majáku. V prohlížeči se zobrazí tento titulek."
),
FieldPanel("seo_title"), FieldPanel("seo_title"),
FieldPanel("search_description"), FieldPanel("search_description"),
ImageChooserPanel("search_image"),
HelpPanel(help.build(help.IMPORTANT_TITLE)),
], ],
gettext_lazy("Common page configuration"), gettext_lazy("Common page configuration"),
), ),
...@@ -131,13 +145,15 @@ class DonateHomePage(Page): ...@@ -131,13 +145,15 @@ class DonateHomePage(Page):
return context return context
class DonateRegionIndexPage(Page): class DonateRegionIndexPage(Page, SubpageMixin, MetadataPageMixin):
promote_panels = [ promote_panels = [
MultiFieldPanel( MultiFieldPanel(
[ [
FieldPanel("slug"), FieldPanel("slug"),
FieldPanel("seo_title"), FieldPanel("seo_title"),
FieldPanel("search_description"), FieldPanel("search_description"),
ImageChooserPanel("search_image"),
HelpPanel(help.build(help.NO_SEO_TITLE, help.NO_SEARCH_IMAGE)),
], ],
gettext_lazy("Common page configuration"), gettext_lazy("Common page configuration"),
), ),
...@@ -154,19 +170,13 @@ class DonateRegionIndexPage(Page): ...@@ -154,19 +170,13 @@ class DonateRegionIndexPage(Page):
class Meta: class Meta:
verbose_name = "Přehled krajů" verbose_name = "Přehled krajů"
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_parent().specific
return self._root_page
def get_context(self, request): def get_context(self, request):
context = super().get_context(request) context = super().get_context(request)
context["regions"] = self.get_children().live().specific() context["regions"] = self.get_children().live().specific()
return context return context
class DonateRegionPage(Page): class DonateRegionPage(Page, SubpageMixin, MetadataPageMixin):
perex = models.TextField("krátký popis do přehledu krajů") perex = models.TextField("krátký popis do přehledu krajů")
main_title = models.CharField("hlavní nadpis na stránce", max_length=250) main_title = models.CharField("hlavní nadpis na stránce", max_length=250)
body = RichTextField("obsah") body = RichTextField("obsah")
...@@ -183,6 +193,14 @@ class DonateRegionPage(Page): ...@@ -183,6 +193,14 @@ class DonateRegionPage(Page):
FieldPanel("slug"), FieldPanel("slug"),
FieldPanel("seo_title"), FieldPanel("seo_title"),
FieldPanel("search_description"), FieldPanel("search_description"),
ImageChooserPanel("search_image"),
HelpPanel(
help.build(
"Pokud není zadán <strong>Titulek stránky</strong>, použije "
"se <strong>Hlavní nadpis</strong> (tab obsah).",
help.NO_SEARCH_IMAGE,
)
),
], ],
gettext_lazy("Common page configuration"), gettext_lazy("Common page configuration"),
), ),
...@@ -205,19 +223,24 @@ class DonateRegionPage(Page): ...@@ -205,19 +223,24 @@ class DonateRegionPage(Page):
self._root_page = self.get_ancestors().type(DonateHomePage).specific().get() self._root_page = self.get_ancestors().type(DonateHomePage).specific().get()
return self._root_page return self._root_page
def get_meta_title(self):
return self.seo_title or self.main_title
def get_context(self, request): def get_context(self, request):
context = super().get_context(request) context = super().get_context(request)
context["other_regions"] = self.get_siblings(inclusive=False).live() context["other_regions"] = self.get_siblings(inclusive=False).live()
return context return context
class DonateProjectIndexPage(Page): class DonateProjectIndexPage(Page, SubpageMixin, MetadataPageMixin):
promote_panels = [ promote_panels = [
MultiFieldPanel( MultiFieldPanel(
[ [
FieldPanel("slug"), FieldPanel("slug"),
FieldPanel("seo_title"), FieldPanel("seo_title"),
FieldPanel("search_description"), FieldPanel("search_description"),
ImageChooserPanel("search_image"),
HelpPanel(help.build(help.NO_SEO_TITLE, help.NO_SEARCH_IMAGE)),
], ],
gettext_lazy("Common page configuration"), gettext_lazy("Common page configuration"),
), ),
...@@ -234,12 +257,6 @@ class DonateProjectIndexPage(Page): ...@@ -234,12 +257,6 @@ class DonateProjectIndexPage(Page):
class Meta: class Meta:
verbose_name = "Přehled projektů" verbose_name = "Přehled projektů"
@property
def root_page(self):
if not hasattr(self, "_root_page"):
self._root_page = self.get_parent().specific
return self._root_page
def get_context(self, request): def get_context(self, request):
context = super().get_context(request) context = super().get_context(request)
context["projects"] = ( context["projects"] = (
...@@ -248,7 +265,7 @@ class DonateProjectIndexPage(Page): ...@@ -248,7 +265,7 @@ class DonateProjectIndexPage(Page):
return context return context
class DonateProjectPage(Page): class DonateProjectPage(Page, SubpageMixin, MetadataPageMixin):
date = models.DateField("běží od") date = models.DateField("běží od")
perex = models.TextField("krátký popis") perex = models.TextField("krátký popis")
body = RichTextField("obsah") body = RichTextField("obsah")
...@@ -265,6 +282,8 @@ class DonateProjectPage(Page): ...@@ -265,6 +282,8 @@ class DonateProjectPage(Page):
verbose_name="galerie fotek", verbose_name="galerie fotek",
blank=True, blank=True,
) )
# we will use photo as search image
search_image = None
content_panels = Page.content_panels + [ content_panels = Page.content_panels + [
MultiFieldPanel( MultiFieldPanel(
...@@ -282,6 +301,14 @@ class DonateProjectPage(Page): ...@@ -282,6 +301,14 @@ class DonateProjectPage(Page):
FieldPanel("slug"), FieldPanel("slug"),
FieldPanel("seo_title"), FieldPanel("seo_title"),
FieldPanel("search_description"), FieldPanel("search_description"),
HelpPanel(
help.build(
"Pokud není zadán <strong>Titulek stránky</strong>, použije "
"se „Podpoř projekt <strong>Název</strong>“ (tab obsah).",
"Pokud není zadán <strong>Popis vyhledávání</strong>, použije "
"se prvních 150 znaků <strong>Perexu</strong> (tab obsah).",
)
),
], ],
gettext_lazy("Common page configuration"), gettext_lazy("Common page configuration"),
), ),
...@@ -302,6 +329,23 @@ class DonateProjectPage(Page): ...@@ -302,6 +329,23 @@ class DonateProjectPage(Page):
self._root_page = self.get_ancestors().type(DonateHomePage).specific().get() self._root_page = self.get_ancestors().type(DonateHomePage).specific().get()
return self._root_page return self._root_page
def get_meta_image(self):
return self.photo
def get_meta_title(self):
return self.seo_title or self.main_title
def get_meta_description(self):
if self.search_description:
return self.search_description
if len(self.perex) > 150:
return str(self.perex)[:150] + "..."
return self.perex
@property
def main_title(self):
return f"Podpoř projekt {self.title}"
def get_context(self, request): def get_context(self, request):
context = super().get_context(request) context = super().get_context(request)
context["other_projects"] = ( context["other_projects"] = (
......
{% load static wagtailuserbar wagtailcore_tags wagtailimages_tags %} {% load static wagtailuserbar wagtailcore_tags wagtailimages_tags wagtailmetadata_tags %}
<!doctype html> <!doctype html>
<html lang="cs"> <html lang="cs">
<head> <head>
...@@ -21,25 +21,10 @@ ...@@ -21,25 +21,10 @@
<!-- Meta --> <!-- Meta -->
<meta charset="utf-8"> <meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no"> <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<meta name="description" content="{{ page.search_description }}"> {% meta_tags %}
<meta name="author" content="Daniel Hlavacek">
<title>{% firstof page.seo_title page.title %}</title>
<!-- OpenGraph info -->
<meta property="og:title" content="{% firstof page.seo_title page.title %}" />
<meta property="og:type" content="website" />
<meta property="og:locale" content="cs_CZ" />
<meta property="og:url" content="{{ page.full_url }}" />
{# TODO #}
<meta property="og:image" content="{% static "shared/img/og_image.jpg" %}" />
<meta property="og:description" content="{{ page.search_description }}" />
<!-- Favicon --> <!-- Favicon -->
<link rel="icon" type="image/png" href="{% static "shared/favicon/favicon-196.png" %}" sizes="196x196"> {% include "shared/favicon_snippet.html" %}
<link rel="icon" type="image/png" href="{% static "shared/favicon/favicon-128.png" %}" sizes="128x128">
<link rel="icon" type="image/png" href="{% static "shared/favicon/favicon-96.png" %}" sizes="96x96">
<link rel="icon" type="image/png" href="{% static "shared/favicon/favicon-32.png" %}" sizes="32x32">
<link rel="icon" type="image/png" href="{% static "shared/favicon/favicon-16.png" %}" sizes="16x16">
<!-- Bootstrap CSS --> <!-- Bootstrap CSS -->
<link rel="stylesheet" href="{% static "shared/vendor/bootstrap-4.4.1/css/bootstrap.min.css" %}"> <link rel="stylesheet" href="{% static "shared/vendor/bootstrap-4.4.1/css/bootstrap.min.css" %}">
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
<section class="section--alternate project__header"> <section class="section--alternate project__header">
<div class="container"> <div class="container">
<h1 class="lead heading">Podpoř projekt {{ page.title }}</h1> <h1 class="lead heading">{{ page.main_title }}</h1>
<div class="row align-items-center"> <div class="row align-items-center">
<div class="col-12 col-md-6 mb-3 mb-md-0"> <div class="col-12 col-md-6 mb-3 mb-md-0">
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment