From f704d417afc887559a824ffcc182f21a742941d6 Mon Sep 17 00:00:00 2001 From: marisa Date: Sun, 21 Jan 2024 14:56:37 -0300 Subject: [PATCH] Initial commit --- README.md | 15 ++++++++++++ emoji_gen.d | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 84 insertions(+) create mode 100644 README.md create mode 100755 emoji_gen.d diff --git a/README.md b/README.md new file mode 100644 index 0000000..ed92005 --- /dev/null +++ b/README.md @@ -0,0 +1,15 @@ +# emoji_gen +Script for generating `pack.json` file for emoji packs in pleroma/akkoma + +## Usage +If you have LLVM's D compiler (`ldc2`) installed, you can run the script directly: +``` +./emoji_gen.d +``` + +Or if you have `dmd`: +``` +rdmd -run emoji_gen.d +``` + +It iterates through all image files inside the directory, not recursively. Check `permittedExtensions` variable for file extensions to include, default value: `jpg jpeg gif png`. At the end, it generates `pack.json` in the same directory as the images. \ No newline at end of file diff --git a/emoji_gen.d b/emoji_gen.d new file mode 100755 index 0000000..609b61b --- /dev/null +++ b/emoji_gen.d @@ -0,0 +1,69 @@ +#!/usr/bin/env -S ldc2 -run + +/** + * @file emoji_gen.d + * @author marisa (marisa@fwmari.net) + * @brief Main program for generating emoji pack metadata + * @version 0.1 + * @date 2023-11-26 + * + * Copyright (c) 2024 Marisa + * + */ + +module emoji_gen; + +import std.stdio; +import std.file; +import std.path; +import std.json; +import std.algorithm.searching; + +enum permittedExtensions = "jpg jpeg gif png"; + +int main(string[] args) { + if (args.length < 2) { + writeln("Usage: ", args[0], " "); + return 1; + } + + string dirPath = args[1]; + assert(exists(dirPath)); + assert(isDir(dirPath)); + + string outFile = buildPath(dirPath, "pack.json"); + + string[string] files; + + foreach (entry; dirEntries(dirPath, SpanMode.shallow)) { + string name = baseName(entry.name); + + if (!entry.isFile) + continue; + + if (!permittedExtensions.canFind(extension(name)[1 .. $])) { + writeln("Not including ", name, " as it isn't a permitted file"); + continue; + } + + writefln("Adding :%s: -> %s", stripExtension(name), name); + files[name.stripExtension] = name; + } + + if (files.length <= 0) { + writeln("No images found, not creating pack"); + return 1; + } + + JSONValue pack; + pack["pack"] = ["can-download": false]; + pack["files"] = files; + pack["files_count"] = files.length; + + writeln("Found ", files.length, " images"); + writeln("Writing pack information to ", outFile); + File(outFile, "w").write(pack.toPrettyString()); + // write(outFile, pack.toPrettyString().ptr); + + return 0; +}