Compare commits

..

2 Commits

Author SHA1 Message Date
d939bfb989 Clean up code
All checks were successful
Build And Publish / BuildAndPublish (push) Successful in 2m38s
2024-09-23 20:45:42 +01:00
967ec9eb23 Add post 2024-09-23 20:39:55 +01:00
4 changed files with 1 additions and 291 deletions

View File

@ -1,5 +1,5 @@
export function createSlug(title: string) {
return title.toLowerCase()
.replace(/[\'\?]+/g, '')
.replace(/['?]+/g, '')
.replace(/[.,\s]+/g, '-')
}

View File

@ -1,54 +0,0 @@
import ReactDOMServer from 'react-dom/server'
import {Feed} from 'feed'
import {mkdir, writeFile} from 'fs/promises'
import {getAllArticles} from './getAllArticles'
export async function generateRssFeed() {
let articles = await getAllArticles()
let siteUrl = process.env.NEXT_PUBLIC_SITE_URL
let author = {
name: 'Ryan Freeman',
email: 'hello@ryanfreeman.dev',
}
let feed = new Feed({
title: author.name,
description: 'Hi. I\'m Ryan, a software engineer based in Dublin, Ireland. I\'m currently working in the aviation industry for Aer Lingus. I am passionate about personal growth and progressing in my career. This is my personal website where you can learn more about me, read articles Ive written and see projects I\'ve worked on.',
author,
id: siteUrl!,
link: siteUrl,
image: `${siteUrl}/favicon.ico`,
favicon: `${siteUrl}/favicon.ico`,
copyright: `All rights reserved ${new Date().getFullYear()}`,
feedLinks: {
rss2: `${siteUrl}/rss/feed.xml`,
json: `${siteUrl}/rss/feed.json`,
},
})
for (let article of articles) {
let url = `${siteUrl}/writing/${article.slug}`;
let html = ReactDOMServer.renderToStaticMarkup(
<article.component isRssFeed/>
)
feed.addItem({
title: article.title,
id: url,
link: url,
description: article.description,
content: html,
author: [author],
contributor: [author],
date: new Date(article.date),
})
}
await mkdir('./public/rss', {recursive: true})
await Promise.all([
writeFile('./public/rss/feed.xml', feed.rss2(), 'utf8'),
writeFile('./public/rss/feed.json', feed.json1(), 'utf8'),
])
}

View File

@ -15,73 +15,6 @@ type PinnedReposResponse = {
}
}
type TotalReposResponse = {
data: {
user: {
repositories: {
totalCount: number
}
}
}
}
type TotalFollowersResponse = {
data: {
user: {
followers: {
totalCount: number
}
}
}
}
type TotalStarsResponse = {
data: {
user: {
repositories: {
nodes: [
{
stargazers: {
totalCount: number
}
}
]
}
}
}
}
type TotalForksResponse = {
data: {
user: {
repositories: {
nodes: [
{
forks: {
totalCount: number
}
}
]
}
}
}
}
type TopRepoResponse = {
data: {
user: {
repositories: {
nodes: [
{
name: string
url: string
}
]
}
}
}
}
export async function getPinnedRepos() {
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
@ -113,127 +46,4 @@ export async function getPinnedRepos() {
}) as PinnedReposResponse
return response.data.user.pinnedItems.nodes
}
export async function getTotalRepos() {
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${GITHUB_ACCESS_TOKEN}`
},
body: JSON.stringify({
query: `{
user(login: "${GITHUB_USERNAME}") {
repositories {
totalCount
}
}
}`
})
}) as TotalReposResponse
return response.data.user.repositories.totalCount
}
export async function getTotalFollowers() {
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${GITHUB_ACCESS_TOKEN}`
},
body: JSON.stringify({
query: `{
user(login: "${GITHUB_USERNAME}") {
followers {
totalCount
}
}
}`
})
}) as TotalFollowersResponse
return response.data.user.followers.totalCount
}
export async function getTotalStars(totalRepos: number) {
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${GITHUB_ACCESS_TOKEN}`
},
body: JSON.stringify({
query: `{
user(login: "${GITHUB_USERNAME}") {
repositories(first: ${totalRepos}) {
nodes {
stargazers {
totalCount
}
}
}
}
}`
})
}) as TotalStarsResponse
return response.data.user.repositories.nodes
.reduce((acc, node) => acc + node.stargazers.totalCount, 0)
}
export async function getTotalForks(totalRepos: number) {
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${GITHUB_ACCESS_TOKEN}`
},
body: JSON.stringify({
query: `{
user(login: "${GITHUB_USERNAME}") {
repositories(first: ${totalRepos}) {
nodes {
forks {
totalCount
}
}
}
}
}`
})
}) as TotalForksResponse
return response.data.user.repositories.nodes
.reduce((acc, node) => acc + node.forks.totalCount, 0)
}
export async function getTopRepo() {
const response = await fetcher(GITHUB_GRAPHQL, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${GITHUB_ACCESS_TOKEN}`
},
body: JSON.stringify({
query: `{
user(login: "${GITHUB_USERNAME}") {
repositories(first: 1, orderBy: {field: STARGAZERS, direction: DESC}) {
nodes {
name
url
}
}
}
}`
})
}) as TopRepoResponse
const {name, url} = response.data.user.repositories.nodes[0]
return {
name,
url
}
}

View File

@ -6,7 +6,6 @@ const SPOTIFY_REFRESH_TOKEN = process.env.SPOTIFY_REFRESH_TOKEN
const SPOTIFY_TOKEN = "https://accounts.spotify.com/api/token"
const SPOTIFY_CURRENTLY_PLAYING = "https://api.spotify.com/v1/me/player/currently-playing"
const SPOTIFY_RECENTLY_PLAYED = "https://api.spotify.com/v1/me/player/recently-played"
const SPOTIFY_TOP_ARTISTS = "https://api.spotify.com/v1/me/top/artists"
const basic = Buffer.from(`${SPOTIFY_CLIENT_ID}:${SPOTIFY_CLIENT_SECRET}`).toString('base64')
@ -53,49 +52,4 @@ export const getRecentlyPlayed = async () => {
Authorization: `Bearer ${access_token}`
}
})
}
type TopArtistItem = {
name: string
uri: string
genres: string[]
}
type TopArtistsResponse = {
items: TopArtistItem[]
}
export const getTopArtist = async () => {
const {access_token}: Response = await getAccessToken() as Response
const response = await fetch(SPOTIFY_TOP_ARTISTS, {
headers: {
Authorization: `Bearer ${access_token}`
}
}).then(r => r.json()) as TopArtistsResponse
const artist = response.items[0].name
const uri = response.items[0].uri
return {
artist,
uri
}
}
export const getTopGenre = async () => {
const {access_token}: Response = await getAccessToken() as Response
const response = await fetch(SPOTIFY_TOP_ARTISTS, {
headers: {
Authorization: `Bearer ${access_token}`
}
}).then(r => r.json()) as TopArtistsResponse
let genre = response.items[0].genres[0]
genre = genre.charAt(0).toUpperCase() + genre.slice(1)
return {
genre
}
}