Add image figure block
This commit is contained in:
parent
38c4c695cf
commit
72f9374c03
4 changed files with 37 additions and 0 deletions
7
static/src/scss/_blocks.scss
Normal file
7
static/src/scss/_blocks.scss
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
div.block-image {
|
||||||
|
margin: 0.5rem 0;
|
||||||
|
|
||||||
|
figcaption {
|
||||||
|
font-size: 85%;
|
||||||
|
}
|
||||||
|
}
|
|
@ -9,6 +9,7 @@
|
||||||
@import "hero";
|
@import "hero";
|
||||||
@import "content";
|
@import "content";
|
||||||
@import "listing";
|
@import "listing";
|
||||||
|
@import "blocks";
|
||||||
|
|
||||||
html,
|
html,
|
||||||
body {
|
body {
|
||||||
|
|
|
@ -5,6 +5,7 @@ from django.utils.html import format_html_join, strip_tags
|
||||||
from django.utils.text import smart_split
|
from django.utils.text import smart_split
|
||||||
from wagtail import blocks
|
from wagtail import blocks
|
||||||
from wagtail.embeds.blocks import EmbedBlock
|
from wagtail.embeds.blocks import EmbedBlock
|
||||||
|
from wagtail.images.blocks import ImageChooserBlock
|
||||||
|
|
||||||
IGNORE_PLAINTEXT_BLOCKS = (blocks.RawHTMLBlock, EmbedBlock)
|
IGNORE_PLAINTEXT_BLOCKS = (blocks.RawHTMLBlock, EmbedBlock)
|
||||||
|
|
||||||
|
@ -25,6 +26,15 @@ RICH_TEXT_FEATURES = [
|
||||||
"strikethrough",
|
"strikethrough",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
RICH_TEXT_FEATURES_SIMPLE = [
|
||||||
|
"bold",
|
||||||
|
"italic",
|
||||||
|
"link",
|
||||||
|
"document-link",
|
||||||
|
"code",
|
||||||
|
"strikethrough",
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class LoremBlock(blocks.StructBlock):
|
class LoremBlock(blocks.StructBlock):
|
||||||
paragraphs = blocks.IntegerBlock(min_value=1)
|
paragraphs = blocks.IntegerBlock(min_value=1)
|
||||||
|
@ -41,12 +51,23 @@ class LoremBlock(blocks.StructBlock):
|
||||||
label = "Lorem Ipsum"
|
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]]:
|
def get_blocks() -> list[tuple[str, blocks.BaseBlock]]:
|
||||||
return [
|
return [
|
||||||
("embed", EmbedBlock()),
|
("embed", EmbedBlock()),
|
||||||
("rich_text", blocks.RichTextBlock(features=RICH_TEXT_FEATURES)),
|
("rich_text", blocks.RichTextBlock(features=RICH_TEXT_FEATURES)),
|
||||||
("lorem", LoremBlock()),
|
("lorem", LoremBlock()),
|
||||||
("html", blocks.RawHTMLBlock()),
|
("html", blocks.RawHTMLBlock()),
|
||||||
|
("image", ImageCaptionBlock()),
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -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>
|
Loading…
Reference in a new issue