Metadata & SEO
Control your application's SEO, social sharing cards, and document head tags. Caspian uses a cascading inheritance system similar to Next.js.
SEO Optimized
Dynamic titles and descriptions that merge intelligently from root layouts to specific pages.
Social Cards
Easily define Open Graph and Twitter card tags using the dictionary-based extra fields.
Type Safe
Import the Metadata class from casp.layout for
Pythonic definitions.
Static Definition
For pages with constant titles, define a metadata variable at
the module level in your layout.py or index.py.
from casp.layout import Metadata, render_page # Static definition (compile-time) metadata = Metadata( title="About Us | My App", description="Learn more about our team and mission.", extra={ "og:image": "/assets/og-about.jpg" } ) def page(): return render_page(__file__)
Dynamic Generation
For dynamic routes (e.g., product pages), instantiate the
Metadata class inside your page function.
This overrides static metadata.
from casp.layout import Metadata, render_page def page(slug: str): # Fetch data based on slug... product_name = f"Product {slug.capitalize()}" # Dynamic definition (runtime) Metadata( title=f"{product_name} | Store", description=f"Buy {product_name} at the best price." ) return render_page(__file__, {"name": product_name})
How Inheritance Works
Caspian merges metadata from the Root Layout down to the Page. Lower levels override higher levels.