Skip to content

Commit 46be72e

Browse files
committed
Avoid adding double title to spotlight pages with a title field (fix #84)
1 parent 9dfa14e commit 46be72e

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

noxfile.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,23 @@ def dummy_setup(session: nox.Session):
299299
"type": "dummy:example",
300300
"example_value": "insert funny message here",
301301
},
302+
{
303+
"type": "patchouli:spotlight",
304+
"text": "spotlight!",
305+
"item": "minecraft:stone",
306+
},
307+
{
308+
"type": "patchouli:spotlight",
309+
"title": "title!",
310+
"text": "spotlight with title!",
311+
"item": "minecraft:stone",
312+
},
313+
{
314+
"type": "patchouli:spotlight",
315+
"text": "spotlight with anchor!",
316+
"item": "minecraft:stone",
317+
"anchor": "spotlight",
318+
},
302319
],
303320
},
304321
"entries/patchistuff.json": {

src/hexdoc/_templates/pages/patchouli/spotlight.html.jinja

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
{% import "macros/textures.html.jinja" as texture_macros with context -%}
33

44
{% block inner_body %}
5-
<h4 class="spotlight-title page-header">{{ page.item.name }}</h4>
65
<div class="spotlight">
76
<img
87
alt="Spotlight inventory slot"
@@ -16,3 +15,5 @@
1615
{% block redirect_image -%}
1716
{{ texture_macros.item_url(page.item) }}
1817
{%- endblock redirect_image %}
18+
19+
{% block title_attrs %} class="spotlight-title page-header"{% endblock title_attrs %}

src/hexdoc/patchouli/page/pages.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from collections import defaultdict
22
from typing import Self
33

4-
from pydantic import ValidationInfo, field_validator, model_validator
4+
from pydantic import Field, ValidationInfo, field_validator, model_validator
55

66
from hexdoc.core import Entity, ItemStack, ResourceLocation
77
from hexdoc.minecraft import I18n, LocalizedStr
@@ -167,6 +167,11 @@ class StonecuttingPage(
167167
pass
168168

169169

170-
class SpotlightPage(PageWithTitle, type="patchouli:spotlight"):
170+
class SpotlightPage(PageWithText, type="patchouli:spotlight"):
171+
title_field: LocalizedStr | None = Field(default=None, alias="title")
171172
item: ItemWithTexture
172173
link_recipe: bool = False
174+
175+
@property
176+
def title(self) -> LocalizedStr | None:
177+
return self.title_field or self.item.name

0 commit comments

Comments
 (0)