Skip to content

Commit

Permalink
[Brand Icons] Fix incorrect file path (#16059)
Browse files Browse the repository at this point in the history
  • Loading branch information
LitoMore authored Dec 30, 2024
1 parent dbaffb1 commit f70a927
Show file tree
Hide file tree
Showing 6 changed files with 37 additions and 10 deletions.
7 changes: 6 additions & 1 deletion extensions/simple-icons/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
# Brand Icons Changelog

## [Maintenance] - {PR_MERGE_DATE}
## [Enhancements & Fixes] - 2024-10-28

- Fix incorrect file path
- Add support for copying font entities

## [Maintenance] - 2024-10-27

- Get ready for the v14 new data structure
- Add support for copying icon title
Expand Down
9 changes: 9 additions & 0 deletions extensions/simple-icons/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,15 @@
"required": false,
"type": "checkbox",
"default": true
},
{
"name": "displaySimpleIconsFontFeatures",
"title": "Display Simple Icons Font Features",
"label": "Enabled",
"description": "Display Simple Icons Font Features, such as font Copy Character, Copy HTML Code, and Copy UTF Code",
"required": false,
"type": "checkbox",
"default": true
}
],
"dependencies": {
Expand Down
8 changes: 8 additions & 0 deletions extensions/simple-icons/src/actions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ export const CopyUnpkg = ({ icon, version }: ActionProps) => {
return <Action.CopyToClipboard title="Copy unpkg CDN Link" content={unpkgCdnLink} />;
};

export const CopyFontEntities = ({ icon }: ActionProps) => (
<>
<Action.CopyToClipboard title="Copy Character" content={String.fromCodePoint(icon.code)} />
<Action.CopyToClipboard title="Copy HTML Code" content={`&#${icon.code.toString()};`} />
<Action.CopyToClipboard title="Copy UTF Code" content={`\\u{${icon.code.toString(16).toUpperCase()}}`} />
</>
);

export const Supports = () => (
<>
<Action.OpenInBrowser
Expand Down
8 changes: 7 additions & 1 deletion extensions/simple-icons/src/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,11 @@ import {
} from "@raycast/api";
import debounce from "lodash/debounce.js";
import { titleToSlug } from "simple-icons/sdk";
import { LaunchCommand, Supports, actions, defaultActionsOrder } from "./actions.js";
import { CopyFontEntities, LaunchCommand, Supports, actions, defaultActionsOrder } from "./actions.js";
import {
cacheAssetPack,
defaultDetailAction,
displaySimpleIconsFontFeatures,
enableAiSearch,
getAliases,
loadCachedJson,
Expand Down Expand Up @@ -260,6 +261,11 @@ export default function Command({ launchContext }: LaunchProps<{ launchContext?:
</ActionPanel.Section>
</>
)}
{displaySimpleIconsFontFeatures && (
<ActionPanel.Section>
<CopyFontEntities icon={icon} version={version} />
</ActionPanel.Section>
)}
<ActionPanel.Section>
<Supports />
</ActionPanel.Section>
Expand Down
1 change: 1 addition & 0 deletions extensions/simple-icons/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export type Aliases = {
};

export type IconData = {
code: number;
title: string;
hex: string;
source: string;
Expand Down
14 changes: 6 additions & 8 deletions extensions/simple-icons/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,12 @@ import { JsDelivrNpmResponse, IconData, LaunchContext } from "./types.js";

const cache = new Cache();

export const fontUnicodeStart = 0xea01;

export const {
defaultDetailAction = "OpenWith",
defaultLoadSvgAction = "WithBrandColor",
displaySimpleIconsFontFeatures,
enableAiSearch,
} = getPreferenceValues<ExtensionPreferences>();

Expand Down Expand Up @@ -88,16 +91,11 @@ export const cacheAssetPack = async (version: string) => {
export const loadCachedJson = async (version: string) => {
const [major] = version.split(".");
const isNewFormat = Number(major) >= 14;
const jsonPath = join(
environment.assetsPath,
"pack",
`simple-icons-${version}`,
isNewFormat ? "data" : "_data",
"simple-icons.json",
);
const jsonPath = join(environment.assetsPath, "pack", `simple-icons-${version}`, "_data", "simple-icons.json");
const jsonFile = await readFile(jsonPath, "utf8");
const json = JSON.parse(jsonFile);
return isNewFormat ? (json as IconData[]) : (json.icons as IconData[]);
const icons = isNewFormat ? (json as IconData[]) : (json.icons as IconData[]);
return icons.map((icon, i) => ({ ...icon, code: fontUnicodeStart + i }));
};

export const loadCachedVersion = () => {
Expand Down

0 comments on commit f70a927

Please sign in to comment.