diff --git a/OliverBooth.sln b/OliverBooth.sln index 5e51d9a..5e724d8 100644 --- a/OliverBooth.sln +++ b/OliverBooth.sln @@ -1,4 +1,4 @@ - + Microsoft Visual Studio Solution File, Format Version 12.00 Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OliverBooth", "OliverBooth\OliverBooth.csproj", "{A58A6FA3-480C-400B-822A-3786741BF39C}" EndProject @@ -32,6 +32,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "ts", "ts", "{BB9F76AC-292A- src\ts\TimeUtility.ts = src\ts\TimeUtility.ts src\ts\UI.ts = src\ts\UI.ts src\ts\Input.ts = src\ts\Input.ts + src\ts\BlogUrl.ts = src\ts\BlogUrl.ts EndProjectSection EndProject Global diff --git a/src/ts/BlogPost.ts b/src/ts/BlogPost.ts index c1d1f25..4c4dac5 100644 --- a/src/ts/BlogPost.ts +++ b/src/ts/BlogPost.ts @@ -1,3 +1,5 @@ +import BlogUrl from "./BlogUrl"; + class BlogPost { private readonly _id: string; private readonly _commentsEnabled: boolean; @@ -7,7 +9,7 @@ class BlogPost { private readonly _authorId: string; private readonly _published: Date; private readonly _updated?: Date; - private readonly _url: string; + private readonly _url: BlogUrl; private readonly _trimmed: boolean; private readonly _identifier: string; private readonly _humanizedTimestamp: string; @@ -22,7 +24,7 @@ class BlogPost { this._authorId = json.author; this._published = new Date(json.published * 1000); this._updated = (json.updated && new Date(json.updated * 1000)) || null; - this._url = json.url; + this._url = new BlogUrl(json.url); this._trimmed = json.trimmed; this._identifier = json.identifier; this._humanizedTimestamp = json.humanizedTimestamp; @@ -61,7 +63,7 @@ class BlogPost { return this._updated; } - get url(): string { + get url(): BlogUrl { return this._url; } diff --git a/src/ts/BlogUrl.ts b/src/ts/BlogUrl.ts new file mode 100644 index 0000000..351ad3c --- /dev/null +++ b/src/ts/BlogUrl.ts @@ -0,0 +1,32 @@ +class BlogUrl { + private readonly _year: string; + private readonly _month: string; + private readonly _day: string; + private readonly _slug: string; + + constructor(json: any) { + this._year = json.year; + this._month = json.month; + this._day = json.day; + this._slug = json.slug; + } + + + get year(): string { + return this._year; + } + + get month(): string { + return this._month; + } + + get day(): string { + return this._day; + } + + get slug(): string { + return this._slug; + } +} + +export default BlogUrl; \ No newline at end of file diff --git a/src/ts/UI.ts b/src/ts/UI.ts index 7744d27..0b431a0 100644 --- a/src/ts/UI.ts +++ b/src/ts/UI.ts @@ -48,7 +48,7 @@ class UI { post: { title: post.title, excerpt: post.excerpt, - url: post.url, + url: `${post.url.year}/${post.url.month}/${post.url.day}/${post.url.slug}`, date: TimeUtility.formatRelativeTimestamp(post.published), formattedDate: post.formattedDate, date_humanized: `${post.updated ? "Updated" : "Published"} ${post.humanizedTimestamp}`,