Skip to content

Commit

Permalink
Avoid adding double title to spotlight pages with a title field (fix #84
Browse files Browse the repository at this point in the history
)
  • Loading branch information
object-Object committed Feb 3, 2025
1 parent 9dfa14e commit 46be72e
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
17 changes: 17 additions & 0 deletions noxfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -299,6 +299,23 @@ def dummy_setup(session: nox.Session):
"type": "dummy:example",
"example_value": "insert funny message here",
},
{
"type": "patchouli:spotlight",
"text": "spotlight!",
"item": "minecraft:stone",
},
{
"type": "patchouli:spotlight",
"title": "title!",
"text": "spotlight with title!",
"item": "minecraft:stone",
},
{
"type": "patchouli:spotlight",
"text": "spotlight with anchor!",
"item": "minecraft:stone",
"anchor": "spotlight",
},
],
},
"entries/patchistuff.json": {
Expand Down
3 changes: 2 additions & 1 deletion src/hexdoc/_templates/pages/patchouli/spotlight.html.jinja
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
{% import "macros/textures.html.jinja" as texture_macros with context -%}

{% block inner_body %}
<h4 class="spotlight-title page-header">{{ page.item.name }}</h4>
<div class="spotlight">
<img
alt="Spotlight inventory slot"
Expand All @@ -16,3 +15,5 @@
{% block redirect_image -%}
{{ texture_macros.item_url(page.item) }}
{%- endblock redirect_image %}

{% block title_attrs %} class="spotlight-title page-header"{% endblock title_attrs %}
9 changes: 7 additions & 2 deletions src/hexdoc/patchouli/page/pages.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from collections import defaultdict
from typing import Self

from pydantic import ValidationInfo, field_validator, model_validator
from pydantic import Field, ValidationInfo, field_validator, model_validator

from hexdoc.core import Entity, ItemStack, ResourceLocation
from hexdoc.minecraft import I18n, LocalizedStr
Expand Down Expand Up @@ -167,6 +167,11 @@ class StonecuttingPage(
pass


class SpotlightPage(PageWithTitle, type="patchouli:spotlight"):
class SpotlightPage(PageWithText, type="patchouli:spotlight"):
title_field: LocalizedStr | None = Field(default=None, alias="title")
item: ItemWithTexture
link_recipe: bool = False

@property
def title(self) -> LocalizedStr | None:
return self.title_field or self.item.name

0 comments on commit 46be72e

Please sign in to comment.