UnofficialCrusaderPatch / UCP3-GUI

Dev work on the UCP3 gui
GNU Affero General Public License v3.0
2 stars 0 forks source link

[FEATURE]: Implement "News" #263

Closed gynt closed 3 weeks ago

gynt commented 1 month ago

Proposal copied from hackmd:

UCP News

News format

Displayed by category (one sentence) in the Overview tab. There are four sentences displayed, one for each of these four categories:

News is not displayed if the ignore condition is true, which is mainly relevant when the new updated versions are installed (no reason to show the news anymore in the main Overview window).

All news is accessible in the News modal (button in the top toolbar).

News should be removed when it is not relevant anymore.

Specification

YAML Front Matter followed by markdown content.

---
timestamp: 2024-10-01
category: frontend-update
ignore-when: # If any is true, not displayed in GUI
  frontend: ">= 1.0.6"

---
# New GUI version released! v1.0.6
Changelog here

Download [link](https://google.com)

---
timestamp: 2024-10-23
category: framework-update
ignore-when: # If any is true, not displayed in GUI
  framework: ">= 3.0.5"
---
# New framework version released! v3.0.5
More content

---
timestamp: 2024-10-24
category: store-update
---
# Hello world!
More content
---
timestamp: 2024-10-24
category: community-update
---
# The UCP Discord was destroyed by an intruder
Explanation of what happened.

Javascript code to parse it

The actual news.md file lives on our GitHub main repo (UnofficialCrusaderPatch/UnofficialCrusaderPatch). The GUI reads this file on start.

const yaml = require("yaml");
const fs = require("fs");

const news = fs.readFileSync("news.md" , {encoding: 'utf-8'});
const elements = yaml.parseAllDocuments(news, {'keepSourceTokens': true})

const newsElements = [];
elements.forEach((doc, index, docs) => {
    if (index % 2 == 0) {
        newsElements.push({meta: doc.toJS()});
    } else {
        newsElements[Math.floor(index / 2)].content = news.substring(docs[index-1].contents.range[2], doc.contents.range[2]).replaceAll('---', '');
    }
})

note: the GUI is written in TypeScript, but you get the point.

gynt commented 1 month ago

I like the idea to display it until it has been clicked or clicked away with an X, except for if newer version is available in the same domain, then the news about the new (but then already old) version doesn't make sense to display at all.