From 41e4a9475e355cf742c77daa9702034c59a0bd89 Mon Sep 17 00:00:00 2001 From: DarkWiiPlayer Date: Sat, 26 Mar 2022 14:25:12 +0100 Subject: [PATCH] Add blog post object --- javascript/BlogPost.js | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) create mode 100644 javascript/BlogPost.js diff --git a/javascript/BlogPost.js b/javascript/BlogPost.js new file mode 100644 index 0000000..50c87db --- /dev/null +++ b/javascript/BlogPost.js @@ -0,0 +1,17 @@ +import element from 'https://cdn.jsdelivr.net/gh/darkwiiplayer/js@3724b3e/element.js' +import {html, empty} from 'https://cdn.jsdelivr.net/gh/darkwiiplayer/js@cdaeac1/skooma.js' + +export default element(class BlogPost extends HTMLElement { + static attributes = { name: true } + constructor() { + super() + this.post = posts.find(post => post.head.slug == this.name) + } + async nameChanged() { + this.replace( + html.a({href: `/blog${this.post.head.uri}`}, html.h2(this.post.head.title)), + this.post.head.description ? html.p(this.post.head.description) : undefined, + html.p(html.time$localDate({datetime: this.post.head.date, class: ["timestamp"]})) + ) + } +})