- Introduced a new TypeScript file `icons.ts` containing a list of unyoHub icons with their respective IDs, names, and image paths. - Added a new utility `jrDataSystemIconUrl.ts` to handle icon URL management for the JR data system, including a function to append icon queries. - Created a bash script `convert-unyohub-icons.sh` to convert WebP icons to PNG format, resizing them to 1024x1024 pixels and saving them in the specified output directory.
44 lines
1.4 KiB
TypeScript
44 lines
1.4 KiB
TypeScript
import { isHubIconDisplayMode } from "./iconDisplayMode";
|
|
import { JR_DATA_SYSTEM_ENVS } from "./jrDataSystemEnvironment";
|
|
|
|
const JR_DATA_SYSTEM_BASE_URLS = [
|
|
"https://jr-shikoku-data-system.pages.dev",
|
|
...Object.values(JR_DATA_SYSTEM_ENVS).map(({ baseUrl }) => baseUrl),
|
|
];
|
|
|
|
const isJrDataSystemUrl = (uri: string): boolean =>
|
|
JR_DATA_SYSTEM_BASE_URLS.some(
|
|
(baseUrl) =>
|
|
uri === baseUrl ||
|
|
uri.startsWith(`${baseUrl}/`) ||
|
|
uri.startsWith(`${baseUrl}?`),
|
|
);
|
|
|
|
/** Hubアイコン表示モード時だけ、運用システムへアイコン指定を引き継ぐ。 */
|
|
export const withJrDataSystemIconQuery = (
|
|
uri: string,
|
|
iconDisplayMode: unknown,
|
|
): string => {
|
|
if (
|
|
typeof uri !== "string" ||
|
|
uri.length === 0 ||
|
|
!isHubIconDisplayMode(iconDisplayMode) ||
|
|
!isJrDataSystemUrl(uri)
|
|
) {
|
|
return uri;
|
|
}
|
|
|
|
const hashIndex = uri.indexOf("#");
|
|
const hash = hashIndex >= 0 ? uri.slice(hashIndex) : "";
|
|
const uriWithoutHash = hashIndex >= 0 ? uri.slice(0, hashIndex) : uri;
|
|
const queryIndex = uriWithoutHash.indexOf("?");
|
|
const baseUrl = queryIndex >= 0 ? uriWithoutHash.slice(0, queryIndex) : uriWithoutHash;
|
|
const query = queryIndex >= 0 ? uriWithoutHash.slice(queryIndex + 1) : "";
|
|
const queryParams = query
|
|
.split("&")
|
|
.filter(Boolean)
|
|
.filter((param) => param.split("=", 1)[0].toLowerCase() !== "icon");
|
|
|
|
return `${baseUrl}?${[...queryParams, "icon=unyohub"].join("&")}${hash}`;
|
|
};
|