Skip to content

Commit

Permalink
Added type definitons to functions
Browse files Browse the repository at this point in the history
  • Loading branch information
maxpetretta committed Sep 16, 2022
1 parent 1e06fea commit d9cf5f1
Show file tree
Hide file tree
Showing 12 changed files with 101 additions and 86 deletions.
2 changes: 1 addition & 1 deletion components/Accordion.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default function Accordion({ job }) {
dangerouslySetInnerHTML={{ __html: job.description }}
/>
<ul className="grid grid-cols-3 xs:m-2 md:w-1/3 md:grid-cols-1 md:grid-rows-3">
{job.skills.map((skill) => {
{job.skills.map((skill: string) => {
return (
<li className=" md:ml-6" key={skill}>
<Badge logo={skill} />
Expand Down
2 changes: 1 addition & 1 deletion components/Heading.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export default function Heading({ tag, children }) {
)
}

function getAnchor(text) {
function getAnchor(text: string): string {
return text
.toLowerCase()
.replace(/[^a-z0-9 ]/g, "")
Expand Down
3 changes: 2 additions & 1 deletion components/Post.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { Post as PostType } from "../lib/types"
import Layout from "./Layout"
import PostCard from "./PostCard"
import Title from "./Title"
Expand Down Expand Up @@ -32,7 +33,7 @@ export default function Post({ meta, children }) {
)
}

export function getPostBySlug(slug) {
export function getPostBySlug(slug: string): PostType {
const post = require(`../pages/blog/${slug}.mdx`)

return {
Expand Down
2 changes: 1 addition & 1 deletion components/Title.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ export default function Title({ meta }) {
})}
</time>
<div className="flex">
{meta.tags.map((tag) => {
{meta.tags.map((tag: string) => {
return (
<span className="chip my-1 first:ml-0" key={tag}>
{tag}
Expand Down
3 changes: 2 additions & 1 deletion lib/jobs.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from "fs"
import path from "path"
import { Job } from "./types"

const dataDirectory = path.join(process.cwd(), "/public/data")

export function getJobs() {
export function getJobs(): Job[] {
const file = fs.readFileSync(dataDirectory + "/jobs.json").toString()
const jobs = JSON.parse(file)

Expand Down
5 changes: 3 additions & 2 deletions lib/posts.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import fs from "fs"
import path from "path"
import { Post } from "./types"

const postDirectory = path.join(process.cwd(), "/pages/blog")

export function getAllPosts() {
export function getAllPosts(): Post[] {
const files = fs.readdirSync(postDirectory)
const posts = files.map((file) => {
const post = require(`../pages/blog/${file}`)
Expand All @@ -13,6 +14,6 @@ export function getAllPosts() {
...post.meta,
}
})

console.log(posts)
return posts
}
23 changes: 23 additions & 0 deletions lib/types.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
export type Job = {
id: number
company: string
title: string
startDate: string
endDate: string
location: string
image: string
skills: string[]
description: string
}

export type Post = {
slug: string
title: string
description: string
date: string
tags: string[]
image: string
alt: string
icon: string
related: string
}
131 changes: 59 additions & 72 deletions pages/_document.tsx
Original file line number Diff line number Diff line change
@@ -1,75 +1,62 @@
import Document, { Head, Html, Main, NextScript } from "next/document"
import { Head, Html, Main, NextScript } from "next/document"
import Script from "next/script"

class MyDocument extends Document {
static async getInitialProps(ctx) {
const initialProps = await Document.getInitialProps(ctx)
return { ...initialProps }
}

render() {
return (
<Html lang="en">
<Head>
{/* Favicons */}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicons/favicon-16x16.png"
/>
<link rel="manifest" href="/favicons/site.webmanifest" />
<link
rel="mask-icon"
href="/favicons/safari-pinned-tab.svg"
color="#4361a2"
/>
<meta name="msapplication-TileColor" content="#c73156" />
<meta name="theme-color" content="#111827" />
{/* Preconnects */}
<link rel="preconnect" href="https://vitals.vercel-insights.com" />
<link rel="preconnect" href="https://www.googletagmanager.com" />
<link rel="preconnect" href="https://www.google-analytics.com" />
</Head>
<body>
<Main />
<NextScript />
<Script
src="/scripts/fade-in.js"
type="module"
strategy="beforeInteractive"
/>
<Script src="/scripts/update-selector.js" />
<Script src="/scripts/smoothscroll.min.js" />
<Script src="/scripts/smoothscroll-anchor.min.js" />
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`}
/>
<Script id="gtag">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', {
page_path: window.location.pathname,
});
`}
</Script>
</body>
</Html>
)
}
export default function Document() {
return (
<Html lang="en">
<Head>
{/* Favicons */}
<link
rel="apple-touch-icon"
sizes="180x180"
href="/favicons/apple-touch-icon.png"
/>
<link
rel="icon"
type="image/png"
sizes="32x32"
href="/favicons/favicon-32x32.png"
/>
<link
rel="icon"
type="image/png"
sizes="16x16"
href="/favicons/favicon-16x16.png"
/>
<link rel="manifest" href="/favicons/site.webmanifest" />
<link
rel="mask-icon"
href="/favicons/safari-pinned-tab.svg"
color="#4361a2"
/>
<meta name="msapplication-TileColor" content="#c73156" />
<meta name="theme-color" content="#111827" />
{/* Preconnects */}
<link rel="preconnect" href="https://vitals.vercel-insights.com" />
<link rel="preconnect" href="https://www.googletagmanager.com" />
<link rel="preconnect" href="https://www.google-analytics.com" />
</Head>
<body>
<Main />
<NextScript />
<Script src="/scripts/fade-in.js" strategy="beforeInteractive" />
<Script src="/scripts/update-selector.js" />
<Script src="/scripts/smoothscroll.min.js" />
<Script src="/scripts/smoothscroll-anchor.min.js" />
<Script
src={`https://www.googletagmanager.com/gtag/js?id=${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}`}
/>
<Script id="gtag">
{`
window.dataLayer = window.dataLayer || [];
function gtag(){dataLayer.push(arguments);}
gtag('js', new Date());
gtag('config', '${process.env.NEXT_PUBLIC_GOOGLE_ANALYTICS}', {
page_path: window.location.pathname,
});
`}
</Script>
</body>
</Html>
)
}

export default MyDocument
7 changes: 4 additions & 3 deletions pages/blog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import Entry from "../components/Entry"
import Layout from "../components/Layout"
import PostCard from "../components/PostCard"
import { getAllPosts } from "../lib/posts"
import { Post } from "../lib/types"

export default function Blog({ posts, postCount, postsByYear, years }) {
return (
Expand All @@ -24,13 +25,13 @@ export default function Blog({ posts, postCount, postsByYear, years }) {
})}
</div>
</section>
{years.map((year) => {
{years.map((year: string) => {
return (
<section key={year}>
<h2 className="mb-0">{year}</h2>
<hr className="mt-2 mb-8 md:mt-3 md:mb-10" />
<ul className="list">
{postsByYear[year].map((post) => {
{postsByYear[year].map((post: Post) => {
return <Entry key={post.slug} post={post} />
})}
</ul>
Expand Down Expand Up @@ -60,7 +61,7 @@ export const getStaticProps: GetStaticProps = async () => {
}
}

export function getFeaturedPosts(posts) {
export function getFeaturedPosts(posts: Post[]): Post[] {
const featured = ["twitt3r", "tech-stack"]

const sorted = posts
Expand Down
5 changes: 3 additions & 2 deletions pages/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import Badge from "../components/Badge"
import Layout from "../components/Layout"
import SkillCard from "../components/SkillCard"
import { getJobs } from "../lib/jobs"
import { Job } from "../lib/types"

export default function Home({ jobs }) {
return (
Expand Down Expand Up @@ -168,8 +169,8 @@ export default function Home({ jobs }) {
<p className="mt-14">Languages I know:</p>
<ul className="fade grid grid-cols-3 md:grid-cols-4 md:gap-2">
{[
"Solidity",
"TypeScript",
"Solidity",
"Python",
"Terraform",
"Java",
Expand Down Expand Up @@ -215,7 +216,7 @@ export default function Home({ jobs }) {
</h2>
<hr className="mt-2 mb-8 md:mt-3 md:mb-10" />
<ul className="list">
{jobs.map((job) => {
{jobs.map((job: Job) => {
return <Accordion key={job.title} job={job} />
})}
</ul>
Expand Down
2 changes: 1 addition & 1 deletion public/scripts/fade-in.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export async function fadeIn() {
async function fadeIn() {
const entries = document.querySelectorAll(".fade, .animate-fade-in")
const options = {
root: null,
Expand Down
2 changes: 1 addition & 1 deletion public/scripts/update-selector.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export async function updateSelector() {
async function updateSelector() {
const classes = [
"translate-x-0",
"translate-x-full",
Expand Down

0 comments on commit d9cf5f1

Please sign in to comment.