meta.py 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  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. Returns:
  12. The rendered title component.
  13. """
  14. # Make sure the title is a single string.
  15. assert len(self.children) == 1 and isinstance(
  16. self.children[0], Bare
  17. ), "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: Optional[str] = None
  24. # The value of meta.
  25. content: Optional[str] = None
  26. # The name of metadata.
  27. name: Optional[str] = None
  28. # The type of metadata value.
  29. property: Optional[str] = None
  30. # The type of metadata value.
  31. http_equiv: Optional[str] = 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 = "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 = "og:image"