Html: import("std:html")
Arrays: import("std:collections/array")
socialHead: (article) => {
Html.head(
Html.meta(%{"charset": "utf-8"}),
Html.title(article.title),
Html.meta(%{"name": "description"; "content": article.summary}),
Html.link(%{"rel": "canonical"; "href": article.url}),
Html.meta(%{"property": "og:type"; "content": "article"}),
Html.meta(%{"property": "og:site_name"; "content": article.site}),
Html.meta(%{"property": "og:title"; "content": article.title}),
Html.meta(%{"property": "og:description"; "content": article.summary}),
Html.meta(%{"property": "og:url"; "content": article.url}),
Html.meta(%{"property": "og:image"; "content": article.image.url}),
Html.meta(%{"property": "og:image:alt"; "content": article.image.alt}),
Html.meta(%{"property": "og:image:width"; "content": article.image.width}),
Html.meta(%{"property": "og:image:height"; "content": article.image.height}),
Html.meta(%{"name": "twitter:card"; "content": "summary_large_image"}),
Html.meta(%{"name": "twitter:title"; "content": article.title}),
Html.meta(%{"name": "twitter:description"; "content": article.summary}),
Html.meta(%{"name": "twitter:image"; "content": article.image.url}),
Html.meta(%{"name": "twitter:image:alt"; "content": article.image.alt})
)
}
articlePage: (article) => {
Html.fragment(
Html.doctype(),
Html.html(%{"lang": "en"},
socialHead(article),
Html.body(
Html.h1(article.title),
...Arrays.map(article.paragraphs, (text) => { Html.p(text) }),
Html.ul(...Arrays.map(article.links, (link) => {
Html.li(Html.a(%{"href": link.href}, link.label))
}))
)
)
)
}
article: {
site: "Example Notes"
title: "Objects <without> classes"
summary: "How delegation replaces inheritance & keeps objects small."
url: "https://www.example.com/notes/objects"
image: {
url: "https://www.example.com/notes/objects.png"
alt: "Two objects connected by a delegation arrow"
width: "1200"
height: "630"
}
paragraphs: Array(
"Every object can serve as a prototype.",
"Untrusted text such as <script> stays text."
)
links: Array(
{ href: "/notes"; label: "All notes" },
{ href: "https://www.example.com/about"; label: "About" }
)
}
print(Html.render(articlePage(article)))