📈 Open source, privacy-first web analytics — a cookie-less Google Analytics alternative with built-in error tracking and performance monitoring. Self-host it or use our cloud. Get started for free!
TypeScript chartsclickhousedockergdprgoogle-analyticsmetricsmonitoringmysqlnestjsprivacyredisself-hostedselfhostedstatisticstailwindcssweb-analyticswebanalyticswebsite
added link to lastt post Blog
kruzhambus1b6da8784792
diff --git a/.env.example b/.env.exampleindex 55f2a0052..b644700b2 100644--- a/.env.example+++ b/.env.example@@ -1,3 +1,4 @@REACT_APP_API_URL=https://api.swetrix.com/+REACT_APP_BLOG_API_URL=https://blog.swetrix.com/CHOKIDAR_USEPOLLING=trueGENERATE_SOURCEMAP=falsediff --git a/src/api/blog.js b/src/api/blog.jsnew file mode 100644index 000000000..4f3e8fed1--- /dev/null+++ b/src/api/blog.js@@ -0,0 +1,47 @@+/* eslint-disable implicit-arrow-linebreak */+import axios from 'axios'+import Debug from 'debug'+import _isEmpty from 'lodash/isEmpty'+import { isSelfhosted } from 'redux/constants'++const debug = Debug('swetrix:api')++const api = axios.create({+ baseURL: isSelfhosted ? window.env.BLOG_API_URL : process.env.REACT_APP_BLOG_API_URL,+})++// api.interceptors.request.use(+// (config) => {+// const token = getAccessToken()+// if (token) {+// // eslint-disable-next-line no-param-reassign+// config.headers.Authorization = `Bearer ${token}`+// }+// return config+// },+// (error) => {+// return Promise.reject(error)+// },+// )++// api.interceptors.response.use(+// (response) => response,+// (error) => {+// if (error.response?.data.statusCode === 401) {+// removeAccessToken()+// store.dispatch(authActions.logout())+// }+// return Promise.reject(error)+// },+// )++export const getLastPost = () =>+ api+ .get('last-post?format=json')+ .then((response) => response.data)+ .catch((error) => {+ debug('%s', error)+ throw _isEmpty(error.response.data?.message)+ ? error.response.data+ : error.response.data.message+ })diff --git a/src/pages/MainPage/index.jsx b/src/pages/MainPage/index.jsxindex ee7ea9256..cafa58b7c 100644--- a/src/pages/MainPage/index.jsx+++ b/src/pages/MainPage/index.jsx@@ -1,9 +1,11 @@-import React, { memo } from 'react'+import React, { memo, useEffect } from 'react'import { Link } from 'react-router-dom'import { useTranslation, Trans } from 'react-i18next'import cx from 'clsx'import { useSelector } from 'react-redux'-import { ArrowTopRightOnSquareIcon, ArrowSmallRightIcon, CheckCircleIcon } from '@heroicons/react/24/solid'+import {+ ArrowTopRightOnSquareIcon, ArrowSmallRightIcon, CheckCircleIcon, ArrowLongRightIcon,+} from '@heroicons/react/24/solid'// import { CheckCircleIcon as CheckCircleIconOutline, Cog8ToothIcon, ClockIcon } from '@heroicons/react/24/outline'import _map from 'lodash/map'@@ -25,9 +27,13 @@ import Notion from 'ui/icons/Notion'import Ghost from 'ui/icons/Ghost'import Gatsby from 'ui/icons/Gatsby'import Wix from 'ui/icons/Wix'++import { getLastPost } from 'api/blog'+import { withAuthentication, auth } from '../../hoc/protected'import SignUp from '../Auth/Signup/BasicSignup'import Pricing from './Pricing'+import './styles.css'const LIVE_DEMO_URL = '/projects/STEzHcB1rALV'@@ -36,11 +42,27 @@ const Main = () => {const { t, i18n: { language } } = useTranslation('common')const { theme } = useSelector(state => state.ui.theme)const stats = useSelector(state => state.ui.misc.stats)+ const [lastPost, setLastPost] = React.useState({})+ const [isLoading, setIsLoading] = React.useState(true)const events = nFormatterSeparated(Number(stats.pageviews), 0)const users = nFormatterSeparated(Number(stats.users), 0)const websites = nFormatterSeparated(Number(stats.projects), 0)+ useEffect(() => {+ if (isLoading) {+ getLastPost()+ .then(res => {+ setLastPost(res)+ setIsLoading(false)+ })+ .catch(err => {+ console.log(err)+ })+ }+ // eslint-disable-next-line react-hooks/exhaustive-deps+ }, [])+return (<Title title={t('titles.main')}><div className='relative flex justify-center items-center bg-gray-900 py-2 px-2'>@@ -75,7 +97,16 @@ const Main = () => {}}/></h1>- <p className='mt-3 text-base text-gray-300 sm:mt-6 sm:text-xl lg:text-lg xl:text-lg'>+ <div className='flex items-center overflow-hidden mt-2 mb-2'>+ {!isLoading && (+ <>+ <p className='text-base text-gray-300 sm:text-xl lg:text-lg xl:text-lg'>Blog</p>+ <ArrowLongRightIcon className='w-5 h-5 text-white mx-2' />+ <a className='text-indigo-600 font-semibold' href={`${process.env.REACT_APP_BLOG_API_URL}/post/${lastPost.url_path}`}>{lastPost.title}</a>+ </>+ )}+ </div>+ <p className='text-base text-gray-300 sm:text-xl lg:text-lg xl:text-lg'>{t('main.description')}<br />{t('main.trackEveryMetric')}