meta.py 1.5 KB

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