Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add Simple-Icons and Selfh.st collections #1118

Merged
merged 2 commits into from
Sep 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions packages/icons/src/icons-fetcher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,22 @@ const repositories = [
new URL("https://api.github.com/repos/walkxcode/dashboard-icons/git/trees/main?recursive=true"),
"https://cdn.jsdelivr.net/gh/walkxcode/dashboard-icons/{0}",
),
new GitHubIconRepository(
"selfh.st",
"selfhst/icons",
"CC0-1.0",
new URL("https://github.com/selfhst/icons"),
new URL("https://api.github.com/repos/selfhst/icons/git/trees/main?recursive=true"),
"https://cdn.jsdelivr.net/gh/selfhst/icons/{0}",
),
new GitHubIconRepository(
"SimpleIcons",
"simple-icons/simple-icons",
"CC0-1.0",
new URL("https://github.com/simple-icons/simple-icons"),
new URL("https://api.github.com/repos/simple-icons/simple-icons/git/trees/master?recursive=true"),
"https://cdn.simpleicons.org/{1}",
),
new JsdelivrIconRepository(
"Papirus",
"PapirusDevelopmentTeam/papirus-icon-theme",
Expand Down
24 changes: 15 additions & 9 deletions packages/icons/src/repositories/github.icon-repository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { parse } from "path";

import { fetchWithTimeout } from "@homarr/common";

import type { IconRepositoryLicense } from "../types/icon-repository-license";
Expand Down Expand Up @@ -27,19 +29,23 @@ export class GitHubIconRepository extends IconRepository {
return {
success: true,
icons: listOfFiles.tree
.filter((treeItem) =>
this.allowedImageFileTypes.some((allowedExtension) => treeItem.path.includes(allowedExtension)),
.filter(({ path }) =>
this.allowedImageFileTypes.some((allowedImageFileType) => parse(path).ext === allowedImageFileType),
)
.map((treeItem) => {
const fileNameWithExtension = this.getFileNameWithoutExtensionFromPath(treeItem.path);
.map(({ path, size: sizeInBytes, sha: checksum }) => {
const file = parse(path);
const fileNameWithExtension = file.base;
const imageUrl = new URL(
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
this.repositoryBlobUrlTemplate!.replace("{0}", path).replace("{1}", file.name),
);

return {
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
imageUrl: new URL(this.repositoryBlobUrlTemplate!.replace("{0}", treeItem.path)),
fileNameWithExtension: fileNameWithExtension,
imageUrl,
fileNameWithExtension,
local: false,
sizeInBytes: treeItem.size,
checksum: treeItem.sha,
sizeInBytes,
checksum,
};
}),
slug: this.slug,
Expand Down
4 changes: 0 additions & 4 deletions packages/icons/src/repositories/icon-repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,4 @@ export abstract class IconRepository {
}

protected abstract getAllIconsInternalAsync(): Promise<RepositoryIconGroup>;

protected getFileNameWithoutExtensionFromPath(path: string) {
return path.replace(/^.*[\\/]/, "");
}
}
19 changes: 11 additions & 8 deletions packages/icons/src/repositories/jsdelivr.icon-repository.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { parse } from "path";

import { fetchWithTimeout } from "@homarr/common";

import type { IconRepositoryLicense } from "../types/icon-repository-license";
Expand All @@ -23,18 +25,19 @@ export class JsdelivrIconRepository extends IconRepository {
return {
success: true,
icons: listOfFiles.files
.filter((file) =>
this.allowedImageFileTypes.some((allowedImageFileType) => file.name.includes(allowedImageFileType)),
.filter(({ name: path }) =>
this.allowedImageFileTypes.some((allowedImageFileType) => parse(path).ext === allowedImageFileType),
)
.map((file) => {
const fileNameWithExtension = this.getFileNameWithoutExtensionFromPath(file.name);
.map(({ name: path, size: sizeInBytes, hash: checksum }) => {
const file = parse(path);
const fileNameWithExtension = file.base;

return {
imageUrl: new URL(this.repositoryBlobUrlTemplate.replace("{0}", file.name)),
fileNameWithExtension: fileNameWithExtension,
imageUrl: new URL(this.repositoryBlobUrlTemplate.replace("{0}", path).replace("{1}", file.name)),
fileNameWithExtension,
local: false,
sizeInBytes: file.size,
checksum: file.hash,
sizeInBytes,
checksum,
};
}),
slug: this.slug,
Expand Down
2 changes: 1 addition & 1 deletion packages/icons/src/types/icon-repository-license.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export type IconRepositoryLicense = "MIT" | "GPL-3.0" | undefined;
export type IconRepositoryLicense = "MIT" | "GPL-3.0" | "CC0-1.0" | undefined;