Fixed order and empty list (#299)

This commit is contained in:
Alessio Occhipinti 2018-12-23 18:14:33 +01:00 committed by Mattia Astorino
parent 3b3abd2a33
commit c4b94d618d
2 changed files with 16 additions and 7 deletions

View file

@ -13,7 +13,13 @@ export interface IPost {
new: IChangeType[];
breaking: IChangeType[];
}
export interface IPostNormalized {
title: String;
version: String;
fixed: String[];
new: String[];
breaking: String[];
}
export interface SettingsChangedMessage {
type: 'settingsChanged';
config: IThemeCustomSettings;

View file

@ -1,6 +1,6 @@
import * as sanityClient from '@sanity/client';
import {IPost} from '../../interfaces';
import {IPost, IPostNormalized} from '../../interfaces';
const getClient = () => sanityClient({
projectId: 'v475t82f',
@ -8,21 +8,24 @@ const getClient = () => sanityClient({
});
const getReleaseNotes = (): Promise<object[]> => {
const query = '*[_type == "release"] | order(_createdAt desc)';
const query = '*[_type == "release"] | order(version desc)';
const client = getClient();
return client.fetch(query);
};
const renderTemplate = (posts: IPost[]) => {
const renderTemplate = (posts: IPostNormalized[]) => {
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">
${fixed.reduce((accc: string, src) => accc.concat(`<li data-type="fixed">${src}</li>`), '')}
${newItems.reduce((accc: string, src) => accc.concat(`<li data-type="new">${src}</li>`), '')}
${breaking.reduce((accc: string, src) => accc.concat(`<li data-type="breaking">${src}</li>`), '')}
${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>`) : '', '')}
</ul>
</section>`), '')}`;
};