Add image figure block

This commit is contained in:
Jake Howard 2022-06-27 20:40:55 +01:00
parent 38c4c695cf
commit 72f9374c03
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 37 additions and 0 deletions

View file

@ -0,0 +1,7 @@
div.block-image {
margin: 0.5rem 0;
figcaption {
font-size: 85%;
}
}

View file

@ -9,6 +9,7 @@
@import "hero";
@import "content";
@import "listing";
@import "blocks";
html,
body {

View file

@ -5,6 +5,7 @@ from django.utils.html import format_html_join, strip_tags
from django.utils.text import smart_split
from wagtail import blocks
from wagtail.embeds.blocks import EmbedBlock
from wagtail.images.blocks import ImageChooserBlock
IGNORE_PLAINTEXT_BLOCKS = (blocks.RawHTMLBlock, EmbedBlock)
@ -25,6 +26,15 @@ RICH_TEXT_FEATURES = [
"strikethrough",
]
RICH_TEXT_FEATURES_SIMPLE = [
"bold",
"italic",
"link",
"document-link",
"code",
"strikethrough",
]
class LoremBlock(blocks.StructBlock):
paragraphs = blocks.IntegerBlock(min_value=1)
@ -41,12 +51,23 @@ class LoremBlock(blocks.StructBlock):
label = "Lorem Ipsum"
class ImageCaptionBlock(blocks.StructBlock):
image = ImageChooserBlock()
caption = blocks.RichTextBlock(features=RICH_TEXT_FEATURES_SIMPLE)
class Meta:
icon = "image"
label = "Image with caption"
template = "common/blocks/image-caption.html"
def get_blocks() -> list[tuple[str, blocks.BaseBlock]]:
return [
("embed", EmbedBlock()),
("rich_text", blocks.RichTextBlock(features=RICH_TEXT_FEATURES)),
("lorem", LoremBlock()),
("html", blocks.RawHTMLBlock()),
("image", ImageCaptionBlock()),
]

View file

@ -0,0 +1,8 @@
{% load wagtailimages_tags wagtailcore_tags %}
<figure>
<img src="{% image_url value.image 'width-1500' %}" alt="" />
<figcaption>
{{ value.caption|richtext }}
</figcaption>
</figure>