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[]; new: IChangeType[];
breaking: IChangeType[]; breaking: IChangeType[];
} }
export interface IPostNormalized {
title: String;
version: String;
fixed: String[];
new: String[];
breaking: String[];
}
export interface SettingsChangedMessage { export interface SettingsChangedMessage {
type: 'settingsChanged'; type: 'settingsChanged';
config: IThemeCustomSettings; config: IThemeCustomSettings;

View file

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