Skip to content

Commit

Permalink
data quality improvement
Browse files Browse the repository at this point in the history
  • Loading branch information
dietrichmax committed Feb 23, 2024
1 parent 34553f5 commit 5c4fe33
Show file tree
Hide file tree
Showing 11 changed files with 78 additions and 17 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -36,6 +36,7 @@
"react-dom": "^18.2.0",
"react-router-dom": "^6.21.3",
"showdown": "^2.1.0",
"strava-v3": "^2.2.0",
"styled-components": "^6.1.8",
"styled-media-query": "^2.1.2"
},
Expand Down
15 changes: 15 additions & 0 deletions pages/api/strava.ts
@@ -0,0 +1,15 @@
import { fetchGET } from "@/src/utils/fetcher"
import type { NextApiRequest, NextApiResponse } from "next"
import * as qs from "qs"
import { getStravaData } from "@/src/data/external/strava"

export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const data = await getStravaData()

res.status(200).json({
strava: "test",
})
}
2 changes: 1 addition & 1 deletion pages/sitemap.xml.ts
Expand Up @@ -4,7 +4,7 @@ import {
getAllPages,
getAllPhotos,
getAllLinks,
getAllTags
getAllTags,
} from "@/src/data/external/cms"
import { config } from "@/src/data/internal/SiteConfig"
import * as fs from "fs"
Expand Down
2 changes: 1 addition & 1 deletion src/components/post/post-meta/post-meta-preview.jsx
Expand Up @@ -47,7 +47,7 @@ export default function PostMeta({ post, slug }) {
className="u-url"
rel="bookmark"
>
<time className="dt-published" dateTime={post.updated_at}>
<time className="dt-published" dateTime={post.updatedAt}>
{postDate.toLocaleDateString("en-US", dateOptions)}
</time>
</DateWrapper>
Expand Down
5 changes: 4 additions & 1 deletion src/components/post/post-meta/post-meta.jsx
Expand Up @@ -49,13 +49,16 @@ export default function PostMeta({ post, slug, syndicationLinks }) {

const dateOptions = { year: "numeric", month: "long", day: "numeric" }

//console.log(post)
return (
<Meta>
<DateWrapper className="dt-published">
First published{" "}
<a className="u-url" title={slug} href={slug}>
{new Date(
post.published_at ? post.published_at : post.published_at
post.attributes.publishedAt
? post.attributes.publishedAt
: post.attributes.createdAt
).toLocaleDateString("en-US", dateOptions)}
</a>
</DateWrapper>
Expand Down
10 changes: 7 additions & 3 deletions src/components/social/webmentions/webmentions.tsx
Expand Up @@ -321,8 +321,12 @@ export default function Webmentions({ slug, preview }) {
"url": `${url}#${comment.id}`,
"published": comment.attributes.publishedAt,
"author": {
name: comment.attributes.users_permissions_user.data ? comment.attributes.users_permissions_user.data.attributes.username : comment.attributes.name || "anonym",
photo: comment.attributes.users_permissions_user.data ? "/images/IMG_20231229_WA_0005_1925a8f37e50x50.webp" : `${process.env.NEXT_PUBLIC_STRAPI_API_URL}/uploads/mm_b619c41da0_990e14278f.jpg`,
name: comment.attributes.users_permissions_user.data
? comment.attributes.users_permissions_user.data.attributes.username
: comment.attributes.name || "anonym",
photo: comment.attributes.users_permissions_user.data
? "/images/IMG_20231229_WA_0005_1925a8f37e50x50.webp"
: `${process.env.NEXT_PUBLIC_STRAPI_API_URL}/uploads/mm_b619c41da0_990e14278f.jpg`,
type: "card",
url: config.siteUrl,
},
Expand All @@ -334,7 +338,7 @@ export default function Webmentions({ slug, preview }) {
})
const allComments = comments.concat(strapiComments)
const sortedComments = allComments.sort(function (a, b) {
return new Date(a.createdAt) - new Date(b.createdAt)
return new Date(a.createdAt) - new Date(b.createdAt)
})
setComments(sortedComments)
}
Expand Down
28 changes: 25 additions & 3 deletions src/data/external/analytics.ts
@@ -1,4 +1,5 @@
import { fetchGET } from "@/src/utils/fetcher"
import { config } from "../internal/SiteConfig"

export async function getMatomoActions() {
const actions = await fetchGET(
Expand Down Expand Up @@ -117,22 +118,43 @@ export async function getMatomoSEOStats() {
}

export async function getMatomoTopPageUrls() {
let topPages = []
const pageUrl = await fetchGET(
`${
process.env.NEXT_PUBLIC_MATOMO_URL
}?module=API&method=Actions.getPageUrls&segment=pageUrl=@/articles/&flat=1&idSite=${
}?module=API&method=Actions.getPageUrls&flat=1&filter_column=label&filter_pattern=%5E%2Farticles%2F&idSite=${
process.env.NEXT_PUBLIC_MATOMO_SITE_ID
}&period=range&date=2018-02-01,${new Date()
.toISOString()
.slice(0, 10)}&format=JSON&filter_limit=5&token_auth=${
.slice(0, 10)}&filter_limit=-1&format=JSON&token_auth=${
process.env.NEXT_PUBLIC_MATOMO_API_KEY
}`
)
if (pageUrl.errors) {
console.error(pageUrl.errors)
throw new Error("Failed to fetch pageUrl")
} else {
pageUrl.map((page) => {
if (page.url != undefined) {
if (!page.url.includes("?")) {
topPages.push({
label: page.label,
nb_hits: page.nb_hits,
})
} else {
const uniquePage = page.url.split("?")[0].replace(config.siteUrl, "")
const topPagesIndex = topPages.findIndex(
(obj) => obj.label === uniquePage
)
topPages[topPagesIndex].nb_hits += page.nb_hits
}
}
})
}
return pageUrl
const sortedTopPages = topPages.sort((a, b) => b.nb_hits - a.nb_hits)
const slicedSortedTopPages = sortedTopPages.slice(0, 7)

return slicedSortedTopPages
}

export async function getMatomoViewForPage(url) {
Expand Down
3 changes: 2 additions & 1 deletion src/data/external/cms.ts
Expand Up @@ -137,6 +137,7 @@ export async function getPostBySlug(slug: string) {
"description",
"updatedAt",
"createdAt",
"publishedAt",
"content",
],
},
Expand Down Expand Up @@ -341,4 +342,4 @@ export async function getAllSubscribers() {
"subscribers"
)
return data
}
}
23 changes: 20 additions & 3 deletions src/data/external/strava.ts
@@ -1,4 +1,21 @@
export async function fetchStravaAPI(query: string, { variables } = {}) {
import strava from "strava-v3"

strava.config({
access_token: process.env.STRAVA_ACCESS_TOKEN, //"Your apps access token (Required for Quickstart)",
client_id: process.env.STRAVA_CLIENT_ID, //"Your apps Client ID (Required for oauth)",
client_secret: process.env.STRAVA_CLIENT_SECRET, //"Your apps Client Secret (Required for oauth)",
redirect_uri: process.env.STRAVA_REDIRECT_URI, //"Your apps Authorization Redirection URI (Required for oauth)",
})

export async function getStravaData() {
const payload = await strava.athlete.listActivities({
access_token: process.env.STRAVA_ACCESS_TOKEN,
})
console.log(payload)
return payload
}

/*export async function fetchStravaAPI(query: string, { constiables } = {}) {
const res = await fetch(`https://www.strava.com/api/v3/`, {
method: "GET",
headers: {
Expand All @@ -8,7 +25,7 @@ export async function fetchStravaAPI(query: string, { variables } = {}) {
cache: "force-cache",
body: JSON.stringify({
query,
variables,
constiables,
}),
})
Expand All @@ -19,4 +36,4 @@ export async function fetchStravaAPI(query: string, { variables } = {}) {
}
return json.data
}
}*/
3 changes: 1 addition & 2 deletions src/utils/getToc.ts
Expand Up @@ -14,12 +14,11 @@ export function getToc(markdown: string) {
const toc = []
let globalID = 0


if (titles) {
titles.map((tempTitle) => {
const level = tempTitle.match(/#/g).length - 1
const title = tempTitle.replace(/#/g, "")
const anchor = `#${title.replace(/ /g, "-").replaceAll(":","").replaceAll(",","").substring(1).toLowerCase()}`
const anchor = `#${title.replace(/ /g, "-").replaceAll(":", "").replaceAll(",", "").substring(1).toLowerCase()}`
level === 1 ? (globalID += 1) : globalID

toc.push({
Expand Down
3 changes: 1 addition & 2 deletions src/utils/renderers.tsx
Expand Up @@ -78,8 +78,7 @@ const MarkdownImage = ({ src }) => {
const filteredSrc = src.replace(process.env.NEXT_PUBLIC_STRAPI_API_URL, "")

const getData = async () => {
const query =
{
const query = {
filters: {
url: {
$containsi: filteredSrc,
Expand Down

0 comments on commit 5c4fe33

Please sign in to comment.