diff --git a/.gitignore b/.gitignore index faa416f..7d372ff 100644 --- a/.gitignore +++ b/.gitignore @@ -304,3 +304,4 @@ cython_debug/ # End of https://www.toptal.com/developers/gitignore/api/python,node /collected-static +media/ diff --git a/static/src/scss/_hero.scss b/static/src/scss/_hero.scss index d6357a7..f638658 100644 --- a/static/src/scss/_hero.scss +++ b/static/src/scss/_hero.scss @@ -1,3 +1,9 @@ +img.hero { + height: 40vh !important; + width: 100%; + object-fit: cover; +} + section.hero { position: sticky; top: 0; diff --git a/static/src/scss/_homepage.scss b/static/src/scss/_homepage.scss index 06665e5..d472a94 100644 --- a/static/src/scss/_homepage.scss +++ b/static/src/scss/_homepage.scss @@ -3,8 +3,9 @@ body.page-home-homepage { flex-direction: column; main { - // TODO: Image background - background-color: orange; + background-repeat: no-repeat; + background-size: cover; + background-position: center; height: 100%; display: flex; justify-content: center; diff --git a/templates/base.html b/templates/base.html index 282a55a..6be69d4 100644 --- a/templates/base.html +++ b/templates/base.html @@ -27,9 +27,11 @@ {% navbar page %} {% endcache %} -
- {% block content %}{% endblock %} -
+ {% block main %} +
+ {% block content %}{% endblock %} +
+ {% endblock %} {% cache 3600 "footer" %} {% footer %} diff --git a/website/common/migrations/0002_contentpage_hero_image.py b/website/common/migrations/0002_contentpage_hero_image.py new file mode 100644 index 0000000..df8422e --- /dev/null +++ b/website/common/migrations/0002_contentpage_hero_image.py @@ -0,0 +1,24 @@ +# Generated by Django 4.0.5 on 2022-06-15 08:11 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailimages", "0024_index_image_file_hash"), + ("common", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="contentpage", + name="hero_image", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="wagtailimages.image", + ), + ), + ] diff --git a/website/common/models.py b/website/common/models.py index 0ca821c..081bb77 100644 --- a/website/common/models.py +++ b/website/common/models.py @@ -1,6 +1,7 @@ from django.db import models from django.utils.functional import classproperty from wagtail.admin.panels import FieldPanel +from wagtail.images import get_image_model_string from wagtail.models import Page @@ -15,5 +16,11 @@ class BasePage(Page): class ContentPage(BasePage): subtitle = models.CharField(max_length=255, blank=True) + hero_image = models.ForeignKey( + get_image_model_string(), null=True, on_delete=models.SET_NULL + ) - content_panels = BasePage.content_panels + [FieldPanel("subtitle")] + content_panels = BasePage.content_panels + [ + FieldPanel("subtitle"), + FieldPanel("hero_image"), + ] diff --git a/website/common/templates/common/content_page.html b/website/common/templates/common/content_page.html index b85627b..8d77f95 100644 --- a/website/common/templates/common/content_page.html +++ b/website/common/templates/common/content_page.html @@ -1,6 +1,10 @@ {% extends "wagtail_base.html" %} +{% load wagtailimages_tags %} + {% block content %} + +
diff --git a/website/home/migrations/0004_homepage_image.py b/website/home/migrations/0004_homepage_image.py new file mode 100644 index 0000000..bcfb8d6 --- /dev/null +++ b/website/home/migrations/0004_homepage_image.py @@ -0,0 +1,24 @@ +# Generated by Django 4.0.5 on 2022-06-15 08:10 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("wagtailimages", "0024_index_image_file_hash"), + ("home", "0003_homepage_heading"), + ] + + operations = [ + migrations.AddField( + model_name="homepage", + name="image", + field=models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + to="wagtailimages.image", + ), + ), + ] diff --git a/website/home/models.py b/website/home/models.py index 3cec0f9..c56b698 100644 --- a/website/home/models.py +++ b/website/home/models.py @@ -1,5 +1,6 @@ from django.db import models from wagtail.admin.panels import FieldPanel +from wagtail.images import get_image_model_string from website.common.models import BasePage @@ -8,5 +9,11 @@ class HomePage(BasePage): max_count = 1 heading = models.CharField(max_length=128, blank=True) + image = models.ForeignKey( + get_image_model_string(), null=True, on_delete=models.SET_NULL + ) - content_panels = BasePage.content_panels + [FieldPanel("heading")] + content_panels = BasePage.content_panels + [ + FieldPanel("heading"), + FieldPanel("image"), + ] diff --git a/website/home/templates/home/home_page.html b/website/home/templates/home/home_page.html index bcfb427..ec03cd2 100644 --- a/website/home/templates/home/home_page.html +++ b/website/home/templates/home/home_page.html @@ -1,13 +1,17 @@ {% extends "wagtail_base.html" %} -{% block content %} -

{{ page.heading }}

+{% load wagtailimages_tags %} - +{% block main %} +
+

{{ page.heading }}

-
- Latest Post: {% lorem 6 w random %} → -
-{% endblock content %} + + +
+ Latest Post: {% lorem 6 w random %} → +
+
+{% endblock %} {% block darkmode %}{% endblock %} diff --git a/website/urls.py b/website/urls.py index ae44f25..d4d06bb 100644 --- a/website/urls.py +++ b/website/urls.py @@ -1,9 +1,10 @@ from django.conf import settings from django.contrib import admin -from django.urls import include, path +from django.urls import include, path, re_path from wagtail import urls as wagtail_urls from wagtail.admin import urls as wagtailadmin_urls from wagtail.documents import urls as wagtaildocs_urls +from wagtail.images.views.serve import ServeView from website.search import views as search_views @@ -12,6 +13,11 @@ urlpatterns = [ path("admin/", include(wagtailadmin_urls)), path("documents/", include(wagtaildocs_urls)), path("search/", search_views.search, name="search"), + re_path( + r"^images/([^/]*)/(\d*)/([^/]*)/[^/]*$", + ServeView.as_view(action="redirect"), + name="wagtailimages_serve", + ), ]