feat: Home Custom Content and tools filters

Fix #1538 and part of #395
This commit is contained in:
ShareVB committed 2025-04-20 18:35:37 +02:00
1 parent 1a0ab177db
commit 9dd8412e57
11 files changed
+117 -13

No files matched your search

+17
View File
@@ -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:
```
+2
View File
@@ -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']
@@ -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
@@ -0,0 +1,9 @@
### Some titles
Text
```
code
```
And [link](https://sharevb-it-tools.vercel.app/)
@@ -0,0 +1,6 @@
{
"excludeCategoryFilterRegex": "^(Gaming|Maths|Physics)$",
"includeCategoryFilterRegex": "",
"excludeToolsFilterRegex": "ai-prompt-splitter",
"includeToolsFilterRegex": "illuminance-converter"
}
View File
Whitespace-only changes.
+1
View File
@@ -0,0 +1 @@
{}
+17
View File
@@ -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() {
</div>
</div>
<div v-if="homeCustomMarkdown">
<VueMarkdown :source="homeCustomMarkdown" />
</div>
<h3 class="mb-5px mt-25px font-500 text-neutral-400">
{{ $t('home.categories.allTools') }}
</h3>
+1 -1
View File
@@ -12,7 +12,7 @@ const [coinFlip, refreshCoinFlip] = computedRefreshable(() => ({
<div>
<Transition name="bounce" mode="out-in">
<div :key="coinFlip.dt" flex items-center justify-center>
<div flex items-center justify-center rounded-full outline style="width: 5em; height: 5em" mt-1 mb-1>
<div style="width: 5em; height: 5em" mb-1 mt-1 flex items-center justify-center rounded-full outline>
{{ coinFlip.coin }}
</div>
</div>
+47 -12
View File
@@ -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<string[]>;
const { t } = useI18n();
const tools = computed<ToolWithCategory[]>(() => 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<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';
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<ToolCategory[]>(() => {
return _.chain(tools.value)
+7
View File
@@ -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 };