2018-12-23 17:35:38 +01:00
|
|
|
import * as sanityClient from '@sanity/client';
|
|
|
|
|
2018-12-23 18:14:33 +01:00
|
|
|
import {IPost, IPostNormalized} from '../../interfaces';
|
2018-10-24 16:28:05 +02:00
|
|
|
|
2018-12-23 17:35:38 +01:00
|
|
|
const getClient = () => sanityClient({
|
|
|
|
projectId: 'v475t82f',
|
|
|
|
dataset: 'production'
|
|
|
|
});
|
|
|
|
|
2018-10-24 16:28:05 +02:00
|
|
|
const getReleaseNotes = (): Promise<object[]> => {
|
2018-12-23 18:14:33 +01:00
|
|
|
const query = '*[_type == "release"] | order(version desc)';
|
2018-12-23 17:35:38 +01:00
|
|
|
const client = getClient();
|
|
|
|
return client.fetch(query);
|
2018-10-24 16:28:05 +02:00
|
|
|
};
|
|
|
|
|
2018-12-23 18:14:33 +01:00
|
|
|
const renderTemplate = (posts: IPostNormalized[]) => {
|
2018-10-24 16:28:05 +02:00
|
|
|
return `${posts.reduce((acc, {version, title, fixed, new: newItems, breaking}) => acc.concat(`<section class="Release">
|
|
|
|
<header class="Release__Header">
|
|
|
|
<span class="Release__Number">${version}</span>
|
|
|
|
<h2 class="Release__Title">${title}</h2>
|
|
|
|
</header>
|
|
|
|
<ul class="Release-List">
|
2018-12-23 18:14:33 +01:00
|
|
|
${fixed.reduce((accc: string, src) =>
|
|
|
|
src.length > 0 ? accc.concat(`<li data-type="fixed">${src}</li>`) : '', '')}
|
|
|
|
${newItems.reduce((accc: string, src) =>
|
|
|
|
src.length > 0 ? accc.concat(`<li data-type="new">${src}</li>`) : '', '')}
|
|
|
|
${breaking.reduce((accc: string, src) =>
|
|
|
|
src.length > 0 ? accc.concat(`<li data-type="breaking">${src}</li>`) : '', '')}
|
2018-10-24 16:28:05 +02:00
|
|
|
</ul>
|
|
|
|
</section>`), '')}`;
|
|
|
|
};
|
|
|
|
|
|
|
|
getReleaseNotes().then((res: IPost[]) => {
|
2018-12-23 17:35:38 +01:00
|
|
|
const normalized = res.reduce((acc, src) => acc.concat({
|
|
|
|
...src,
|
|
|
|
fixed: src.fixed ? src.fixed.map(item => item.children[0].text) : [],
|
|
|
|
new: src.new ? src.new.map(item => item.children[0].text) : [],
|
|
|
|
breaking: src.breaking ? src.breaking.map(item => item.children[0].text) : []
|
|
|
|
}), []);
|
|
|
|
document.querySelector('.Container').innerHTML = renderTemplate(normalized);
|
2018-10-24 16:28:05 +02:00
|
|
|
});
|