feat!: Use YAML instead of JSON

site-config.json is now site-config.yml.
That was the only usage of JSON, so not much changes.

Dep removed: org.json:json
Added: org.snakeyaml:snakeyaml-engine

Signed-off-by: Minecon724 <git@m724.eu>
This commit is contained in:
Minecon724 2025-02-12 16:17:43 +01:00
parent 721d8d2768
commit d155079514
Signed by: Minecon724
GPG key ID: 3CCC4D267742C8E8
3 changed files with 10 additions and 9 deletions

View file

@ -36,9 +36,9 @@
<version>3.2.3</version>
</dependency>
<dependency>
<groupId>org.json</groupId>
<artifactId>json</artifactId>
<version>20250107</version>
<groupId>org.snakeyaml</groupId>
<artifactId>snakeyaml-engine</artifactId>
<version>2.9</version>
</dependency>
<dependency>
<groupId>commons-io</groupId>

View file

@ -116,7 +116,7 @@ public class BlogBuilder {
*/
public void build() throws IOException {
if (site == null)
this.site = Site.fromConfig(workingDirectory.resolve("site-config.json"));
this.site = Site.fromConfig(workingDirectory.resolve("site-config.yml"));
if (template == null)
this.template = new TemplateRenderer(templateDirectory);

View file

@ -1,6 +1,7 @@
package eu.m724.blog.data;
import org.json.JSONObject;
import org.snakeyaml.engine.v2.api.Load;
import org.snakeyaml.engine.v2.api.LoadSettings;
import java.io.IOException;
import java.nio.file.Files;
@ -30,15 +31,15 @@ public record Site(
* @throws IOException if an error occurs during file reading
*/
public static Site fromConfig(Path path) throws IOException {
var content = Files.readString(path);
var json = new JSONObject(content);
var load = new Load(LoadSettings.builder().build());
var yaml = (Map<String, Object>) load.loadFromInputStream(Files.newInputStream(path));
String name = null;
String baseUrl = null;
var custom = new HashMap<String, Object>();
for (var key : json.keySet()) {
var value = json.get(key);
for (var key : yaml.keySet()) {
var value = yaml.get(key);
switch (key) {
case "name":