summaryrefslogtreecommitdiff
path: root/src/utils
diff options
context:
space:
mode:
author2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-01 17:27:18 +1100
committer2 * r + 2 * t <61896496+soramanew@users.noreply.github.com>2025-04-01 17:27:18 +1100
commitff7324e7bfc1e01c8502e24a38e0729d87e63564 (patch)
tree3af12a838f191dad413c6ff7096dd83d9ee8daa5 /src/utils
parentlauncher: hide todo action if tod not installed (diff)
downloadcaelestia-shell-ff7324e7bfc1e01c8502e24a38e0729d87e63564.tar.gz
caelestia-shell-ff7324e7bfc1e01c8502e24a38e0729d87e63564.tar.bz2
caelestia-shell-ff7324e7bfc1e01c8502e24a38e0729d87e63564.zip
calendar: cache calendars
Diffstat (limited to 'src/utils')
-rw-r--r--src/utils/strings.ts10
-rw-r--r--src/utils/thumbnailer.ts5
2 files changed, 10 insertions, 5 deletions
diff --git a/src/utils/strings.ts b/src/utils/strings.ts
index c2bf71a..4aaa916 100644
--- a/src/utils/strings.ts
+++ b/src/utils/strings.ts
@@ -1,7 +1,13 @@
export const ellipsize = (str: string, len: number) => (str.length > len ? `${str.slice(0, len - 1)}…` : str);
-export const basename = (path: string) => {
+export const basename = (path: string, stripExt = true) => {
const lastSlash = path.lastIndexOf("/");
const lastDot = path.lastIndexOf(".");
- return path.slice(lastSlash + 1, lastDot > lastSlash ? lastDot : undefined);
+ return path.slice(lastSlash + 1, stripExt && lastDot > lastSlash ? lastDot : undefined);
+};
+
+export const pathToFileName = (path: string, ext?: string) => {
+ const start = /[a-z]+:\/\//.test(path) ? 0 : path.indexOf("/") + 1;
+ const dir = path.slice(start, path.lastIndexOf("/")).replaceAll("/", "-");
+ return `${dir}-${basename(path, ext !== undefined)}${ext ? `.${ext}` : ""}`;
};
diff --git a/src/utils/thumbnailer.ts b/src/utils/thumbnailer.ts
index 7551870..caa3bbb 100644
--- a/src/utils/thumbnailer.ts
+++ b/src/utils/thumbnailer.ts
@@ -1,5 +1,5 @@
import { execAsync, Gio, GLib } from "astal";
-import { basename } from "./strings";
+import { pathToFileName } from "./strings";
export default class Thumbnailer {
static readonly thumbnailDir = `${CACHE}/thumbnails`;
@@ -13,8 +13,7 @@ export default class Thumbnailer {
static readonly #running = new Set<string>();
static getThumbPath(path: string) {
- const dir = path.slice(path.indexOf("/") + 1, path.lastIndexOf("/")).replaceAll("/", "-");
- return `${this.thumbnailDir}/${dir}-${basename(path)}.png`;
+ return `${this.thumbnailDir}/${pathToFileName(path, "png")}`;
}
static async shouldThumbnail(path: string) {