📈 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
improved blog link
Blue Mousea33bf493727c
diff --git a/.env.example b/.env.exampleindex b644700b2..aad8e1f1d 100644--- a/.env.example+++ b/.env.example@@ -1,4 +1,4 @@REACT_APP_API_URL=https://api.swetrix.com/-REACT_APP_BLOG_API_URL=https://blog.swetrix.com/+REACT_APP_BLOG_URL=https://blog.swetrix.com/CHOKIDAR_USEPOLLING=trueGENERATE_SOURCEMAP=falsediff --git a/src/api/blog.js b/src/api/blog.jsindex 4f3e8fed1..39a306758 100644--- a/src/api/blog.js+++ b/src/api/blog.js@@ -2,39 +2,13 @@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,+ baseURL: process.env.REACT_APP_BLOG_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')diff --git a/src/pages/MainPage/index.jsx b/src/pages/MainPage/index.jsxindex cafa58b7c..018eaa0e4 100644--- a/src/pages/MainPage/index.jsx+++ b/src/pages/MainPage/index.jsx@@ -1,13 +1,15 @@-import React, { memo, useEffect } from 'react'+/* eslint-disable react/jsx-no-target-blank */+import React, { memo } 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, ArrowLongRightIcon,+ ArrowTopRightOnSquareIcon, ArrowSmallRightIcon, CheckCircleIcon,} from '@heroicons/react/24/solid'// import { CheckCircleIcon as CheckCircleIconOutline, Cog8ToothIcon, ClockIcon } from '@heroicons/react/24/outline'import _map from 'lodash/map'+import _isEmpty from 'lodash/isEmpty'import routes from 'routes'import { nFormatterSeparated } from 'utils/generic'@@ -28,8 +30,6 @@ 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'@@ -41,28 +41,12 @@ const LIVE_DEMO_URL = '/projects/STEzHcB1rALV'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 { stats, lastBlogPost } = useSelector(state => state.ui.misc)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'>@@ -97,13 +81,25 @@ const Main = () => {}}/></h1>- <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+ className={cx('flex items-center overflow-hidden mt-2 mb-2 sm:text-xl lg:text-lg xl:text-lg', {+ 'animate-pulse': _isEmpty(lastBlogPost),+ })}+ >+ <p className='text-base text-gray-50 dark:text-gray-100 bg-indigo-700 dark:bg-indigo-800 px-1 rounded-lg mr-2'>+ {t('footer.blog')}+ </p>+ {_isEmpty(lastBlogPost) ? (+ <div className='h-6 bg-slate-700 w-full rounded-md' />+ ) : (+ <a+ className='text-indigo-500 dark:text-indigo-600 hover:underline font-semibold'+ href={`${process.env.REACT_APP_BLOG_URL}post/${lastBlogPost.url_path}`}+ target='_blank'+ rel='noopener'+ >+ {lastBlogPost.title}+ </a>)}</div><p className='text-base text-gray-300 sm:text-xl lg:text-lg xl:text-lg'>diff --git a/src/redux/actions/ui/index.js b/src/redux/actions/ui/index.jsindex 0aad8fc21..1ed6a2029 100644--- a/src/redux/actions/ui/index.js+++ b/src/redux/actions/ui/index.js@@ -161,6 +161,11 @@ const setDashboardTabs = (tab) => ({payload: { tab },})+const setLastBlogPost = (lastBlogPost) => ({+ type: types.SET_LAST_BLOG_POST,+ payload: { lastBlogPost },+})+const UIActions = {loadProjects,loadSharedProjects,@@ -185,6 +190,7 @@ const UIActions = {setProjectsShareData,shareVerifyAsync,setDashboardTabs,+ setLastBlogPost,}export default UIActionsdiff --git a/src/redux/actions/ui/types.js b/src/redux/actions/ui/types.jsindex 53b123c84..b38bcad45 100644--- a/src/redux/actions/ui/types.js+++ b/src/redux/actions/ui/types.js@@ -18,6 +18,7 @@ export const types = {SET_DASHBOARD_PAGINATION_PAGE: 'UI_SET_DASHBOARD_PAGINATION_PAGE',SET_DASHBOARD_PAGINATION_PAGE_SHARED: 'UI_SET_DASHBOARD_PAGINATION_PAGE_SHARED',SET_SHOW_NO_EVENTS_LEFT: 'UI_SET_SHOW_NO_EVENTS_LEFT',+ SET_LAST_BLOG_POST: 'UI_SET_LAST_BLOG_POST',SET_PROJECTS_SHARE_DATA: 'UI_SET_PROJECTS_SHARE_DATA',SHARE_VERIFY_ASYNC: 'UI_SHARE_VERIFY_ASYNC',LOAD_SHARED_PROJECTS: 'UI_LOAD_SHARED_PROJECTS',diff --git a/src/redux/reducers/ui/misc.js b/src/redux/reducers/ui/misc.jsindex 68556ce44..2fea823fb 100644--- a/src/redux/reducers/ui/misc.js+++ b/src/redux/reducers/ui/misc.js@@ -13,6 +13,7 @@ const initialState = {lastEvent: null,},showNoEventsLeftBanner: false,+ lastBlogPost: {},}// eslint-disable-next-line default-param-last@@ -53,6 +54,15 @@ const miscReducer = (state = initialState, { type, payload }) => {}}+ case types.SET_LAST_BLOG_POST: {+ const { lastBlogPost } = payload++ return {+ ...state,+ lastBlogPost,+ }+ }+default:return state}diff --git a/src/redux/sagas/ui/initialise.js b/src/redux/sagas/ui/initialise.jsindex 87cf22202..343cc2f69 100644--- a/src/redux/sagas/ui/initialise.js+++ b/src/redux/sagas/ui/initialise.js@@ -1,7 +1,8 @@-import { put, call } from 'redux-saga/effects'+import { put, call, delay } from 'redux-saga/effects'import Debug from 'debug'import { getAccessToken } from 'utils/accessToken'+import { getLastPost } from 'api/blog'import UIActions from 'redux/actions/ui'const debug = Debug('swetrix:rx:s:initialise')@@ -14,6 +15,10 @@ export default function* initialise() {yield put(UIActions.loadProjects())yield put(UIActions.loadSharedProjects())}++ const lastBlogPost = yield call(getLastPost)+ yield delay(2000)+ yield put(UIActions.setLastBlogPost(lastBlogPost))} catch (e) {debug('An error occured whilst initialising: %s', e)}