meta.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. """Display the title of the current page."""
  2. from typing import Optional
  3. from pynecone.components.base.bare import Bare
  4. from pynecone.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) -> str:
  9. """Render the title component.
  10. Returns:
  11. The rendered title component.
  12. """
  13. tag = self._render()
  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 str(tag.set(contents=str(self.children[0].contents)))
  19. class Meta(Component):
  20. """A component that displays metadata for the current page."""
  21. tag = "meta"
  22. class Description(Meta):
  23. """A component that displays the title of the current page."""
  24. # The description of the page.
  25. content: Optional[str] = None
  26. # The type of the description.
  27. name: str = "description"
  28. class Image(Meta):
  29. """A component that displays the title of the current page."""
  30. # The image of the page.
  31. content: Optional[str] = None
  32. # The type of the image.
  33. property: str = "og:image"