CORE CONCEPTS

Metadata

Rasengan.js has a Metadata API that can be used to define your application metadata (e.g. meta and link tags inside your HTML head element) for improved SEO and web shareability.

Usage

There is two ways to use the Metadata API:

Using static metadata

TypeScript
JavaScript
home.page.tsx
tsximport { Metadata, PageComponent } from "rasengan"; const metadata: Metadata = { // Title of the page title: "Home", // Description of the page description: "Home page", // Defines the meta tags to be added to the head element // (e.g. <meta name="viewport" content="width=device-width, initial-scale=1.0">) metaTags: [{ name: "viewport", content: "width=device-width, initial-scale=1.0" }], // Defines the link tags to be added to the head element // (e.g. <link rel="icon" href="/favicon.ico">) links: [{ rel: "icon", href: "/favicon.ico", }], // Used for link previews on social media openGraph: { title: "Rasengan.js", description: "Rasengan" image: "https://example.com/image.jpg", url: "https://example.com", }, // Used for Twitter link previews twitter: { title: "Rasengan.js", description: "Rasengan.js", image: "https://example.com/image.jpg", card: "summary_large_image", }, } const HomePage: PageComponent = () => { return ( <section> <h1>Home Page</h1> </section> ) } HomePage.path = "/"; HomePage.metadata = metadata; export default HomePage;

Using dynamic metadata

To use dynamic metadata, you have to rely on loader functions.

TypeScript
JavaScript
home.page.tsx
tsximport { Metadata, PageComponent } from "rasengan"; const Home: PageComponent = () => { return ( <section> <h1>Home Page</h1> </section> ) } Home.path = "/"; Home.loader = async () => { // You can fetch data from an API or a database here const metadata: Metadata = { /* Your metaadata here */ } return { meta: metadata, } } export default Home;

The loader function must return an object with a meta property. The meta property must be an object that contains the metadata to be added to the page.

You can decide to mix static and dynamic metadata, but the dynamic metadata has the highest priority.

API

Metadata.title and Metadata.description

PropertyTypeDescriptionOptionalDefault
titlestringThe title of the pagetrueName of the page component
descriptionstringThe description of the pagetrue-

Metadata.metaTags

An array of meta tags to be added to the head element.

PropertyTypeDescriptionOptional
namestringThe name of the meta tag.true
propertystringThe property of the meta tag. Can replace the name property sometimestrue
contentstringThe content of the meta tag.false

An array of link tags to be added to the head element.

PropertyTypeDescriptionDefaultOptional
relstringThe relationship of the link tag."icon"false
hrefstringThe href of the link tag.-false
typestringThe type of the link tag."image/png"true
sizesstringThe sizes of the link tag."32x32"true

Metadata.openGraph

An object containing the Open Graph metadata for link previews on social media.

PropertyTypeDescriptionDefaultOptional
titlestringThe title of the link preview.-false
descriptionstringThe description of the link preview.-false
imagestringThe image of the link preview.-true
urlstringThe URL of the link preview.-true
typestringThe type of the link preview."website"false
widthnumberThe width of the image.-false
heightnumberThe height of the image.-false

Metadata.twitter

An object containing the Twitter metadata for link previews.

PropertyTypeDescriptionDefaultOptional
titlestringThe title of the link preview.-true
descriptionstringThe description of the link preview.-false
imagestringThe image of the link preview.-true
cardstringThe type of the link preview."summary_large_image"true
sitestringThe site of the link preview.-false
creatorstringThe creator of the link preview.-false
Optimizing Images
Static Assets