📈 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
Move SEO stuff to utility functions
Blue Mouse95560e039c39
diff --git a/web/app/routes/blog.$category.$slug.tsx b/web/app/routes/blog.$category.$slug.tsxindex 251ed7f2f..54384fcdc 100644--- a/web/app/routes/blog.$category.$slug.tsx+++ b/web/app/routes/blog.$category.$slug.tsx@@ -1,45 +1,18 @@import type { LoaderFunction, MetaFunction } from 'react-router'import { redirect, data } from 'react-router'-import { isSelfhosted, TITLE_SUFFIX, getOgImageUrl, isDisableMarketingPages } from '~/lib/constants'+import { isSelfhosted, getOgImageUrl, isDisableMarketingPages } from '~/lib/constants'import Post from '~/pages/Blog/Post'import { getPost } from '~/utils/getPosts'+import { getDescription, getPreviewImage, getTitle } from '~/utils/seo'export const meta: MetaFunction = (loaderData: any) => {const ogImageUrl = getOgImageUrl(loaderData?.data?.title)return [- {- title: `${loaderData?.data?.title || 'Blog'} ${TITLE_SUFFIX}`,- },- {- property: 'og:title',- content: `${loaderData?.data?.title || 'Blog'} ${TITLE_SUFFIX}`,- },- {- property: 'twitter: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 || '',- },- {- property: 'og:image',- content: ogImageUrl,- },- {- property: 'twitter:image',- content: ogImageUrl,- },+ ...getTitle(loaderData?.data?.title || 'Blog'),+ ...getDescription(loaderData?.data?.intro || ''),+ ...getPreviewImage(ogImageUrl),]}diff --git a/web/app/routes/blog.$slug.tsx b/web/app/routes/blog.$slug.tsxindex bc99dbd4b..ff5a5a7b7 100644--- a/web/app/routes/blog.$slug.tsx+++ b/web/app/routes/blog.$slug.tsx@@ -7,45 +7,18 @@ import type { LoaderFunction, MetaFunction } from 'react-router'import type { SitemapFunction } from 'remix-sitemap'import { getSitemap } from '~/api'-import { isSelfhosted, TITLE_SUFFIX, getOgImageUrl, isDisableMarketingPages } from '~/lib/constants'+import { isSelfhosted, getOgImageUrl, isDisableMarketingPages } from '~/lib/constants'import Post from '~/pages/Blog/Post'import { getPost, getSlugFromFilename, getDateFromFilename } from '~/utils/getPosts'+import { getDescription, getPreviewImage, getTitle } from '~/utils/seo'export const meta: MetaFunction = (loaderData: any) => {const ogImageUrl = getOgImageUrl(loaderData?.data?.title)return [- {- title: `${loaderData?.data?.title || 'Blog'} ${TITLE_SUFFIX}`,- },- {- property: 'og:title',- content: `${loaderData?.data?.title || 'Blog'} ${TITLE_SUFFIX}`,- },- {- property: 'twitter: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 || '',- },- {- property: 'og:image',- content: ogImageUrl,- },- {- property: 'twitter:image',- content: ogImageUrl,- },+ ...getTitle(loaderData?.data?.title || 'Blog'),+ ...getDescription(loaderData?.data?.intro || ''),+ ...getPreviewImage(ogImageUrl),]}diff --git a/web/app/routes/blog._index.tsx b/web/app/routes/blog._index.tsxindex 45deccdb1..8369120a6 100644--- a/web/app/routes/blog._index.tsx+++ b/web/app/routes/blog._index.tsx@@ -5,7 +5,8 @@ import type { LoaderFunction, MetaFunction } from 'react-router'import { redirect, Link, useLoaderData } from 'react-router'import { getBlogPosts } from '~/api'-import { isDisableMarketingPages, isSelfhosted, TITLE_SUFFIX } from '~/lib/constants'+import { isDisableMarketingPages, isSelfhosted } from '~/lib/constants'+import { getTitle } from '~/utils/seo'export const loader: LoaderFunction = async () => {if (isSelfhosted || isDisableMarketingPages) {@@ -28,19 +29,7 @@ export const loader: LoaderFunction = async () => {}export const meta: MetaFunction = () => {- return [- {- title: `Blog ${TITLE_SUFFIX}`,- },- {- property: 'og:title',- content: `Blog ${TITLE_SUFFIX}`,- },- {- property: 'twitter:title',- content: `Blog ${TITLE_SUFFIX}`,- },- ]+ return [...getTitle('Blog')]}export default function Posts() {diff --git a/web/app/utils/seo.ts b/web/app/utils/seo.tsnew file mode 100644index 000000000..7765e1d6c--- /dev/null+++ b/web/app/utils/seo.ts@@ -0,0 +1,41 @@+import { TITLE_SUFFIX } from '~/lib/constants'++export const getTitle = (title: string) => [+ {+ title: `${title} ${TITLE_SUFFIX}`,+ },+ {+ property: 'og:title',+ content: `${title} ${TITLE_SUFFIX}`,+ },+ {+ property: 'twitter:title',+ content: `${title} ${TITLE_SUFFIX}`,+ },+]++export const getDescription = (description: string) => [+ {+ property: 'og:description',+ content: description,+ },+ {+ property: 'twitter:description',+ content: description,+ },+ {+ property: 'description',+ content: description,+ },+]++export const getPreviewImage = (imageUrl: string) => [+ {+ property: 'og:image',+ content: imageUrl,+ },+ {+ property: 'twitter:image',+ content: imageUrl,+ },+]