mirror of
https://github.com/sergeyyarkov/yarkov.tech.git
synced 2026-10-11 10:29:21 +03:00
optimized fetch calls
This commit is contained in:
parent
5051a6a6ca
commit
0e951d2aca
13
src/components/ArticlesList.astro
Normal file
13
src/components/ArticlesList.astro
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
---
|
||||||
|
import { useTranslation, getLanguageFromURL } from "@i18n/utils";
|
||||||
|
import { filterArticlesByPageLang, formatToArticleBlocks } from "@utils/article";
|
||||||
|
import List from "@components/ArticlesList";
|
||||||
|
import { getArticleList } from "@root/queries/article";
|
||||||
|
|
||||||
|
const t = useTranslation(Astro);
|
||||||
|
const pageLang = getLanguageFromURL(Astro.url.pathname);
|
||||||
|
const articles = (await getArticleList()).flatMap((a) => filterArticlesByPageLang(a.translations, pageLang));
|
||||||
|
const articleBlocks = formatToArticleBlocks(articles);
|
||||||
|
---
|
||||||
|
|
||||||
|
<List client:load i18n={{ "articles.empty": t("articles.empty") }} articles={articleBlocks} pageLang={pageLang} />
|
||||||
@ -1,19 +1,16 @@
|
|||||||
import type { Component } from "solid-js";
|
import type { Component } from "solid-js";
|
||||||
import { createSignal, createEffect, For } from "solid-js";
|
import { createSignal, createEffect, For } from "solid-js";
|
||||||
import { search, selectedTags, setCount } from "@stores/searchStore";
|
import { search, selectedTags, setCount } from "@stores/searchStore";
|
||||||
import SearchInput from "./SearchInput";
|
|
||||||
import TagsList from "./TagsList";
|
|
||||||
import ArticleItem from "@components/ArticleItem";
|
import ArticleItem from "@components/ArticleItem";
|
||||||
import "./ArticlesList.scss";
|
|
||||||
import { ArticleQuery } from "@/src/graphql/graphql";
|
import { ArticleQuery } from "@/src/graphql/graphql";
|
||||||
|
import "./ArticlesList.scss";
|
||||||
|
|
||||||
type UiStringsType = { "articles.empty": string; "input.search": string };
|
type UiStringsType = { "articles.empty": string };
|
||||||
|
|
||||||
type ArticlesBlockType = Record<string, ArticleQuery["article"][0]["translations"]>;
|
type ArticlesBlockType = Record<string, ArticleQuery["article"][0]["translations"]>;
|
||||||
|
|
||||||
type ArticlesListProps = {
|
type ArticlesListProps = {
|
||||||
articles: ArticlesBlockType;
|
articles: ArticlesBlockType;
|
||||||
tags: string[];
|
|
||||||
pageLang: string;
|
pageLang: string;
|
||||||
i18n: UiStringsType;
|
i18n: UiStringsType;
|
||||||
};
|
};
|
||||||
@ -35,9 +32,7 @@ const ArticlesList: Component<ArticlesListProps> = (props) => {
|
|||||||
params: { search: string; tags?: string[] };
|
params: { search: string; tags?: string[] };
|
||||||
}): ArticlesBlockType => {
|
}): ArticlesBlockType => {
|
||||||
const filter = (
|
const filter = (
|
||||||
cb: (
|
cb: (articles: ArticleQuery["article"][0]["translations"]) => ArticleQuery["article"][0]["translations"]
|
||||||
articles: ArticleQuery["article"][0]["translations"]
|
|
||||||
) => ArticleQuery["article"][0]["translations"]
|
|
||||||
) => {
|
) => {
|
||||||
return Object.fromEntries(
|
return Object.fromEntries(
|
||||||
Object.keys(props.articles)
|
Object.keys(props.articles)
|
||||||
@ -69,8 +64,6 @@ const ArticlesList: Component<ArticlesListProps> = (props) => {
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<>
|
||||||
<SearchInput i18n={{ "input.search": props.i18n["input.search"] }} />
|
|
||||||
<TagsList tags={props.tags} />
|
|
||||||
<div itemscope itemtype="http://schema.org/Blog" class="articles-list">
|
<div itemscope itemtype="http://schema.org/Blog" class="articles-list">
|
||||||
{!isEmpty() ? (
|
{!isEmpty() ? (
|
||||||
<For each={sortByYears(articles())}>
|
<For each={sortByYears(articles())}>
|
||||||
|
|||||||
@ -1,8 +1,14 @@
|
|||||||
---
|
---
|
||||||
|
import ProjectItem from "@components/ProjectItem.astro";
|
||||||
|
import { getLanguageFromURL } from "../i18n/utils";
|
||||||
|
import { getProjectList } from "../queries";
|
||||||
|
|
||||||
|
const pageLang = getLanguageFromURL(Astro.url.pathname);
|
||||||
|
const projects = await getProjectList(pageLang);
|
||||||
---
|
---
|
||||||
|
|
||||||
<div>
|
<div>
|
||||||
<slot />
|
{projects.map((data) => <ProjectItem data={data} />)}
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
|
|||||||
8
src/components/TagsList.astro
Normal file
8
src/components/TagsList.astro
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
---
|
||||||
|
import { getTagList } from "@root/queries/tag";
|
||||||
|
import List from "@components/ArticlesList/TagsList";
|
||||||
|
|
||||||
|
const tags = (await getTagList()).map((t) => t.title);
|
||||||
|
---
|
||||||
|
|
||||||
|
<List client:load tags={tags} />
|
||||||
@ -1,18 +1,14 @@
|
|||||||
---
|
---
|
||||||
import { useTranslation, getLanguageFromURL } from "@i18n/utils";
|
import { useTranslation, getLanguageFromURL } from "@i18n/utils";
|
||||||
import { filterArticlesByPageLang, formatToArticleBlocks } from "@utils/article";
|
|
||||||
import PageLayout from "@layouts/default.astro";
|
import PageLayout from "@layouts/default.astro";
|
||||||
import PageHeading from "@components/PageHeading.astro";
|
import PageHeading from "@components/PageHeading.astro";
|
||||||
import ArticlesList from "@root/components/ArticlesList";
|
import TagsList from "@components/TagsList.astro";
|
||||||
import { getTagList } from "@root/queries/tag";
|
import SearchInput from "@components/ArticlesList/SearchInput";
|
||||||
import { getArticleList } from "@root/queries/article";
|
import ArticlesList from "@components/ArticlesList.astro";
|
||||||
|
|
||||||
const t = useTranslation(Astro);
|
const t = useTranslation(Astro);
|
||||||
const pageLang = getLanguageFromURL(Astro.url.pathname);
|
const pageLang = getLanguageFromURL(Astro.url.pathname);
|
||||||
const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
|
const canonicalUrl = new URL(Astro.url.pathname, Astro.site);
|
||||||
const tags = (await getTagList()).map((t) => t.title);
|
|
||||||
const articles = (await getArticleList()).flatMap((a) => filterArticlesByPageLang(a.translations, pageLang));
|
|
||||||
const articleBlocks = formatToArticleBlocks(articles);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<PageLayout
|
<PageLayout
|
||||||
@ -23,12 +19,8 @@ const articleBlocks = formatToArticleBlocks(articles);
|
|||||||
>
|
>
|
||||||
<PageHeading heading={t("pageTitle.articles")} description={t("pageDescription.articles")} />
|
<PageHeading heading={t("pageTitle.articles")} description={t("pageDescription.articles")} />
|
||||||
<section>
|
<section>
|
||||||
<ArticlesList
|
<SearchInput i18n={{ "input.search": t("input.search") }} client:load />
|
||||||
client:load
|
<TagsList />
|
||||||
i18n={{ "articles.empty": t("articles.empty"), "input.search": t("input.search") }}
|
<ArticlesList />
|
||||||
articles={articleBlocks}
|
|
||||||
tags={tags}
|
|
||||||
pageLang={pageLang}
|
|
||||||
/>
|
|
||||||
</section>
|
</section>
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
|
|||||||
@ -1,21 +1,16 @@
|
|||||||
---
|
---
|
||||||
import PageLayout from "@layouts/default.astro";
|
import PageLayout from "@layouts/default.astro";
|
||||||
import ProjectsList from "@components/ProjectsList.astro";
|
import ProjectsList from "@components/ProjectsList.astro";
|
||||||
import ProjectItem from "@components/ProjectItem.astro";
|
|
||||||
import PageHeading from "@components/PageHeading.astro";
|
import PageHeading from "@components/PageHeading.astro";
|
||||||
import { getLanguageFromURL, useTranslation } from "@i18n/utils";
|
import { getLanguageFromURL, useTranslation } from "@i18n/utils";
|
||||||
import { getProjectList } from "../queries/project";
|
|
||||||
|
|
||||||
const t = useTranslation(Astro);
|
const t = useTranslation(Astro);
|
||||||
const pageLang = getLanguageFromURL(Astro.url.pathname);
|
const pageLang = getLanguageFromURL(Astro.url.pathname);
|
||||||
const projects = await getProjectList(pageLang);
|
|
||||||
---
|
---
|
||||||
|
|
||||||
<PageLayout noIndex lang={pageLang} title={t("pageTitle.projects")} description={t("pageDescription.projects")}>
|
<PageLayout noIndex lang={pageLang} title={t("pageTitle.projects")} description={t("pageDescription.projects")}>
|
||||||
<PageHeading heading={t("pageTitle.projects")} description={t("pageDescription.projects")} />
|
<PageHeading heading={t("pageTitle.projects")} description={t("pageDescription.projects")} />
|
||||||
<section>
|
<section>
|
||||||
<ProjectsList>
|
<ProjectsList />
|
||||||
{projects.map((data) => <ProjectItem data={data} />)}
|
|
||||||
</ProjectsList>
|
|
||||||
</section>
|
</section>
|
||||||
</PageLayout>
|
</PageLayout>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user