Skip to content

Commit

Permalink
variables
Browse files Browse the repository at this point in the history
  • Loading branch information
dietrichmax committed Feb 14, 2024
1 parent 14e8254 commit 381de20
Show file tree
Hide file tree
Showing 13 changed files with 107 additions and 50 deletions.
18 changes: 9 additions & 9 deletions pages/_app.tsx
Expand Up @@ -35,23 +35,23 @@ export default function App({ Component, pageProps }: AppProps): ReactElement {
content="minimum-scale=1, initial-scale=1, width=device-width, shrink-to-fit=no, viewport-fit=cover"
/>
{/* DNS Prefetch*/}
<link rel="dns-prefetch" href="https://cms.mxd.codes" />
<link rel="dns-prefetch" href="https://geodaten.mxd.codes" />
<link rel="dns-prefetch" href="https://analytics.mxd.codes/" />
<link rel="dns-prefetch" href={process.env.NEXT_PUBLIC_STRAPI_API_URL} />
<link rel="dns-prefetch" href={process.env.NEXT_PUBLIC_MAPPROXY_URL} />
<link rel="dns-prefetch" href={process.env.NEXT_PUBLIC_MATOMO_URL} />
{/* Preconnect */}
<link rel="preconnect" href="https://cms.mxd.codes" />,
<link rel="preconnect" href="https://analytics.mxd.codes/" />
<link rel="preconnect" href={process.env.NEXT_PUBLIC_STRAPI_API_URL} />,
<link rel="preconnect" href={process.env.NEXT_PUBLIC_MATOMO_URL} />
{/* Preload */}
{/* IndieCert */}
<link rel="authorization_endpoint" href="https://indieauth.com/auth" />
<link rel="micropub" href="https://mxd.codes/micropub" />
<link rel="token_endpoint" href="https://mxd.codes/token" />
<link rel="micropub" href={`${config.siteUrl}/micropub`} />
<link rel="token_endpoint" href={`${config.siteUrl}/token"`} />
<link
rel="webmention"
href="https://webmention.io/mxd.codes/webmention"
href={`https://webmention.io/${config.siteTitleShort}/webmention`}
/>
,
<link rel="pingback" href="https://webmention.io/mxd.codes/xmlrpc" />,
<link rel="pingback" href={`https://webmention.io/${config.siteTitleShort}/xmlrpc`} />,
{/* Me */}
<link rel="me" href={config.socials.mail} />
<link rel="me" href={config.socials.github} />
Expand Down
23 changes: 23 additions & 0 deletions pages/api/cms.ts
@@ -0,0 +1,23 @@
import { fetchGET } from "@/src/utils/fetcher"
import type { NextApiRequest, NextApiResponse } from 'next'

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {

const recentPostsData = await fetchGET(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/posts?_sort=published_at:DESC&_limit=4`)
let recentPosts = []
recentPostsData.map((post) =>
recentPosts.push({
title: post.title,
slug: `/articles/${post.slug}`
})
)
const about = await fetchGET(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/about`)

res.status(200).json({
recentPosts,
about
})
}
8 changes: 7 additions & 1 deletion pages/api/stats.ts
Expand Up @@ -9,7 +9,10 @@ export default async function handler(
const liveViews = await fetchGET(
`${process.env.NEXT_PUBLIC_MATOMO_URL}?method=Live.getCounters&idSite=${process.env.NEXT_PUBLIC_MATOMO_SITE_ID}&lastMinutes=5&module=API&format=JSON&token_auth=${process.env.NEXT_PUBLIC_MATOMO_API_KEY}`
)
const thanks = await fetchGET(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/thanks`)


const subscriberCount = await fetchGET(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/subscribers/count`)
/*const overallPageViews = await fetchGET(
`${process.env.NEXT_PUBLIC_MATOMO_URL}?method=Actions.get&idSite=${
process.env.NEXT_PUBLIC_MATOMO_SITE_ID
Expand Down Expand Up @@ -102,6 +105,9 @@ export default async function handler(
biggestTrafficSource: biggestTrafficSource,
countryVisits: countryVisits,*/
},
cms: {},
cms: {
thanks: thanks.thanks,
subscriberCount: subscriberCount
},
})
}
28 changes: 28 additions & 0 deletions pages/api/subscribers.ts
@@ -0,0 +1,28 @@
import type { NextApiRequest, NextApiResponse } from 'next'

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {

console.log(req.body)
const requestOptions = {
method: "POST",
headers: req.headers,
body: req.body
}

fetch(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/subscribers`, requestOptions)
.then(function (response) {
if (!response.ok) {
res.status(500).json({response})
} else {
res.status(200).json({response})
}
})
.catch(function (error) {
console.log(error)
})


}
2 changes: 1 addition & 1 deletion pages/pay/index.tsx
@@ -1,4 +1,4 @@
import { useEffect, useState } from "react"
import { useState } from "react"
import Layout from "@/src/components/layout/layout"
import SEO from "@/src/components/seo/seo"
import media from "styled-media-query"
Expand Down
2 changes: 1 addition & 1 deletion pages/shop/index.tsx
Expand Up @@ -19,7 +19,7 @@ export default function Shop() {
id: 1,
name: "Cup",
description: "Personalize your cup",
image: "https://cms.mxd.codes/uploads/samantha_ram_Ha5_Jc_Y_Arf0_unsplash_7d627ef41c.jpg?",
image: `${process.env.NEXT_PUBLIC_STRAPI_API_URL}/uploads/samantha_ram_Ha5_Jc_Y_Arf0_unsplash_7d627ef41c.jpg?`,
colors: ["red", "blue"],
sizes: ["medium"],
ratings: [],
Expand Down
2 changes: 1 addition & 1 deletion pages/stats/index.tsx
Expand Up @@ -442,7 +442,7 @@ export default function Dashboard({

async function getMatomoLiveCounter() {
const res = await fetchGET("/api/stats")
res ? setLiveViews(res.analytics.currentVisitors.visitors) : setLiveViews(0)
setLiveViews(res.analytics.currentVisitors.visitors)
}

useEffect(() => {
Expand Down
13 changes: 7 additions & 6 deletions pages/support/index.tsx
Expand Up @@ -71,12 +71,13 @@ export default function Support({}) {
const [count, setThanks] = useState<number>(0)
const [submitted, setSubmitted] = useState<boolean>(false)

async function getThanks() {
const data = await fetchGET("/api/stats")
setThanks(data.cms.thanks)
}

useEffect(() => {
const fetchData = async () => {
const data = await fetchGET("https://cms.mxd.codes/thanks")
setThanks(data.thanks)
}
fetchData()
getThanks()
}, [])

const sendThanks = () => {
Expand All @@ -85,7 +86,7 @@ export default function Support({}) {
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ thanks: count + 1 }),
}
fetch("https://cms.mxd.codes/thanks", requestOptions)
fetch(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/thanks`, requestOptions)
.then(function (response) {
if (!response.ok) {
console.log(response.statusText)
Expand Down
13 changes: 7 additions & 6 deletions src/components/article/article-author/article-author.tsx
Expand Up @@ -82,12 +82,13 @@ export default function Author({ post }: Author) {

const { username, picture, bio } = post

async function getThanks() {
const data = await fetchGET("/api/stats")
setThanks(data.cms.thanks)
}

useEffect(() => {
const fetchData = async () => {
const data = await fetchGET("https://cms.mxd.codes/thanks")
setThanks(data.thanks)
}
fetchData()
getThanks()
}, [])

const sendThanks = () => {
Expand All @@ -96,7 +97,7 @@ export default function Author({ post }: Author) {
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ thanks: count + 1 }),
}
fetch("https://cms.mxd.codes/thanks", requestOptions)
fetch(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/thanks`, requestOptions)
.then(function (response) {
if (!response.ok) {
console.log(response.statusText)
Expand Down
24 changes: 10 additions & 14 deletions src/components/navigation/footer/footer.tsx
Expand Up @@ -141,20 +141,16 @@ export default function Footer() {
about: {},
})

useEffect(() => {
const fetchData = async () => {
const postsResult = await fetchGET(
"https://cms.mxd.codes/posts?_sort=published_at:DESC&_limit=4"
)
const aboutResult = await fetchGET("https://cms.mxd.codes/about")

setData({
recentPosts: postsResult,
about: aboutResult,
})
}
async function getRecentPosts() {
const data = await fetchGET("/api/cms")
setData({
recentPosts: data.recentPosts,
about: data.about
})
}

fetchData()
useEffect(() => {
getRecentPosts()
}, [])

const footerItems = [
Expand Down Expand Up @@ -280,7 +276,7 @@ export default function Footer() {
{data.recentPosts
? data.recentPosts.map((post, i) => (
<FooterItem key={i}>
<Link href={`/articles/${post.slug}`} title={post.title}>
<Link href={post.slug} title={post.title}>
{post.title}
</Link>
</FooterItem>
Expand Down
2 changes: 1 addition & 1 deletion src/components/seo/seo.tsx
Expand Up @@ -39,7 +39,7 @@ const SEO = ({

useEffect(() => {
const fetchCV = async () => {
const cv = await fetchGET("https://cms.mxd.codes/cv")
const cv = await fetchGET(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/cv`)
setData({
timeline: cv.timeline,
skills: cv.skills,
Expand Down
14 changes: 8 additions & 6 deletions src/components/social/newsletter/subscribe.tsx
Expand Up @@ -72,12 +72,14 @@ export default function Subscribe() {
const [count, setCount] = useState<number>(0)
const [submitted, setSubmitted] = useState<boolean>(false)


async function getSubscriberCount() {
const data = await fetchGET("/api/stats")
setCount(data.cms.subscriberCount)
}

useEffect(() => {
const getCount = async () => {
const data = await fetchGET("https://cms.mxd.codes/subscribers/count")
setCount(data)
}
getCount()
getSubscriberCount()
}, [])

const handleSubmit = () => {
Expand All @@ -87,7 +89,7 @@ export default function Subscribe() {
body: JSON.stringify({ email }),
}

fetch("https://cms.mxd.codes/subscribers", requestOptions)
fetch(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/subscribers`, requestOptions)
.then(function (response) {
if (!response.ok) {
console.log(response.statusText)
Expand Down
8 changes: 4 additions & 4 deletions src/components/social/webmentions/webmentions.tsx
Expand Up @@ -307,7 +307,7 @@ export default function Webmentions({ slug, preview }) {
"published": comment.published_at,
"author": {
name: comment.name || "anonym",
photo: "https://cms.mxd.codes/uploads/xmm8_553245a18b.jpg",
photo: `${process.env.NEXT_PUBLIC_STRAPI_API_URL}/uploads/xmm8_553245a18b.jpg`,
type: "card",
url: config.siteUrl,
},
Expand Down Expand Up @@ -336,7 +336,7 @@ export default function Webmentions({ slug, preview }) {
body: JSON.stringify(newComment),
}

fetch("https://cms.mxd.codes/comments", requestOptions)
fetch(`${process.env.NEXT_PUBLIC_STRAPI_API_URL}/comments`, requestOptions)
.then((response) => response.json())
.then((data) => {
setSentComment(true)
Expand All @@ -346,7 +346,7 @@ export default function Webmentions({ slug, preview }) {
"published": data.published_at,
"author": {
name: data.name || "anonym",
photo: "https://cms.mxd.codes/uploads/xmm8_553245a18b.jpg",
photo: `${process.env.NEXT_PUBLIC_STRAPI_API_URL}/uploads/xmm8_553245a18b.jpg`,
type: "card",
url: config.siteUrl,
},
Expand Down Expand Up @@ -388,7 +388,7 @@ export default function Webmentions({ slug, preview }) {
src={
mention.author.photo
? mention.author.photo
: "https://cms.mxd.codes/uploads/xmm8_553245a18b.jpg"
: `${process.env.NEXT_PUBLIC_STRAPI_API_URL}/uploads/xmm8_553245a18b.jpg`
}
height="50"
width="50"
Expand Down

0 comments on commit 381de20

Please sign in to comment.