From 60c6bb5505150d6aa62b5fccfffff3645ba3770e Mon Sep 17 00:00:00 2001 From: sergeyyarkov Date: Sat, 18 Feb 2023 19:36:39 +0300 Subject: [PATCH] yametrika --- astro.config.mjs | 7 +++++++ siteconfig.json | 23 ++++++++++++----------- src/components/Analytics/YaMetrika.astro | 21 +++++++++++++++++++++ src/components/ArticlePost.astro | 11 +++++------ src/components/BaseHead.astro | 6 +++++- src/quicklink.js | 5 +++++ 6 files changed, 55 insertions(+), 18 deletions(-) create mode 100644 src/components/Analytics/YaMetrika.astro create mode 100644 src/quicklink.js diff --git a/astro.config.mjs b/astro.config.mjs index 646a820..e1378ac 100644 --- a/astro.config.mjs +++ b/astro.config.mjs @@ -325,6 +325,13 @@ export default defineConfig({ default: false, hint: "Отображает баннер на всех старницах о том, что веб-сайт находится в разработке", }, + { + label: "Счетчик Яндекс.Метрики", + name: "ymCounter", + widget: "number", + hint: "Например: 90034656", + required: false, + }, { label: "Статьи", name: "articles", diff --git a/siteconfig.json b/siteconfig.json index 163350d..f750c79 100644 --- a/siteconfig.json +++ b/siteconfig.json @@ -1,12 +1,13 @@ { - "globalTitle": "Sergey Yarkov", - "articles": { - "recentLimit": 5 - }, - "isSiteUnderConstruction": false, - "contacts": { - "email": "serzh.yarkov@gmail.com", - "telegram": "https://t.me/sergeyyarkov", - "github": "https://github.com/sergeyyarkov" - } -} \ No newline at end of file + "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 +} diff --git a/src/components/Analytics/YaMetrika.astro b/src/components/Analytics/YaMetrika.astro new file mode 100644 index 0000000..8f3d4c3 --- /dev/null +++ b/src/components/Analytics/YaMetrika.astro @@ -0,0 +1,21 @@ +--- +export interface Props { + counter: number; +} + +const { counter } = Astro.props as Props +--- + + \ No newline at end of file diff --git a/src/components/ArticlePost.astro b/src/components/ArticlePost.astro index b2fbbe2..2e6eafb 100644 --- a/src/components/ArticlePost.astro +++ b/src/components/ArticlePost.astro @@ -4,7 +4,7 @@ import { Icon } from "astro-icon"; import { createDateFormatter } from "@root/utils"; import ArticleCover from "@components/ArticleCover.astro"; import ArticleComments from "@components/ArticleComments.astro"; -// import TranslatedLink from "../TranslatedLink"; +import TranslatedLink from "@components/TranslatedLink.astro"; import { useTranslation, getLanguageFromURL } from "@i18n/utils"; export type Props = { @@ -19,8 +19,7 @@ const { data: { coverImage, title, author, description, tags, pubDate }, slug, } = article; - -// const t = useTranslation(Astro); +const t = useTranslation(Astro); ---
@@ -32,9 +31,9 @@ const { @@ -43,7 +42,7 @@ const { }
- --- {"просмотров"} + --- {t("article.views")}
diff --git a/src/components/BaseHead.astro b/src/components/BaseHead.astro index 73c3c72..73ea506 100644 --- a/src/components/BaseHead.astro +++ b/src/components/BaseHead.astro @@ -1,6 +1,8 @@ --- import "@styles/global.scss"; +import siteconfig from "siteconfig.json"; import { SITE_METADATA } from "@root/constants"; +import YaMetrika from "./Analytics/YaMetrika.astro"; export interface Props { title?: string; @@ -10,6 +12,7 @@ export interface Props { const canonicalURL = new URL(Astro.url.pathname, Astro.site); const { title, description } = Astro.props; +const isDev = import.meta.env.DEV; --- @@ -72,5 +75,6 @@ const { title, description } = Astro.props; - + + {!isDev && siteconfig?.ymCounter && } diff --git a/src/quicklink.js b/src/quicklink.js new file mode 100644 index 0000000..7294f2e --- /dev/null +++ b/src/quicklink.js @@ -0,0 +1,5 @@ +import { listen } from "quicklink/dist/quicklink.mjs"; +window.addEventListener("load", () => { + listen({ el: document.querySelector("body > header") }); + listen({ el: document.querySelector("body > main article header") }); +});