From 454a82126eb3b679411b9aeaad411d0bb5a95947 Mon Sep 17 00:00:00 2001 From: sergeyyarkov Date: Wed, 22 Feb 2023 17:37:33 +0300 Subject: [PATCH] refactor --- .env.example | 1 - astro.config.mjs | 6 + siteconfig.json | 27 +- src/components/ArticlesList/ArticlesList.tsx | 12 +- .../ArticlesList/SearchInput/SearchInput.tsx | 2 +- .../ArticlesList/TagsList/TagsList.tsx | 21 +- src/components/BaseHead.astro | 4 +- src/constants.ts | 2 +- ...ние-webserial-api-для-общения-с-микроконтроллером.md | 883 +++++++++++++++++- ...ние-webserial-api-для-общения-с-микроконтроллером.md | 2 +- src/content/blog/ru/тестовая-статьия.md | 1 + ...»ючение-сдвигового-регистра-74hc595-к-микрокотнороллеру.md | 2 +- src/env.d.ts | 4 - src/pages/rss.xml.ts | 24 +- src/styles/global.scss | 1 + src/templates/Home.astro | 5 +- src/templates/NotFound.astro | 2 +- 17 files changed, 941 insertions(+), 58 deletions(-) diff --git a/.env.example b/.env.example index c64313f..7068b58 100644 --- a/.env.example +++ b/.env.example @@ -1,4 +1,3 @@ -IS_SITE_UNDER_CONSTRUCTION=false REDIS_HOST=redis-1234.p124.eu-central-5-5.ec2.cloud.redislabs.com REDIS_PASSWORD=superpassword REDIS_PORT=1234 \ No newline at end of file diff --git a/astro.config.mjs b/astro.config.mjs index 6233900..fe806a6 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -318,6 +318,12 @@ export default defineConfig({ hint: "Отображается в шапке.", default: "yarkov.tech", }, + { + label: "Автор веб-сайта", + name: "author", + widget: "string", + hint: "Отображается в подвале.", + }, { label: "Глобальный заголовок", name: "globalTitle", diff --git a/siteconfig.json b/siteconfig.json index f2f93a5..0b4679e 100644 --- a/siteconfig.json +++ b/siteconfig.json @@ -1,14 +1,15 @@ { - "globalTitle": "Sergey Yarkov", - "articles": { - "recentLimit": 5 - }, - "isSiteUnderConstruction": false, - "contacts": { - "email": "serzh.yarkov@gmail.com", - "telegram": "https://t.me/sergeyyarkov", - "github": "https://github.com/sergeyyarkov" - }, - "ymCounter": 90034656, - "name": "yarkov.tech" -} + "globalTitle": "Sergey Yarkov", + "articles": { + "recentLimit": 5 + }, + "isSiteUnderConstruction": false, + "contacts": { + "email": "serzh.yarkov@gmail.com", + "telegram": "https://t.me/sergeyyarkov", + "github": "https://github.com/sergeyyarkov" + }, + "ymCounter": 90034656, + "name": "yarkov.tech", + "author": "Sergey Yarkov" +} \ No newline at end of file diff --git a/src/components/ArticlesList/ArticlesList.tsx b/src/components/ArticlesList/ArticlesList.tsx index 89ff51a..c0bb5a5 100644 --- a/src/components/ArticlesList/ArticlesList.tsx +++ b/src/components/ArticlesList/ArticlesList.tsx @@ -40,17 +40,17 @@ const ArticlesList: Component = (props) => { }: { params: { search: string; tags?: string[] }; }): ArticlesBlockType => { - const filter = (cb: (year: string) => ArticlesType) => { + const filter = (cb: (articles: ArticlesType) => ArticlesType) => { return Object.fromEntries( Object.keys(props.articles) - .map((year) => [year, cb(year)]) + .map((year) => [year, cb(props.articles[year])]) .filter((articles) => articles[1].length !== 0) ); }; - return filter((year) => { - let filtered = props.articles[year].filter((a) => - a.title.toLocaleLowerCase().includes(search) + return filter((articles) => { + let filtered = articles.filter((a) => + a.title.toLocaleLowerCase().includes(search.trim().toLocaleLowerCase()) ); if (tags && tags.length > 0) { filtered = filtered.filter((a) => tags.some((t) => a.tags.includes(t))); @@ -68,7 +68,7 @@ const ArticlesList: Component = (props) => { return ( <> - +
{!isEmpty() ? ( diff --git a/src/components/ArticlesList/SearchInput/SearchInput.tsx b/src/components/ArticlesList/SearchInput/SearchInput.tsx index ff1ac95..2b95dc9 100644 --- a/src/components/ArticlesList/SearchInput/SearchInput.tsx +++ b/src/components/ArticlesList/SearchInput/SearchInput.tsx @@ -21,7 +21,7 @@ const SearchInput: Component = (props) => { * Update state and set url param */ const onSearch: JSX.EventHandler = (e) => { - const value = e.currentTarget.value.trim().toLocaleLowerCase(); + const value = e.currentTarget.value; if (value.trim().length === 0) { resetSearch(); diff --git a/src/components/ArticlesList/TagsList/TagsList.tsx b/src/components/ArticlesList/TagsList/TagsList.tsx index 55a1c75..17ca589 100644 --- a/src/components/ArticlesList/TagsList/TagsList.tsx +++ b/src/components/ArticlesList/TagsList/TagsList.tsx @@ -3,7 +3,7 @@ import { For, createEffect } from "solid-js"; import { selectedTags, setSelectedTags } from "@stores/searchStore"; import * as utils from "@utils/history"; -type TagsListProps = { data: string[] }; +type TagsListProps = { tags: string[] }; const TagsList: Component = (props) => { const isTagSelected = (tag: string) => selectedTags().includes(tag); @@ -18,7 +18,7 @@ const TagsList: Component = (props) => { history.replaceState(null, "", url); }; - const onSelect: JSX.EventHandler = (e) => { + const onSelect: JSX.EventHandler = (e) => { const tag = e.target.getAttribute("data-tag"); if (!tag) return; @@ -52,14 +52,13 @@ const TagsList: Component = (props) => { }; createEffect(() => { - let param: string | string[] = new URLSearchParams(location.search).get("tags"); + let param: string | null | string[] = new URLSearchParams(location.search).get("tags"); if (!param) { resetSelected(); return; } - /* to array */ param = param.split(","); if (param.length === 0) { @@ -67,23 +66,13 @@ const TagsList: Component = (props) => { return; } - const tags: string[] = []; - - for (const tag of props.data) { - const isTagExist = param.includes(tag); - - if (isTagExist) { - tags.push(tag); - } - } - - setSelectedTags(tags); + setSelectedTags(props.tags.filter((t) => param?.includes(t))); }); return (