diff --git a/.prettierrc.json b/.prettierrc.json index e7407ec..f3d832f 100644 --- a/.prettierrc.json +++ b/.prettierrc.json @@ -1,5 +1,5 @@ { - "printWidth": 150, + "printWidth": 120, "semi": true, "singleQuote": false, "tabWidth": 2, diff --git a/astro.config.mjs b/astro.config.mjs index 0c6ce25..9991a20 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -1,8 +1,3 @@ -import { defineConfig } from "astro/config"; -import { h } from "hastscript"; -import { toString } from "hast-util-to-string"; -import { escape } from "html-escaper"; - /** * Integrations */ @@ -24,6 +19,14 @@ import remarkSmartypants from "remark-smartypants"; import rehypeSlug from "rehype-slug"; import rehypeAutolinkHeadings from "rehype-autolink-headings"; +/** + * Other required modules + */ +import { defineConfig } from "astro/config"; +import { h } from "hastscript"; +import { toString } from "hast-util-to-string"; +import { escape } from "html-escaper"; + const createAnchorLabel = (heading) => { const node = h("span.anchor-label", escape(heading)); node.properties["is:raw"] = true; @@ -41,11 +44,14 @@ export default defineConfig({ locales: { ru: "ru", en: "en", + de: "de", }, }, }), image(), - compress(), + compress({ + img: false, + }), mdx({ remarkPlugins: [remarkGfm, remarkSmartypants], rehypePlugins: [ diff --git a/package.json b/package.json index 4767fe8..61b17b3 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "yarkov.tech", - "version": "1.0.0", + "version": "1.0.1", "private": true, "description": "Personal website created with Astro.", "author": { @@ -15,7 +15,7 @@ "start": "astro dev", "build": "astro build", "preview": "astro preview --host", - "format": "prettier --write \"**/*.{js,jsx,ts,tsx,json,md,mdx}\"", + "format": "prettier --write ./src/\"**/*.{js,jsx,ts,tsx,json,md,mdx,astro}\"", "lint": "eslint '**/*.{js,mjs,ts,tsx}'" }, "devDependencies": { diff --git a/src/components/AlternateLangLink/AlternateLangLink.astro b/src/components/AlternateLangLink/AlternateLangLink.astro new file mode 100644 index 0000000..9481056 --- /dev/null +++ b/src/components/AlternateLangLink/AlternateLangLink.astro @@ -0,0 +1,30 @@ +--- +/** + * This components is used in article layout to display links in alternative lanugages. + */ +import { DEFAULT_LANGUAGE } from "@root/config"; +import { getLanguageFromURL } from "@root/utils"; + +export interface Props extends astroHTML.JSX.AnchorHTMLAttributes { + lang: LanguageKeys; +} + +const { pathname } = Astro.url; +const siteLang = getLanguageFromURL(pathname); +const { lang, ...attrs } = Astro.props as Props; +let href: string; +if (lang === DEFAULT_LANGUAGE) { + href = `/${pathname.split("/").slice(2).join("/")}`; +} else { + href = `/${lang}/`; + if (siteLang !== DEFAULT_LANGUAGE) { + href += `${pathname.split("/").slice(2).join("/")}`; + } else { + href += `${pathname.split("/").slice(1).join("/")}`; + } +} +--- + + + + diff --git a/src/components/AlternateLangLink/index.ts b/src/components/AlternateLangLink/index.ts new file mode 100644 index 0000000..49f0896 --- /dev/null +++ b/src/components/AlternateLangLink/index.ts @@ -0,0 +1 @@ +export { default } from "./AlternateLangLink.astro"; diff --git a/src/components/ArticleItem/ArticleItem.tsx b/src/components/ArticleItem/ArticleItem.tsx index 4ba2e3c..4051a13 100644 --- a/src/components/ArticleItem/ArticleItem.tsx +++ b/src/components/ArticleItem/ArticleItem.tsx @@ -11,16 +11,22 @@ export type ArticleItemProps = { export const ArticleItem: Component = (props) => { const isNonDefaultLanguage = props.data.lang && props.data.lang !== props.lang; - const hrefLangPrefix = props.data.lang && props.data.lang !== DEFAULT_LANGUAGE ? "/en" : ""; + const hrefLangPrefix = props.data.lang && props.data.lang !== DEFAULT_LANGUAGE ? `/${props.data.lang}` : ""; return (
- +

{props.data.title}

{isNonDefaultLanguage && {props.data.lang.toLocaleUpperCase()}}

- +

diff --git a/src/components/ArticlePost/ArticlePost.astro b/src/components/ArticlePost/ArticlePost.astro index 223098b..c67e59b 100644 --- a/src/components/ArticlePost/ArticlePost.astro +++ b/src/components/ArticlePost/ArticlePost.astro @@ -21,7 +21,9 @@ const { title, coverImage, tags, author, published_at } = data; { tags.map((tag) => (
  • - +
  • )) } @@ -31,7 +33,9 @@ const { title, coverImage, tags, author, published_at } = data;

    {title}

    - +
    { diff --git a/src/components/ArticlesList/ArticlesList.tsx b/src/components/ArticlesList/ArticlesList.tsx index b059d0c..9b7356c 100644 --- a/src/components/ArticlesList/ArticlesList.tsx +++ b/src/components/ArticlesList/ArticlesList.tsx @@ -84,7 +84,10 @@ const ArticlesList: Component = (props) => { return (

    {year}

    - } /> + } + />
    ); }} diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index ae4de95..5db2629 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -30,8 +30,20 @@ const { title = SITE_METADATA.title, description, canonicalUrl } = Astro.props a - - + + diff --git a/src/components/ContactForm/ContactForm.astro b/src/components/ContactForm/ContactForm.astro index c28cd56..44165e0 100644 --- a/src/components/ContactForm/ContactForm.astro +++ b/src/components/ContactForm/ContactForm.astro @@ -19,7 +19,14 @@ const t = useTranslation(Astro); - + diff --git a/src/components/Header/Header.astro b/src/components/Header/Header.astro index 63536d1..86938d0 100644 --- a/src/components/Header/Header.astro +++ b/src/components/Header/Header.astro @@ -24,7 +24,10 @@ const { pathname } = Astro.url; { nav.map((link) => (
  • - +
  • diff --git a/src/components/LanguageSelect/LanguageSelect.astro b/src/components/LanguageSelect/LanguageSelect.astro index 4144f64..d0865bf 100644 --- a/src/components/LanguageSelect/LanguageSelect.astro +++ b/src/components/LanguageSelect/LanguageSelect.astro @@ -1,6 +1,6 @@ --- import { Icon } from "astro-icon"; -import { DEFAULT_LANGUAGE } from "@root/config"; +import { DEFAULT_LANGUAGE, SUPPORTED_LANGUAGES } from "@root/config"; import languages from "@i18n/languages"; import { getLanguageFromURL } from "@root/utils"; @@ -11,7 +11,7 @@ const lang = getLanguageFromURL(Astro.url.pathname);