meta.py 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. from pynecone.components.tags import Tag
  6. class Title(Component):
  7. """A component that displays the title of the current page."""
  8. tag = "title"
  9. def render(self) -> str:
  10. """Render the title component.
  11. Returns:
  12. The rendered title component.
  13. """
  14. tag = self._render()
  15. # Make sure the title is a single string.
  16. assert len(self.children) == 1 and isinstance(
  17. self.children[0], Bare
  18. ), "Title must be a single string."
  19. return str(tag.set(contents=str(self.children[0].contents)))
  20. class Meta(Component):
  21. """A component that displays metadata for the current page."""
  22. tag = "meta"
  23. class Description(Meta):
  24. """A component that displays the title of the current page."""
  25. # The description of the page.
  26. content: Optional[str] = None
  27. # The type of the description.
  28. name: str = "description"
  29. class Image(Meta):
  30. """A component that displays the title of the current page."""
  31. # The image of the page.
  32. content: Optional[str] = None
  33. # The type of the image.
  34. property: str = "og:image"