meta.py 1.5 KB

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