Skip to content

📈 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!

fixed blog articles meta tags

Blue Mousecd50bc76fa75
diff --git a/app/App.tsx b/app/App.tsx
index 7cef2fe98..5842b4756 100644
--- a/app/App.tsx
+++ b/app/App.tsx
@@ -35,7 +35,7 @@ interface IApp {
}
const TITLE_BLACKLIST = [
- '/projects/', '/captchas/',
+ '/projects/', '/captchas/', '/blog',
]
const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {
@@ -92,7 +92,7 @@ const App: React.FC<IApp> = ({ ssrTheme, ssrAuthenticated }) => {
}, [message, type]) // eslint-disable-line
useEffect(() => {
- if (_some(TITLE_BLACKLIST, (page) => _includes(pathname, page))) {
+ if (_some(TITLE_BLACKLIST, (page) => _startsWith(pathname, page))) {
return
}
diff --git a/app/components/Header/index.tsx b/app/components/Header/index.tsx
index 1d86a65d5..e715a8349 100644
--- a/app/components/Header/index.tsx
+++ b/app/components/Header/index.tsx
@@ -490,7 +490,7 @@ const NotAuthedHeader = ({
{/* Language selector */}
<Dropdown
items={whitelist}
- buttonClassName='inline-flex items-center [&>svg]:w-4 [&>svg]:h-4 [&>svg]:mr-0 [&>svg]:ml-1 text-sm font-semibold leading-6 text-base text-slate-800 hover:text-slate-700 dark:text-slate-200 dark:hover:text-white'
+ buttonClassName='!py-0 inline-flex items-center [&>svg]:w-4 [&>svg]:h-4 [&>svg]:mr-0 [&>svg]:ml-1 text-sm font-semibold leading-6 text-base text-slate-800 hover:text-slate-700 dark:text-slate-200 dark:hover:text-white'
selectItemClassName='text-gray-700 block px-4 py-2 text-base cursor-pointer hover:bg-gray-200 dark:text-gray-50 dark:bg-slate-800 dark:hover:bg-slate-700'
title={(
<>
@@ -725,7 +725,6 @@ const Header: React.FC<IHeader> = ({ ssrTheme, authenticated, refPage, transpare
</div>
)}
onSelect={onLanguageChange}
- headless
/>
{authenticated ? (
<>
diff --git a/app/entry.server.tsx b/app/entry.server.tsx
index 3b215df61..55db3ab86 100644
--- a/app/entry.server.tsx
+++ b/app/entry.server.tsx
@@ -16,8 +16,6 @@ import i18n, { detectLanguage } from './i18n'
const ABORT_DELAY = 5_000
-
-
const { isSitemapUrl, sitemap } = createSitemapGenerator({
siteUrl: MAIN_URL,
autoLastmod: false,
diff --git a/app/root.tsx b/app/root.tsx
index 88a0aaee7..8bb692a39 100644
--- a/app/root.tsx
+++ b/app/root.tsx
@@ -1,5 +1,5 @@
import type {
- LinksFunction, LoaderArgs, V2_MetaFunction, HeadersFunction,
+ LinksFunction, LoaderArgs, HeadersFunction,
} from '@remix-run/node'
import { json, redirect } from '@remix-run/node'
import { useState } from 'react'
@@ -25,6 +25,7 @@ import { Provider } from 'react-redux'
import clsx from 'clsx'
import _map from 'lodash/map'
import _replace from 'lodash/replace'
+import _startsWith from 'lodash/startsWith'
// @ts-ignore
import { transitions, positions, Provider as AlertProvider } from '@blaumaus/react-alert'
import BillboardCss from 'billboard.js/dist/billboard.min.css'
@@ -75,11 +76,6 @@ export const links: LinksFunction = () => [
{ rel: 'stylesheet', href: FontsCss },
]
-export const meta: V2_MetaFunction = () => [
- { property: 'twitter:image', content: 'https://swetrix.com/assets/og_image.png' },
- { property: 'og:image', content: 'https://swetrix.com/assets/og_image.png' },
-]
-
export const headers: HeadersFunction = (stuff) => ({
// General headers
'access-control-allow-origin': '*',
@@ -220,7 +216,7 @@ export async function loader({ request }: LoaderArgs) {
} : undefined
return json({
- locale, url, theme, REMIX_ENV, isAuthed,
+ locale, url, theme, REMIX_ENV, isAuthed, pathname: urlObject.pathname,
}, init)
}
@@ -230,7 +226,7 @@ export const handle = {
export default function App() {
const {
- locale, url, theme, REMIX_ENV, isAuthed,
+ locale, url, theme, REMIX_ENV, isAuthed, pathname,
} = useLoaderData<typeof loader>()
const { i18n, t } = useTranslation('common')
const { title } = getPageMeta(t, url)
@@ -261,19 +257,27 @@ export default function App() {
useChangeLanguage(locale)
+ const isBlogPage = _startsWith(pathname, '/blog')
+
return (
<html className={theme} lang={locale} dir={i18n.dir()}>
<head>
<meta charSet='utf-8' />
- <title>{title}</title>
+ {!isBlogPage && (
+ <>
+ <title>{title}</title>
+ <meta property='og:title' content='Swetrix' />
+ <meta name='description' content='Swetrix is a cookieless, privacy-first and GDPR-compliant Google Analytics alternative' />
+ <meta name='twitter:description' content='Swetrix is a cookieless, privacy-first and GDPR-compliant Google Analytics alternative' />
+ <meta property='og:description' content='Swetrix is a cookieless, privacy-first and GDPR-compliant Google Analytics alternative' />
+ </>
+ )}
<meta name='theme-color' content='#818cf8' />
- <meta name='description' content='Swetrix is a cookieless, privacy-first and GDPR-compliant Google Analytics alternative' />
<meta name='twitter:title' content='Swetrix | Ultimate open-source web analytics to satisfy all your needs' />
<meta name='twitter:site' content='@swetrix' />
- <meta name='twitter:description' content='Swetrix is a cookieless, privacy-first and GDPR-compliant Google Analytics alternative' />
<meta name='twitter:card' content='summary_large_image' />
- <meta property='og:title' content='Swetrix' />
- <meta property='og:description' content='Swetrix is a cookieless, privacy-first and GDPR-compliant Google Analytics alternative' />
+ <meta name='twitter:image' content='https://swetrix.com/assets/og_image.png' />
+ <meta property='og:image' content='https://swetrix.com/assets/og_image.png' />
<meta property='og:site_name' content='Swetrix' />
<meta property='og:url' content='https://swetrix.com' />
<meta property='og:type' content='website' />
diff --git a/app/routes/blog.$category.$slug.tsx b/app/routes/blog.$category.$slug.tsx
index 4b9ab1815..b005f4be6 100644
--- a/app/routes/blog.$category.$slug.tsx
+++ b/app/routes/blog.$category.$slug.tsx
@@ -1,14 +1,38 @@
-import type { LoaderFunction, LinksFunction } from '@remix-run/node'
+import type { LoaderFunction, LinksFunction, V2_MetaFunction } from '@remix-run/node'
import { redirect, json } from '@remix-run/node'
import singlePostCss from 'css/mdfile.css'
import { getPost } from 'utils/getPosts'
-import { isSelfhosted } from 'redux/constants'
+import { isSelfhosted, TITLE_SUFFIX } from 'redux/constants'
import Post from 'pages/Blog/Post'
export const links: LinksFunction = () => {
return [{ rel: 'stylesheet', href: singlePostCss }]
}
+export const meta: V2_MetaFunction = (loaderData: any) => {
+ return [
+ {
+ title: `${loaderData?.data?.title || 'Blog'} ${TITLE_SUFFIX}`,
+ },
+ {
+ property: "og:title",
+ content: `${loaderData?.data?.title || 'Blog'} ${TITLE_SUFFIX}`,
+ },
+ {
+ property: "og:description",
+ content: loaderData?.data?.intro || '',
+ },
+ {
+ property: "twitter:description",
+ content: loaderData?.data?.intro || '',
+ },
+ {
+ property: "description",
+ content: loaderData?.data?.intro || '',
+ },
+ ]
+}
+
export const loader: LoaderFunction = async ({ params }) => {
if (isSelfhosted) {
return redirect('/dashboard', 302)
diff --git a/app/routes/blog.$slug.tsx b/app/routes/blog.$slug.tsx
index ba953da80..afbef58c4 100644
--- a/app/routes/blog.$slug.tsx
+++ b/app/routes/blog.$slug.tsx
@@ -1,5 +1,5 @@
import type { SitemapFunction } from 'remix-sitemap'
-import type { LoaderFunction, LinksFunction } from '@remix-run/node'
+import type { LoaderFunction, LinksFunction, V2_MetaFunction } from '@remix-run/node'
import { redirect, json } from '@remix-run/node'
import _map from 'lodash/map'
import _last from 'lodash/last'
@@ -10,13 +10,37 @@ import {
getPost, getSlugFromFilename, getDateFromFilename,
} from 'utils/getPosts'
import { getSitemap } from 'api'
-import { isSelfhosted } from 'redux/constants'
+import { isSelfhosted, TITLE_SUFFIX} from 'redux/constants'
import Post from 'pages/Blog/Post'
export const links: LinksFunction = () => {
return [{ rel: 'stylesheet', href: singlePostCss }]
}
+export const meta: V2_MetaFunction = (loaderData: any) => {
+ return [
+ {
+ title: `${loaderData?.data?.title || 'Blog'} ${TITLE_SUFFIX}`,
+ },
+ {
+ property: "og:title",
+ content: `${loaderData?.data?.title || 'Blog'} ${TITLE_SUFFIX}`,
+ },
+ {
+ property: "og:description",
+ content: loaderData?.data?.intro || '',
+ },
+ {
+ property: "twitter:description",
+ content: loaderData?.data?.intro || '',
+ },
+ {
+ property: "description",
+ content: loaderData?.data?.intro || '',
+ },
+ ]
+}
+
export const sitemap: SitemapFunction = async () => {
const files = await getSitemap()
diff --git a/app/routes/blog.tsx b/app/routes/blog.tsx
index bbc12bd8a..f45dab392 100644
--- a/app/routes/blog.tsx
+++ b/app/routes/blog.tsx
@@ -1,10 +1,24 @@
+import type { V2_MetaFunction } from '@remix-run/node'
import { Link, useLoaderData } from '@remix-run/react'
import { blogLoader } from 'utils/getPosts'
import _map from 'lodash/map'
import _filter from 'lodash/filter'
+import { TITLE_SUFFIX } from 'redux/constants'
export const loader = blogLoader
+export const meta: V2_MetaFunction = () => {
+ return [
+ {
+ title: `Blog ${TITLE_SUFFIX}`,
+ },
+ {
+ property: "og:title",
+ content: `Blog ${TITLE_SUFFIX}`,
+ },
+ ]
+}
+
export default function Posts() {
const posts: any[] = useLoaderData()