diff --git a/README.md b/README.md index 4da60c30..0b53f661 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,23 @@ services: - 8080:8080 ``` +## Filter tools and add home custom content + +You can add custom content in Home page by mounting a `home.custom.md` in `/usr/share/nginx/html`. + +You can filter available tools by mounting `tools-filter.json` in `/usr/share/nginx/html`. It can contains the following filtering regex: +```json +{ + "excludeCategoryFilterRegex": "", + "includeCategoryFilterRegex": "", + "excludeToolsFilterRegex": "", + "includeToolsFilterRegex": "" +} +``` +Category matches on category (English) names ; Tools matches on tools path/url. + +See (docker-tools-filter-and-home-content)[https://github.com/sharevb/it-tools] + ## To build using a custom folder: ``` diff --git a/components.d.ts b/components.d.ts index 2aae30df..bb63627a 100644 --- a/components.d.ts +++ b/components.d.ts @@ -279,6 +279,8 @@ declare module '@vue/runtime-core' { NH1: typeof import('naive-ui')['NH1'] NH3: typeof import('naive-ui')['NH3'] NIcon: typeof import('naive-ui')['NIcon'] + NInputGroup: typeof import('naive-ui')['NInputGroup'] + NInputGroupLabel: typeof import('naive-ui')['NInputGroupLabel'] NInputNumber: typeof import('naive-ui')['NInputNumber'] NLayout: typeof import('naive-ui')['NLayout'] NLayoutSider: typeof import('naive-ui')['NLayoutSider'] diff --git a/docker-tools-filter-and-home-content/docker-compose.yml b/docker-tools-filter-and-home-content/docker-compose.yml new file mode 100644 index 00000000..a39964b3 --- /dev/null +++ b/docker-tools-filter-and-home-content/docker-compose.yml @@ -0,0 +1,10 @@ +services: + it-tools: + image: sharevb/it-tools:latest + pull_policy: always + restart: unless-stopped + volumes: + - ./tools-filter.json:/usr/share/nginx/html/tools-filter.json + - ./home.custom.md:/usr/share/nginx/html/home.custom.md + ports: + - 8080:8080 \ No newline at end of file diff --git a/docker-tools-filter-and-home-content/home.custom.md b/docker-tools-filter-and-home-content/home.custom.md new file mode 100644 index 00000000..aec696a1 --- /dev/null +++ b/docker-tools-filter-and-home-content/home.custom.md @@ -0,0 +1,9 @@ +### Some titles + +Text + +``` +code +``` + +And [link](https://sharevb-it-tools.vercel.app/) \ No newline at end of file diff --git a/docker-tools-filter-and-home-content/tools-filter.json b/docker-tools-filter-and-home-content/tools-filter.json new file mode 100644 index 00000000..0f7061c9 --- /dev/null +++ b/docker-tools-filter-and-home-content/tools-filter.json @@ -0,0 +1,6 @@ +{ + "excludeCategoryFilterRegex": "^(Gaming|Maths|Physics)$", + "includeCategoryFilterRegex": "", + "excludeToolsFilterRegex": "ai-prompt-splitter", + "includeToolsFilterRegex": "illuminance-converter" +} diff --git a/public/home.custom.md b/public/home.custom.md new file mode 100644 index 00000000..e69de29b diff --git a/public/tools-filter.json b/public/tools-filter.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/public/tools-filter.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/src/pages/Home.page.vue b/src/pages/Home.page.vue index acda02da..368b6d18 100644 --- a/src/pages/Home.page.vue +++ b/src/pages/Home.page.vue @@ -3,11 +3,24 @@ import { IconDragDrop, IconFileDescription, IconHeart } from '@tabler/icons-vue' import { useHead } from '@vueuse/head'; import { computed } from 'vue'; import Draggable from 'vuedraggable'; +import VueMarkdown from 'vue-markdown-render'; import ColoredCard from '../components/ColoredCard.vue'; import ToolCard from '../components/ToolCard.vue'; import { useToolStore } from '@/tools/tools.store'; import { config } from '@/config'; +const base = import.meta.env.BASE_URL ?? '/'; +const homeCustomMarkdown = computedAsync(async () => { + try { + const remoteCustomHomeMarkdownResponse = await fetch(`${base}home.custom.md`); + if (remoteCustomHomeMarkdownResponse.ok) { + return await remoteCustomHomeMarkdownResponse.text(); + } + } + catch {} + return ''; +}); + const toolStore = useToolStore(); useHead({ title: 'IT Tools - Handy online tools for developers' }); @@ -87,6 +100,10 @@ function onUpdateFavoriteTools() { +
+ +
+

{{ $t('home.categories.allTools') }}

diff --git a/src/tools/coin-flipper/coin-flipper.vue b/src/tools/coin-flipper/coin-flipper.vue index 24ba6531..7f4a2a5b 100644 --- a/src/tools/coin-flipper/coin-flipper.vue +++ b/src/tools/coin-flipper/coin-flipper.vue @@ -12,7 +12,7 @@ const [coinFlip, refreshCoinFlip] = computedRefreshable(() => ({
-
+
{{ coinFlip.coin }}
diff --git a/src/tools/tools.store.ts b/src/tools/tools.store.ts index dbddd9ca..aaad3dd1 100644 --- a/src/tools/tools.store.ts +++ b/src/tools/tools.store.ts @@ -2,25 +2,60 @@ import { type MaybeRef, get, useStorage } from '@vueuse/core'; import { defineStore } from 'pinia'; import type { Ref } from 'vue'; import _ from 'lodash'; -import type { Tool, ToolCategory, ToolWithCategory } from './tools.types'; +import type { Tool, ToolCategory, ToolWithCategory, ToolsFilter } from './tools.types'; import { tools as allTools } from './index'; +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 = useStorage('favoriteToolsName', []) as Ref; const { t } = useI18n(); - const tools = computed(() => allTools.map((tool) => { - const toolI18nKey = tool.path.replace(/\//g, ''); - const category = tool.category || 'Development'; + 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), + }; - return ({ - ...tool, - path: tool.path, - name: t(`tools.${toolI18nKey}.title`, tool.name), - description: t(`tools.${toolI18nKey}.description`, tool.description), - category: t(`tools.categories.${category.toLowerCase()}`, category), - }); - })); + const tools = computed(() => 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'; + + return ({ + ...tool, + path: tool.path, + name: t(`tools.${toolI18nKey}.title`, tool.name), + description: t(`tools.${toolI18nKey}.description`, tool.description), + category: t(`tools.categories.${category.toLowerCase()}`, category), + }); + })); const toolsByCategory = computed(() => { return _.chain(tools.value) diff --git a/src/tools/tools.types.ts b/src/tools/tools.types.ts index d4f65697..f4106810 100644 --- a/src/tools/tools.types.ts +++ b/src/tools/tools.types.ts @@ -20,4 +20,11 @@ export interface ToolCategory { components: Tool[] } +export interface ToolsFilter { + excludeCategoryFilterRegex?: string + includeCategoryFilterRegex?: string + excludeToolsFilterRegex?: string + includeToolsFilterRegex?: string +} + export type ToolWithCategory = Tool & { category: string };