Skip to content

Commit

Permalink
chore: code
Browse files Browse the repository at this point in the history
  • Loading branch information
CCherry07 committed Jul 19, 2024
1 parent e4dc7f3 commit 5d3c17a
Show file tree
Hide file tree
Showing 8 changed files with 76 additions and 789 deletions.
765 changes: 14 additions & 751 deletions Cargo.lock

Large diffs are not rendered by default.

9 changes: 2 additions & 7 deletions packages/icons/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,7 @@ farmfe_utils = "0.1.4"
svgr-rs = "0.1.2"
once_cell = "1.19.0"
fervid = "0.2.0"
reqwest = "0.12.5"
tokio = { version = "1.38.0", features = ["full"] }
# reqwest = "0.12.5"
# tokio = { version = "1.38.0", features = ["full"] }
walkdir = "2.5.0"
xmltree = "0.10.3"
openssl-sys = "0.9.102"
# openssl = "0.10.64"
# pkg-config = "0.3.30"
# openssl-probe = "0.1.5"
# rand = "0.8"
4 changes: 2 additions & 2 deletions packages/icons/playground-react/src/main.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import React, { useState } from "react";
import "./main.css";
import FarmLogo from "./assets/logo.png";
import VueLogoIconifyRaw from '~icons/logos/vue?raw'
import RemoteComponent from "~icons/remote/react";
// import RemoteComponent from "~icons/remote/react";
import ReactLogoIconify from '~icons/logos/react?width=2em&height=2em'
import ReactLogoComponent from "./assets/react.svg?component";
import LocalReactLogo from "~icons/local/react";
Expand All @@ -24,7 +24,7 @@ export function Main() {
<ReactLogoIconify className=" text-100px text-#00D8FF" />
<ReactLogoComponent className="text-100px h-1em w-1em" />
<LocalReactLogo className="text-100px h-1em w-1em" />
<RemoteComponent className="text-100px h-1em w-1em" />
{/* <RemoteComponent className="text-100px h-1em w-1em" /> */}
<div dangerouslySetInnerHTML={
{
__html: VueLogoIconifyRaw
Expand Down
59 changes: 30 additions & 29 deletions packages/icons/src/loader/common.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
use farmfe_core::regex::{self, Regex};
use farmfe_toolkit::fs::read_file_utf8;
use reqwest::Client;
// use reqwest::Client;
use serde_json::Value;
use std::{
fs::File,
io::BufReader,
path::{Path, PathBuf},
process::Command,
};
use tokio::runtime::Runtime;
// use tokio::runtime::Runtime;
use walkdir::WalkDir;

pub const URL_PREFIXES: [&str; 4] = ["/~icons/", "~icons/", "virtual:icons/", "virtual/icons/"];
Expand Down Expand Up @@ -101,18 +101,19 @@ pub struct GetIconPathDataParams {
pub fn get_svg_by_custom_collections(opt: GetSvgByCustomCollectionsParams) -> String {
let GetSvgByCustomCollectionsParams {
custom_collection_path,
icon,
icon: _icon,
project_dir,
} = opt;
if is_valid_icon_path(&custom_collection_path) {
let mut svg_raw = String::new();
let custom_collection_path = custom_collection_path.replace("[iconname]", &icon);
let rt = Runtime::new().unwrap();
rt.block_on(async {
if let Ok(res) = get_svg_by_url(&custom_collection_path).await {
svg_raw = res;
}
});
let svg_raw = String::new();
// let custom_collection_path = custom_collection_path.replace("[iconname]", &icon);
// let rt = Runtime::new().unwrap();
// rt.block_on(async {
// if let Ok(res) = get_svg_by_url(&custom_collection_path).await {
// svg_raw = res;
// }
// });
println!("the remote path that does not support custom sets currently does");
return svg_raw;
}
let icons_collection_path = Path::new(&project_dir).join(custom_collection_path);
Expand All @@ -139,24 +140,24 @@ pub fn get_svg_by_local_path(path: &str) -> String {
let svg_raw = read_file_utf8(path).unwrap();
svg_raw
}
async fn get_svg_by_url(url: &str) -> Result<String, reqwest::Error> {
let client = Client::new();
let res = client.get(url).send().await;
match res {
Ok(response) => {
if response.status().is_success() {
let text = response.text().await?;
Ok(text)
} else {
println!("{} icon fetch err: {:?}", url, response.status());
Ok(String::new())
}
}
Err(e) => {
panic!("icon fetch err: {:?}", e);
}
}
}
// async fn get_svg_by_url(url: &str) -> Result<String, reqwest::Error> {
// let client = Client::new();
// let res = client.get(url).send().await;
// match res {
// Ok(response) => {
// if response.status().is_success() {
// let text = response.text().await?;
// Ok(text)
// } else {
// println!("{} icon fetch err: {:?}", url, response.status());
// Ok(String::new())
// }
// }
// Err(e) => {
// panic!("icon fetch err: {:?}", e);
// }
// }
// }
pub fn get_icon_data_by_iconify(opt: GetIconPathDataParams) -> Value {
let ResolveResult { collection, icon } = resolve_icons_path(&opt.path);
let all_icon_path = build_icon_path(&opt.project_dir, "@iconify/json/json");
Expand Down
8 changes: 8 additions & 0 deletions packages/icons/types/react.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,11 @@ declare module '~icons/*' {
const component: (props: SVGProps<SVGSVGElement>) => React.ReactElement
export default component
}

declare module '*.svg?component' {
import type { SVGProps } from 'react'
import type React from 'react'

const component: (props: SVGProps<SVGSVGElement>) => React.ReactElement
export default component
}
6 changes: 6 additions & 0 deletions packages/icons/types/solid.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ declare module '~icons/*' {
const component: (props: ComponentProps<'svg'>) => JSX.Element
export default component
}
declare module '*.svg?component' {
import type { ComponentProps, JSX } from 'solid-js'

const component: (props: ComponentProps<'svg'>) => JSX.Element
export default component
}
8 changes: 8 additions & 0 deletions packages/icons/types/svelte4.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,11 @@ declare module '~icons/*' {

export default class extends SvelteComponent<SvelteHTMLElements['svg']> {}
}


declare module '*.svg?component' {
import { SvelteComponent } from 'svelte'
import type { SvelteHTMLElements } from 'svelte/elements'

export default class extends SvelteComponent<SvelteHTMLElements['svg']> {}
}
6 changes: 6 additions & 0 deletions packages/icons/types/vue3.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ declare module '~icons/*' {
const component: FunctionalComponent<SVGAttributes>
export default component
}
declare module '*.svg?component' {
import type { FunctionalComponent, SVGAttributes } from 'vue'

const component: FunctionalComponent<SVGAttributes>
export default component
}

0 comments on commit 5d3c17a

Please sign in to comment.