You are tasked with grabbing some blog posts from an API and formatting them using markdown, so that your coworker (who has no idea what markdown is) can publish them with ease on your company's website.
You already figured out how to get the posts and the associated users from the API, now you just need to write a function that takes that data and formats it in a markdown string. The rules are as follows:
The title should start with an uppercase character and be displayed as an H1.
Add 2 newlines after the title.
The metadata of the post has the following format:
Written by <author> on <date>
<author> part is a link where the text is the author's firstName and lastName (separated by a space), while the href is a mailto:<author email>.<date> part is the date of the post and the format is the following:
<weekday>, <month> <date>, <year>
Thu, Sun, …)April, December, …)01 - 31)2018)Add 2 newlines after the metadata.
The separator is an horizontal line, in markdown it's written like this: ---.
Add 2 newlines after the separator.
The body of the post is already properly formatted and is the last thing you must add.
| Property | Type | Description |
|---|---|---|
id | number | id of the post |
userId | number | id of the user that authored the post |
timestamp | number | timestamp of the post (in milliseconds) |
title | string | title of the post |
body | string | body (content) of the post |
| Property | Type | Description |
|---|---|---|
id | number | id of the user |
firstName | string | first name of the user |
lastName | string | last name of the user |
email | string | email of the user |
Input:
formatBlogPost(
{
id: 1,
userId: 10,
timestamp: 1536581919628,
title: 'varius ut blandit non interdum in ante',
body:
'Nullam sit amet turpis elementum ligula vehicula consequat. Morbi a ipsum. Integer a nibh.\n\nIn quis justo. Maecenas rhoncus aliquam lacus. Morbi quis tortor id nulla ultrices aliquet.',
},
users, // Array of objects, see structure above
);
Output (as a string):
# Varius ut blandit non interdum in ante
Written by [Sigismond Reavell](mailto:[email protected]) on Mon, September 10, 2018
---
Nullam sit amet turpis elementum ligula vehicula consequat. Morbi a ipsum. Integer a nibh.
In quis justo. Maecenas rhoncus aliquam lacus. Morbi quis tortor id nulla ultrices aliquet.