From c4f5c776e259c9c388594595b7821470fbffd68d Mon Sep 17 00:00:00 2001 From: xenofem Date: Tue, 2 Apr 2024 14:24:42 -0400 Subject: [PATCH] kanatype-insensitive sorting using Unicode Collation Algorithm --- dlibrary/dlibrary.py | 4 +++- flake.nix | 1 + pyproject.toml | 1 + 3 files changed, 5 insertions(+), 1 deletion(-) diff --git a/dlibrary/dlibrary.py b/dlibrary/dlibrary.py index 7bce8b9..67ba0ea 100755 --- a/dlibrary/dlibrary.py +++ b/dlibrary/dlibrary.py @@ -23,6 +23,7 @@ import fitz from libsixel import * from PIL import Image from jinja2 import Environment, PackageLoader, select_autoescape +import pyuca import rarfile import requests @@ -1151,10 +1152,11 @@ def generate(args): print(f'\x1b[2K\r{idx+1}/{len(works)} works processed...', end=('' if idx+1 < len(works) else '\n')) + uca = pyuca.Collator().sort_key def make_categorization(categorization, query, work_filter, work_style_cards=False): categorization_dir = site_dir / categorization - cats = sorted((cat for (cat,) in cur.execute(query)), key=str.casefold) + cats = sorted((cat for (cat,) in cur.execute(query)), key=uca) cat_samples = {} for cat in cats: cat_works = list(filter(work_filter(cat), works)) diff --git a/flake.nix b/flake.nix index 6391e97..c4d3f8d 100644 --- a/flake.nix +++ b/flake.nix @@ -60,6 +60,7 @@ setuptools libsixel (rarfile.override { useUnrar = true; }) + pyuca ]; src = ./.; }; diff --git a/pyproject.toml b/pyproject.toml index 7897dec..99a07c1 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -13,6 +13,7 @@ dependencies = [ "importlib_resources", "libsixel-python", "rarfile", + "pyuca", ] [project.scripts]