Initial commit

This commit is contained in:
2024-01-21 14:56:37 -03:00
commit f704d417af
2 changed files with 84 additions and 0 deletions

15
README.md Normal file
View File

@@ -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 <images directory>
```
Or if you have `dmd`:
```
rdmd -run emoji_gen.d <images directory>
```
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.

69
emoji_gen.d Executable file
View File

@@ -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], " <directory>");
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;
}