@@ -2,25 +2,60 @@ import { type MaybeRef, get, useStorage } from '@vueuse/core';
22import { defineStore } from 'pinia' ;
33import type { Ref } from 'vue' ;
44import _ from 'lodash' ;
5- import type { Tool , ToolCategory , ToolWithCategory } from './tools.types' ;
5+ import type { Tool , ToolCategory , ToolWithCategory , ToolsFilter } from './tools.types' ;
66import { tools as allTools } from './index' ;
77
8+ const base = import . meta. env . BASE_URL ?? '/' ;
9+ let filterConfig : ToolsFilter = { } ;
10+ try {
11+ const remoteConfigResponse = await fetch ( `${ base } tools-filter.json` ) ;
12+ if ( remoteConfigResponse . ok ) {
13+ filterConfig = ( await remoteConfigResponse . json ( ) ) as ToolsFilter ;
14+ }
15+ }
16+ catch { }
17+
818export const useToolStore = defineStore ( 'tools' , ( ) => {
919 const favoriteToolsName = useStorage ( 'favoriteToolsName' , [ ] ) as Ref < string [ ] > ;
1020 const { t } = useI18n ( ) ;
1121
12- const tools = computed < ToolWithCategory [ ] > ( ( ) => allTools . map ( ( tool ) => {
13- const toolI18nKey = tool . path . replace ( / \/ / g, '' ) ;
14- const category = tool . category || 'Development' ;
22+ const makeRegExp = ( regex : string | undefined ) => regex ? new RegExp ( regex , 'i' ) : null ;
23+ const filters = {
24+ excludeCategoryFilterRegex : makeRegExp ( filterConfig . excludeCategoryFilterRegex ) ,
25+ includeCategoryFilterRegex : makeRegExp ( filterConfig . includeCategoryFilterRegex ) ,
26+ excludeToolsFilterRegex : makeRegExp ( filterConfig . excludeToolsFilterRegex ) ,
27+ includeToolsFilterRegex : makeRegExp ( filterConfig . includeToolsFilterRegex ) ,
28+ } ;
29+
30+ const tools = computed < ToolWithCategory [ ] > ( ( ) => allTools
31+ . filter ( ( tool ) => {
32+ const category = tool . category || 'Development' ;
33+ if ( filters . includeToolsFilterRegex ?. test ( tool . path ) ) {
34+ return true ;
35+ }
36+ if ( filters . includeCategoryFilterRegex ?. test ( category ) ) {
37+ return true ;
38+ }
39+ if ( filters . excludeToolsFilterRegex ?. test ( tool . path ) ) {
40+ return false ;
41+ }
42+ if ( filters . excludeCategoryFilterRegex ?. test ( category ) ) {
43+ return false ;
44+ }
45+ return true ;
46+ } )
47+ . map ( ( tool ) => {
48+ const toolI18nKey = tool . path . replace ( / \/ / g, '' ) ;
49+ const category = tool . category || 'Development' ;
1550
16- return ( {
17- ...tool ,
18- path : tool . path ,
19- name : t ( `tools.${ toolI18nKey } .title` , tool . name ) ,
20- description : t ( `tools.${ toolI18nKey } .description` , tool . description ) ,
21- category : t ( `tools.categories.${ category . toLowerCase ( ) } ` , category ) ,
22- } ) ;
23- } ) ) ;
51+ return ( {
52+ ...tool ,
53+ path : tool . path ,
54+ name : t ( `tools.${ toolI18nKey } .title` , tool . name ) ,
55+ description : t ( `tools.${ toolI18nKey } .description` , tool . description ) ,
56+ category : t ( `tools.categories.${ category . toLowerCase ( ) } ` , category ) ,
57+ } ) ;
58+ } ) ) ;
2459
2560 const toolsByCategory = computed < ToolCategory [ ] > ( ( ) => {
2661 return _ . chain ( tools . value )
0 commit comments