Coded parseAuthor

pull/83/head
MillenniumEarl 2021-03-22 12:39:25 +01:00
parent b4b83f36e1
commit a72462becb
1 changed files with 41 additions and 22 deletions

View File

@ -220,34 +220,15 @@ function fillWithPostData(hw: HandiWork, elements: IPostElement[]) {
const releaseDate = getPostElementByName(elements, "release date")?.text; const releaseDate = getPostElementByName(elements, "release date")?.text;
if (DateTime.fromISO(releaseDate).isValid) hw.lastRelease = new Date(releaseDate); if (DateTime.fromISO(releaseDate).isValid) hw.lastRelease = new Date(releaseDate);
//#region Convert the author // Get the author
const authorElement = hw.authors = parseAuthor(elements);
getPostElementByName(elements, "developer") ||
getPostElementByName(elements, "developer/publisher") ||
getPostElementByName(elements, "artist");
const author: TAuthor = {
name: authorElement?.text,
platforms: []
};
// Add the found platforms
authorElement?.content.forEach((el: ILink, idx) => {
const platform: TExternalPlatform = {
name: el.text,
link: el.href
};
author.platforms.push(platform);
});
hw.authors = [author];
//#endregion Convert the author
//#region Get the changelog //#region Get the changelog
hw.changelog = []; hw.changelog = [];
const changelogElement = const changelogElement =
getPostElementByName(elements, "changelog") || getPostElementByName(elements, "change-log"); getPostElementByName(elements, "changelog") || getPostElementByName(elements, "change-log");
if (changelogElement?.content) { if (false && changelogElement?.content) {
const changelogSpoiler = changelogElement.content.find( const changelogSpoiler = changelogElement.content.find(
(el) => el.type === "Spoiler" && el.content.length > 0 (el) => el.type === "Spoiler" && el.content.length > 0
); );
@ -264,4 +245,42 @@ function fillWithPostData(hw: HandiWork, elements: IPostElement[]) {
//#endregion Get the changelog //#endregion Get the changelog
} }
/**
* Parse the author from the post's data.
*/
function parseAuthor(elements: IPostElement[]): TAuthor[] {
// Local variables
const author: TAuthor = {
name: "",
platforms: []
};
// Fetch the authors from the post data
const authorElement =
getPostElementByName(elements, "developer") ||
getPostElementByName(elements, "developer/publisher") ||
getPostElementByName(elements, "artist");
if (authorElement) {
// Set the author name
author.name = authorElement.text;
// Add the found platforms
authorElement.content.forEach((e: ILink) => {
// Ignore invalid links
if (e.href) {
// Create and push the new platform
const platform: TExternalPlatform = {
name: e.text,
link: e.href
};
author.platforms.push(platform);
}
});
}
return [author];
}
//#endregion Private methods //#endregion Private methods