1
0

meta.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. """Display the title of the current page."""
  2. from __future__ import annotations
  3. from typing import Optional
  4. from reflex.components.base.bare import Bare
  5. from reflex.components.component import Component
  6. class Title(Component):
  7. """A component that displays the title of the current page."""
  8. tag = "title"
  9. def render(self) -> dict:
  10. """Render the title component.
  11. Raises:
  12. ValueError: If the title is not a single string.
  13. Returns:
  14. The rendered title component.
  15. """
  16. # Make sure the title is a single string.
  17. if len(self.children) != 1 or not isinstance(self.children[0], Bare):
  18. raise ValueError("Title must be a single string.")
  19. return super().render()
  20. class Meta(Component):
  21. """A component that displays metadata for the current page."""
  22. tag = "meta"
  23. # The description of character encoding.
  24. char_set: Optional[str] = None
  25. # The value of meta.
  26. content: Optional[str] = None
  27. # The name of metadata.
  28. name: Optional[str] = None
  29. # The type of metadata value.
  30. property: Optional[str] = None
  31. # The type of metadata value.
  32. http_equiv: Optional[str] = None
  33. class Description(Meta):
  34. """A component that displays the title of the current page."""
  35. # The type of the description.
  36. name: str | None = "description"
  37. class Image(Meta):
  38. """A component that displays the title of the current page."""
  39. # The type of the image.
  40. property: str | None = "og:image"