diff --git a/package.json b/package.json index 2c361f3..c805d47 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "type": "module", "scripts": { "dev": "astro dev", - "build": "astro build", + "build": "astro check && astro build", "start": "node --env-file=.env ./dist/server/entry.mjs", "preview": "astro preview", "astro": "astro", diff --git a/src/components/ArticleContent.astro b/src/components/ArticleContent.astro index eacc8f7..17b2ce7 100644 --- a/src/components/ArticleContent.astro +++ b/src/components/ArticleContent.astro @@ -7,7 +7,7 @@ const tocTitle = t("article.tableOfContents");
- - - diff --git a/src/components/TableOfContentsHeading.astro b/src/components/TableOfContentsHeading.astro deleted file mode 100644 index b69dd7b..0000000 --- a/src/components/TableOfContentsHeading.astro +++ /dev/null @@ -1,16 +0,0 @@ ---- -import type { MarkdownHeadingToc } from "@root/utils"; - -export interface Props { - heading: MarkdownHeadingToc; -} - -const { heading } = Astro.props; ---- - -
  • - {heading.text} - -
  • diff --git a/src/graphql/gql.ts b/src/graphql/gql.ts index 504e8e2..4374753 100644 --- a/src/graphql/gql.ts +++ b/src/graphql/gql.ts @@ -17,8 +17,8 @@ import * as types from './graphql'; type Documents = { "\n\t\tquery LatestAppealByClientIpQuery($client_ip: String!, $limit: Int!) {\n\t\t\tappeal(filter: { client_ip: { _eq: $client_ip } }, sort: [\"-date_created\"], limit: $limit) {\n\t\t\t\tclient_ip\n\t\t\t\tdate_created\n\t\t\t}\n\t\t}\n\t": typeof types.LatestAppealByClientIpQueryDocument, "\n\t\tmutation CreateAppealQuery(\n\t\t\t$name: String!\n\t\t\t$email: String!\n\t\t\t$subject: String!\n\t\t\t$message: String!\n\t\t\t$client_ip: String!\n\t\t) {\n\t\t\tcreate_appeal_item(\n\t\t\t\tdata: { name: $name, email: $email, subject: $subject, message: $message, client_ip: $client_ip }\n\t\t\t) {\n\t\t\t\tid\n\t\t\t}\n\t\t}\n\t": typeof types.CreateAppealQueryDocument, - "\n\t\tquery Article {\n\t\t\tarticle {\n\t\t\t\ttranslations(filter: { status: { _eq: \"published\" } }) {\n\t\t\t\t\tid\n\t\t\t\t\ttitle\n\t\t\t\t\ttags {\n\t\t\t\t\t\ttag_id {\n\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdescription\n\t\t\t\t\tslug\n\t\t\t\t\tpub_date\n\t\t\t\t\tlanguages_code {\n\t\t\t\t\t\tcode\n\t\t\t\t\t\tname\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": typeof types.ArticleDocument, - "\n\t\tquery RecentArticle {\n\t\t\tarticle {\n\t\t\t\ttranslations(filter: { status: { _eq: \"published\" } }, sort: [\"-pub_date\"]) {\n\t\t\t\t\ttitle\n\t\t\t\t\tcover_image {\n\t\t\t\t\t\tid\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t\tslug\n\t\t\t\t\tpub_date\n\t\t\t\t\tviews\n\t\t\t\t\tlanguages_code {\n\t\t\t\t\t\tcode\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": typeof types.RecentArticleDocument, + "\n\t\tquery Article {\n\t\t\tarticle_translations(filter: { status: { _eq: \"published\" } }) {\n\t\t\t\tid\n\t\t\t\ttitle\n\t\t\t\ttags {\n\t\t\t\t\ttag_id {\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdescription\n\t\t\t\tslug\n\t\t\t\tpub_date\n\t\t\t\tlanguages_code {\n\t\t\t\t\tcode\n\t\t\t\t\tname\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": typeof types.ArticleDocument, + "\n\t\tquery RecentArticle($limit: Int!) {\n\t\t\tarticle_translations(filter: { status: { _eq: \"published\" } }, sort: [\"-pub_date\"], limit: $limit) {\n\t\t\t\ttitle\n\t\t\t\tslug\n\t\t\t\tpub_date\n\t\t\t\tlanguages_code {\n\t\t\t\t\tcode\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": typeof types.RecentArticleDocument, "\n\t\tquery Article_translations($slug: String!) {\n\t\t\tarticle_translations(filter: { slug: { _eq: $slug } }) {\n\t\t\t\tid\n\t\t\t\ttitle\n\t\t\t\ttags {\n\t\t\t\t\ttag_id {\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdescription\n\t\t\t\tslug\n\t\t\t\tcontent\n\t\t\t\tauthor {\n\t\t\t\t\tfirst_name\n\t\t\t\t\tlast_name\n\t\t\t\t}\n\t\t\t\tpub_date\n\t\t\t\tviews\n\t\t\t\tlanguages_code {\n\t\t\t\t\tcode\n\t\t\t\t\tname\n\t\t\t\t}\n\t\t\t\tcover_image {\n\t\t\t\t\ttitle\n\t\t\t\t\ttype\n\t\t\t\t\tfilename_disk\n\t\t\t\t}\n\t\t\t\tarticle_id {\n\t\t\t\t\ttranslations {\n\t\t\t\t\t\tslug\n\t\t\t\t\t\tlanguages_code {\n\t\t\t\t\t\t\tcode\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpub_date\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": typeof types.Article_TranslationsDocument, "\n\t\tmutation Update_article_translations_item($id: ID!, $views: Int!) {\n\t\t\tupdate_article_translations_item(id: $id, data: { views: $views }) {\n\t\t\t\tviews\n\t\t\t}\n\t\t}\n\t": typeof types.Update_Article_Translations_ItemDocument, "\n\t\tquery AboutMeQuery($pageLang: String!) {\n\t\t\tglobal_translations(filter: { languages_code: { code: { _contains: $pageLang } } }) {\n\t\t\t\tabout\n\t\t\t}\n\t\t}\n\t": typeof types.AboutMeQueryDocument, @@ -30,8 +30,8 @@ type Documents = { const documents: Documents = { "\n\t\tquery LatestAppealByClientIpQuery($client_ip: String!, $limit: Int!) {\n\t\t\tappeal(filter: { client_ip: { _eq: $client_ip } }, sort: [\"-date_created\"], limit: $limit) {\n\t\t\t\tclient_ip\n\t\t\t\tdate_created\n\t\t\t}\n\t\t}\n\t": types.LatestAppealByClientIpQueryDocument, "\n\t\tmutation CreateAppealQuery(\n\t\t\t$name: String!\n\t\t\t$email: String!\n\t\t\t$subject: String!\n\t\t\t$message: String!\n\t\t\t$client_ip: String!\n\t\t) {\n\t\t\tcreate_appeal_item(\n\t\t\t\tdata: { name: $name, email: $email, subject: $subject, message: $message, client_ip: $client_ip }\n\t\t\t) {\n\t\t\t\tid\n\t\t\t}\n\t\t}\n\t": types.CreateAppealQueryDocument, - "\n\t\tquery Article {\n\t\t\tarticle {\n\t\t\t\ttranslations(filter: { status: { _eq: \"published\" } }) {\n\t\t\t\t\tid\n\t\t\t\t\ttitle\n\t\t\t\t\ttags {\n\t\t\t\t\t\ttag_id {\n\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdescription\n\t\t\t\t\tslug\n\t\t\t\t\tpub_date\n\t\t\t\t\tlanguages_code {\n\t\t\t\t\t\tcode\n\t\t\t\t\t\tname\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": types.ArticleDocument, - "\n\t\tquery RecentArticle {\n\t\t\tarticle {\n\t\t\t\ttranslations(filter: { status: { _eq: \"published\" } }, sort: [\"-pub_date\"]) {\n\t\t\t\t\ttitle\n\t\t\t\t\tcover_image {\n\t\t\t\t\t\tid\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t\tslug\n\t\t\t\t\tpub_date\n\t\t\t\t\tviews\n\t\t\t\t\tlanguages_code {\n\t\t\t\t\t\tcode\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": types.RecentArticleDocument, + "\n\t\tquery Article {\n\t\t\tarticle_translations(filter: { status: { _eq: \"published\" } }) {\n\t\t\t\tid\n\t\t\t\ttitle\n\t\t\t\ttags {\n\t\t\t\t\ttag_id {\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdescription\n\t\t\t\tslug\n\t\t\t\tpub_date\n\t\t\t\tlanguages_code {\n\t\t\t\t\tcode\n\t\t\t\t\tname\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": types.ArticleDocument, + "\n\t\tquery RecentArticle($limit: Int!) {\n\t\t\tarticle_translations(filter: { status: { _eq: \"published\" } }, sort: [\"-pub_date\"], limit: $limit) {\n\t\t\t\ttitle\n\t\t\t\tslug\n\t\t\t\tpub_date\n\t\t\t\tlanguages_code {\n\t\t\t\t\tcode\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": types.RecentArticleDocument, "\n\t\tquery Article_translations($slug: String!) {\n\t\t\tarticle_translations(filter: { slug: { _eq: $slug } }) {\n\t\t\t\tid\n\t\t\t\ttitle\n\t\t\t\ttags {\n\t\t\t\t\ttag_id {\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdescription\n\t\t\t\tslug\n\t\t\t\tcontent\n\t\t\t\tauthor {\n\t\t\t\t\tfirst_name\n\t\t\t\t\tlast_name\n\t\t\t\t}\n\t\t\t\tpub_date\n\t\t\t\tviews\n\t\t\t\tlanguages_code {\n\t\t\t\t\tcode\n\t\t\t\t\tname\n\t\t\t\t}\n\t\t\t\tcover_image {\n\t\t\t\t\ttitle\n\t\t\t\t\ttype\n\t\t\t\t\tfilename_disk\n\t\t\t\t}\n\t\t\t\tarticle_id {\n\t\t\t\t\ttranslations {\n\t\t\t\t\t\tslug\n\t\t\t\t\t\tlanguages_code {\n\t\t\t\t\t\t\tcode\n\t\t\t\t\t\t\tname\n\t\t\t\t\t\t}\n\t\t\t\t\t\tpub_date\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t": types.Article_TranslationsDocument, "\n\t\tmutation Update_article_translations_item($id: ID!, $views: Int!) {\n\t\t\tupdate_article_translations_item(id: $id, data: { views: $views }) {\n\t\t\t\tviews\n\t\t\t}\n\t\t}\n\t": types.Update_Article_Translations_ItemDocument, "\n\t\tquery AboutMeQuery($pageLang: String!) {\n\t\t\tglobal_translations(filter: { languages_code: { code: { _contains: $pageLang } } }) {\n\t\t\t\tabout\n\t\t\t}\n\t\t}\n\t": types.AboutMeQueryDocument, @@ -52,11 +52,11 @@ export function graphql(source: "\n\t\tmutation CreateAppealQuery(\n\t\t\t$name: /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function graphql(source: "\n\t\tquery Article {\n\t\t\tarticle {\n\t\t\t\ttranslations(filter: { status: { _eq: \"published\" } }) {\n\t\t\t\t\tid\n\t\t\t\t\ttitle\n\t\t\t\t\ttags {\n\t\t\t\t\t\ttag_id {\n\t\t\t\t\t\t\ttitle\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t\tdescription\n\t\t\t\t\tslug\n\t\t\t\t\tpub_date\n\t\t\t\t\tlanguages_code {\n\t\t\t\t\t\tcode\n\t\t\t\t\t\tname\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t"): typeof import('./graphql').ArticleDocument; +export function graphql(source: "\n\t\tquery Article {\n\t\t\tarticle_translations(filter: { status: { _eq: \"published\" } }) {\n\t\t\t\tid\n\t\t\t\ttitle\n\t\t\t\ttags {\n\t\t\t\t\ttag_id {\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tdescription\n\t\t\t\tslug\n\t\t\t\tpub_date\n\t\t\t\tlanguages_code {\n\t\t\t\t\tcode\n\t\t\t\t\tname\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t"): typeof import('./graphql').ArticleDocument; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ -export function graphql(source: "\n\t\tquery RecentArticle {\n\t\t\tarticle {\n\t\t\t\ttranslations(filter: { status: { _eq: \"published\" } }, sort: [\"-pub_date\"]) {\n\t\t\t\t\ttitle\n\t\t\t\t\tcover_image {\n\t\t\t\t\t\tid\n\t\t\t\t\t\ttitle\n\t\t\t\t\t}\n\t\t\t\t\tslug\n\t\t\t\t\tpub_date\n\t\t\t\t\tviews\n\t\t\t\t\tlanguages_code {\n\t\t\t\t\t\tcode\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t"): typeof import('./graphql').RecentArticleDocument; +export function graphql(source: "\n\t\tquery RecentArticle($limit: Int!) {\n\t\t\tarticle_translations(filter: { status: { _eq: \"published\" } }, sort: [\"-pub_date\"], limit: $limit) {\n\t\t\t\ttitle\n\t\t\t\tslug\n\t\t\t\tpub_date\n\t\t\t\tlanguages_code {\n\t\t\t\t\tcode\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t"): typeof import('./graphql').RecentArticleDocument; /** * The graphql function is used to parse GraphQL queries into a document that can be used by GraphQL clients. */ diff --git a/src/graphql/graphql.ts b/src/graphql/graphql.ts index 4cda543..99cd96c 100644 --- a/src/graphql/graphql.ts +++ b/src/graphql/graphql.ts @@ -4544,12 +4544,14 @@ export type CreateAppealQueryMutation = { __typename?: 'Mutation', create_appeal export type ArticleQueryVariables = Exact<{ [key: string]: never; }>; -export type ArticleQuery = { __typename?: 'Query', article: Array<{ __typename?: 'article', translations?: Array<{ __typename?: 'article_translations', id: string, title: string, description: string, slug: string, pub_date: any, tags?: Array<{ __typename?: 'article_translations_tag', tag_id?: { __typename?: 'tag', title: string } | null } | null> | null, languages_code?: { __typename?: 'languages', code: string, name?: string | null } | null } | null> | null }> }; +export type ArticleQuery = { __typename?: 'Query', article_translations: Array<{ __typename?: 'article_translations', id: string, title: string, description: string, slug: string, pub_date: any, tags?: Array<{ __typename?: 'article_translations_tag', tag_id?: { __typename?: 'tag', title: string } | null } | null> | null, languages_code?: { __typename?: 'languages', code: string, name?: string | null } | null }> }; -export type RecentArticleQueryVariables = Exact<{ [key: string]: never; }>; +export type RecentArticleQueryVariables = Exact<{ + limit: Scalars['Int']['input']; +}>; -export type RecentArticleQuery = { __typename?: 'Query', article: Array<{ __typename?: 'article', translations?: Array<{ __typename?: 'article_translations', title: string, slug: string, pub_date: any, views: number, cover_image?: { __typename?: 'directus_files', id: string, title?: string | null } | null, languages_code?: { __typename?: 'languages', code: string } | null } | null> | null }> }; +export type RecentArticleQuery = { __typename?: 'Query', article_translations: Array<{ __typename?: 'article_translations', title: string, slug: string, pub_date: any, languages_code?: { __typename?: 'languages', code: string } | null }> }; export type Article_TranslationsQueryVariables = Exact<{ slug: Scalars['String']['input']; @@ -4637,41 +4639,36 @@ export const CreateAppealQueryDocument = new TypedDocumentString(` `) as unknown as TypedDocumentString; export const ArticleDocument = new TypedDocumentString(` query Article { - article { - translations(filter: {status: {_eq: "published"}}) { - id - title - tags { - tag_id { - title - } - } - description - slug - pub_date - languages_code { - code - name + article_translations(filter: {status: {_eq: "published"}}) { + id + title + tags { + tag_id { + title } } + description + slug + pub_date + languages_code { + code + name + } } } `) as unknown as TypedDocumentString; export const RecentArticleDocument = new TypedDocumentString(` - query RecentArticle { - article { - translations(filter: {status: {_eq: "published"}}, sort: ["-pub_date"]) { - title - cover_image { - id - title - } - slug - pub_date - views - languages_code { - code - } + query RecentArticle($limit: Int!) { + article_translations( + filter: {status: {_eq: "published"}} + sort: ["-pub_date"] + limit: $limit + ) { + title + slug + pub_date + languages_code { + code } } } diff --git a/src/queries/article.ts b/src/queries/article.ts index b22ec32..40e11a3 100644 --- a/src/queries/article.ts +++ b/src/queries/article.ts @@ -5,23 +5,21 @@ import { Article_Translations } from "../graphql/graphql"; export async function getArticleList() { const ArticleQuery = graphql(` query Article { - article { - translations(filter: { status: { _eq: "published" } }) { - id - title - tags { - tag_id { - title - } - } - description - slug - pub_date - languages_code { - code - name + article_translations(filter: { status: { _eq: "published" } }) { + id + title + tags { + tag_id { + title } } + description + slug + pub_date + languages_code { + code + name + } } } `); @@ -30,35 +28,28 @@ export async function getArticleList() { if (!result.data) return []; - return result.data.article; + return result.data.article_translations; } -export async function getRecentArticleList() { +export async function getRecentArticleList(limit: number = 5) { const RecentArticleQuery = graphql(` - query RecentArticle { - article { - translations(filter: { status: { _eq: "published" } }, sort: ["-pub_date"]) { - title - cover_image { - id - title - } - slug - pub_date - views - languages_code { - code - } + query RecentArticle($limit: Int!) { + article_translations(filter: { status: { _eq: "published" } }, sort: ["-pub_date"], limit: $limit) { + title + slug + pub_date + languages_code { + code } } } `); - const result = await execute(RecentArticleQuery); + const result = await execute(RecentArticleQuery, { limit }); if (!result.data) return []; - return result.data.article; + return result.data.article_translations; } export async function getArticleTranslationsBySlug(slug: string) { diff --git a/src/templates/Home.astro b/src/templates/Home.astro index d847986..ecb8fd0 100644 --- a/src/templates/Home.astro +++ b/src/templates/Home.astro @@ -28,5 +28,5 @@ const t = useTranslation(Astro); - + diff --git a/src/utils/article.ts b/src/utils/article.ts index b7af35f..469437b 100644 --- a/src/utils/article.ts +++ b/src/utils/article.ts @@ -1,13 +1,12 @@ -import type { MarkdownHeading } from "astro"; import { DEFAULT_LANGUAGE } from "@root/constants"; -import { ArticleQuery } from "../graphql/graphql"; +import { Article_Translations, ArticleQuery } from "../graphql/graphql"; /** * If there is a translation of an article in the current language of the page, * the remaining articles with other translations should be removed. */ -export function filterArticlesByPageLang( - articles: ArticleQuery["article"][number]["translations"], +export function filterArticlesByPageLang( + articles: Array>, pageLang: LanguageKeys ) { if (!articles) return []; @@ -33,8 +32,8 @@ export function createRelativeArticleUrl( return `${lang}/${prefix}/${date}/${slug}`; } -export function formatToArticleBlocks(articles: ArticleQuery["article"][0]["translations"]) { - const blocks: Record = {}; +export function formatToArticleBlocks(articles: Array>) { + const blocks: Record>> = {}; if (!articles) return {}; @@ -48,21 +47,3 @@ export function formatToArticleBlocks(articles: ArticleQuery["article"][0]["tran return blocks; } - -export type MarkdownHeadingToc = MarkdownHeading & { subheadings?: MarkdownHeading[] }; - -export function buildToc(headings: MarkdownHeading[], maxDepth: number = 2) { - const toc: MarkdownHeadingToc[] = []; - const parentHeadings = new Map(); - - headings.forEach((h) => { - const heading = { ...h, subheadings: [] }; - parentHeadings.set(heading.depth, heading); - if (heading.depth === 1) { - toc.push(heading); - } else if (heading.depth <= maxDepth) { - parentHeadings.get(heading.depth - 1)?.subheadings.push(heading); - } - }); - return toc; -}