diff --git a/lib/generateRssFeed.tsx b/lib/generateRssFeed.tsx deleted file mode 100644 index 10342e0..0000000 --- a/lib/generateRssFeed.tsx +++ /dev/null @@ -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( - - ) - - 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'), - ]) -} diff --git a/lib/github.ts b/lib/github.ts index 6aeb1d1..34329df 100644 --- a/lib/github.ts +++ b/lib/github.ts @@ -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 - } } \ No newline at end of file diff --git a/lib/spotify.ts b/lib/spotify.ts index 43a0dc8..dbaa9b1 100644 --- a/lib/spotify.ts +++ b/lib/spotify.ts @@ -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 - } } \ No newline at end of file