-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Implement changelog * Add top margin to first changelog date * Address reviews Improve loading failed message and reload button
- Loading branch information
1 parent
e1e9e77
commit 1fb7bf8
Showing
4 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
// noinspection CssInvalidHtmlTagReference | ||
|
||
const changelogUrl = 'https://moon.spacestation14.com/changelog.xml'; | ||
|
||
export async function fetchChangelog() | ||
{ | ||
const response = await fetch(changelogUrl); | ||
if (!response.ok) | ||
{ | ||
document.getElementById('changelog-reload-button').hidden = false; | ||
return; | ||
} | ||
|
||
const parser = new DOMParser(); | ||
const changelog: XMLDocument = parser.parseFromString(await response.text(), 'text/xml'); | ||
const versions = changelog.querySelectorAll('item'); | ||
|
||
|
||
let outputHtml = ""; | ||
|
||
for (const version of versions) | ||
{ | ||
const date = new Date(Date.parse(version.querySelector('pubDate').innerHTML)); | ||
const entries = Array.from(version.querySelectorAll('entry')) | ||
.map(entry => new ChangelogEntry(entry)); | ||
|
||
const versionHtml = versionTemplate(date, entries) | ||
outputHtml = outputHtml.concat(versionHtml); | ||
} | ||
document.getElementById('changelog-output').innerHTML = outputHtml; | ||
} | ||
|
||
// Funny identity tag function for webstorm syntax highlighting in string templates | ||
const html = (strings: any, ...values: any[]) => String.raw({ raw: strings }, ...values); | ||
|
||
const versionTemplate = (date: Date, changes: ChangelogEntry[]) => html` | ||
<article class="changelog-version"> | ||
<h3 class="version-date">${date.toLocaleDateString('en-EN', {})}</h3> | ||
${changes.map(value => changelogTemplate(value)).join('')} | ||
</article> | ||
`; | ||
|
||
const changelogTemplate = (change: ChangelogEntry) => html` | ||
<h4 class="change-author">${change.author}</h4> | ||
<ul class="version-changes"> | ||
${change.changes.map(entry => `<li class="version-change" data-type="${entry.type}">${entry.text}</li>`).join('')} | ||
</ul>`; | ||
|
||
class ChangelogEntry | ||
{ | ||
private _changes = []; | ||
private readonly _author: string; | ||
|
||
/** | ||
* | ||
* @param entry | ||
*/ | ||
constructor(entry: Element) | ||
{ | ||
this._author = entry.querySelector('author').innerHTML; | ||
const xmlChanges = entry.querySelectorAll('change') | ||
|
||
for (const change of xmlChanges) | ||
{ | ||
this._changes.push({ | ||
type: change.getAttribute('ss14:type'), | ||
text: change.innerHTML | ||
}); | ||
} | ||
} | ||
|
||
get author(): string | ||
{ | ||
return this._author; | ||
} | ||
|
||
get changes(): any[] | ||
{ | ||
return this._changes; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters