mirror of
https://github.com/sharevb/it-tools.git
synced 2026-11-20 21:23:08 +03:00
1 parent
087860c472
commit
2c2643b14c
2 files changed
+38
-37
No files matched your search
+37
-2
@@ -1,8 +1,43 @@
|
||||
import type { ToolCategory, ToolWithCategory } from './tools.types';
|
||||
import type { ToolCategory, ToolWithCategory, ToolsFilter } from './tools.types';
|
||||
|
||||
const modules = import.meta.glob<true, string, ToolWithCategory>('./*/index.ts', { eager: true, import: 'tool' });
|
||||
|
||||
export const toolsByCategory = Object.values(modules).reduce((la, moduleDef) => {
|
||||
const base = import.meta.env.BASE_URL ?? '/';
|
||||
let filterConfig: ToolsFilter = {};
|
||||
try {
|
||||
const remoteConfigResponse = await fetch(`${base}tools-filter.json`);
|
||||
if (remoteConfigResponse.ok) {
|
||||
filterConfig = (await remoteConfigResponse.json()) as ToolsFilter;
|
||||
}
|
||||
}
|
||||
catch {}
|
||||
|
||||
const makeRegExp = (regex: string | undefined) => regex ? new RegExp(regex, 'i') : null;
|
||||
const filters = {
|
||||
excludeCategoryFilterRegex: makeRegExp(filterConfig.excludeCategoryFilterRegex),
|
||||
includeCategoryFilterRegex: makeRegExp(filterConfig.includeCategoryFilterRegex),
|
||||
excludeToolsFilterRegex: makeRegExp(filterConfig.excludeToolsFilterRegex),
|
||||
includeToolsFilterRegex: makeRegExp(filterConfig.includeToolsFilterRegex),
|
||||
};
|
||||
|
||||
const filteredModules = Object.values(modules).filter((tool) => {
|
||||
const category = tool.category || 'Development';
|
||||
if (filters.includeToolsFilterRegex?.test(tool.path)) {
|
||||
return true;
|
||||
}
|
||||
if (filters.includeCategoryFilterRegex?.test(category)) {
|
||||
return true;
|
||||
}
|
||||
if (filters.excludeToolsFilterRegex?.test(tool.path)) {
|
||||
return false;
|
||||
}
|
||||
if (filters.excludeCategoryFilterRegex?.test(category)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
});
|
||||
|
||||
export const toolsByCategory = filteredModules.reduce((la, moduleDef) => {
|
||||
let found = la.find(l => l.name === moduleDef.category);
|
||||
if (!found) {
|
||||
found = {
|
||||
|
||||
@@ -2,49 +2,15 @@ import { type MaybeRef, get } from '@vueuse/core';
|
||||
import { defineStore } from 'pinia';
|
||||
import type { Ref } from 'vue';
|
||||
import _ from 'lodash';
|
||||
import type { Tool, ToolCategory, ToolWithCategory, ToolsFilter } from './tools.types';
|
||||
import type { Tool, ToolCategory, ToolWithCategory } from './tools.types';
|
||||
import { tools as allTools } from './index';
|
||||
import { useITStorage } from '@/composable/queryParams';
|
||||
|
||||
const base = import.meta.env.BASE_URL ?? '/';
|
||||
let filterConfig: ToolsFilter = {};
|
||||
try {
|
||||
const remoteConfigResponse = await fetch(`${base}tools-filter.json`);
|
||||
if (remoteConfigResponse.ok) {
|
||||
filterConfig = (await remoteConfigResponse.json()) as ToolsFilter;
|
||||
}
|
||||
}
|
||||
catch {}
|
||||
|
||||
export const useToolStore = defineStore('tools', () => {
|
||||
const favoriteToolsName = useITStorage('favoriteToolsName', []) as Ref<string[]>;
|
||||
const { t } = useI18n();
|
||||
|
||||
const makeRegExp = (regex: string | undefined) => regex ? new RegExp(regex, 'i') : null;
|
||||
const filters = {
|
||||
excludeCategoryFilterRegex: makeRegExp(filterConfig.excludeCategoryFilterRegex),
|
||||
includeCategoryFilterRegex: makeRegExp(filterConfig.includeCategoryFilterRegex),
|
||||
excludeToolsFilterRegex: makeRegExp(filterConfig.excludeToolsFilterRegex),
|
||||
includeToolsFilterRegex: makeRegExp(filterConfig.includeToolsFilterRegex),
|
||||
};
|
||||
|
||||
const tools = computed<ToolWithCategory[]>(() => allTools
|
||||
.filter((tool) => {
|
||||
const category = tool.category || 'Development';
|
||||
if (filters.includeToolsFilterRegex?.test(tool.path)) {
|
||||
return true;
|
||||
}
|
||||
if (filters.includeCategoryFilterRegex?.test(category)) {
|
||||
return true;
|
||||
}
|
||||
if (filters.excludeToolsFilterRegex?.test(tool.path)) {
|
||||
return false;
|
||||
}
|
||||
if (filters.excludeCategoryFilterRegex?.test(category)) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
})
|
||||
.map((tool) => {
|
||||
const toolI18nKey = tool.path.replace(/\//g, '');
|
||||
const category = tool.category || 'Development';
|
||||
|
||||
Reference in new issue
Block a user