Examples¶
Short, self-contained programs. Each one builds a payload and prints the generated HTML.
Python¶
from easeo import SEOConfig, SEOEntity, build_seo_payload
config = SEOConfig(
canonical_host="example.com",
public_base_url="https://example.com",
)
entity = SEOEntity(
entity_type="post",
title="Hello World",
excerpt="An example post.",
)
payload = build_seo_payload(entity, "/blog/hello", config)
print(payload.render_html())
JavaScript¶
const { buildSeoPayload } = require("@easeo/core");
const payload = buildSeoPayload(
{ entityType: "post", title: "Hello World", description: "An example post." },
"/blog/hello",
{ canonicalHost: "example.com", publicBaseUrl: "https://example.com" }
);
console.log(payload.renderHtml());
Rust¶
use easeo_core::{SEOConfig, SEOEntity, EntityType, build_seo_payload};
let config = SEOConfig {
canonical_host: "example.com".into(),
public_base_url: "https://example.com".into(),
..Default::default()
};
let entity = SEOEntity {
entity_type: EntityType::Post,
title: Some("Hello World".into()),
excerpt: Some("An example post.".into()),
..Default::default()
};
let payload = build_seo_payload(&entity, "/blog/hello", &config)?;
println!("{}", payload.render_html()?);
Runnable files¶
The repository ships runnable copies under examples/:
Determinism demo¶
from easeo import SEOConfig, SEOEntity, build_seo_payload
config = SEOConfig(canonical_host="example.com", public_base_url="https://example.com")
entity = SEOEntity(entity_type="page", title="Stable")
a = build_seo_payload(entity, "/x", config)
b = build_seo_payload(entity, "/x", config)
assert a == b
assert a.hash() == b.hash()
print("stable:", a.etag())