feat: refactor posts; add recipes

This commit is contained in:
Aaron Yarborough 2024-03-13 16:28:19 +00:00
parent 1dd348a191
commit c931533b9e
11 changed files with 120 additions and 152 deletions

View file

@ -1,9 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9" xmlns:news="http://www.google.com/schemas/sitemap-news/0.9" xmlns:xhtml="http://www.w3.org/1999/xhtml" xmlns:mobile="http://www.google.com/schemas/sitemap-mobile/1.0" xmlns:image="http://www.google.com/schemas/sitemap-image/1.1" xmlns:video="http://www.google.com/schemas/sitemap-video/1.1">
<url><loc>https://www.aaronjy.me/</loc><lastmod>2024-03-13T12:46:49.416Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/cv/</loc><lastmod>2024-03-13T12:46:49.417Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/fun/</loc><lastmod>2024-03-13T12:46:49.417Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/writing/</loc><lastmod>2024-03-13T12:46:49.417Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/fun/javascript-html5-tile-editor/</loc><lastmod>2024-03-13T12:46:49.417Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/writing/static-site-on-google-cloud/</loc><lastmod>2024-03-13T12:46:49.417Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/</loc><lastmod>2024-03-13T16:28:02.820Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/cv/</loc><lastmod>2024-03-13T16:28:02.821Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/fun/</loc><lastmod>2024-03-13T16:28:02.821Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/recipes/</loc><lastmod>2024-03-13T16:28:02.821Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/writing/</loc><lastmod>2024-03-13T16:28:02.821Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/recipes/manakish-pan/</loc><lastmod>2024-03-13T16:28:02.821Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/fun/javascript-html5-tile-editor/</loc><lastmod>2024-03-13T16:28:02.821Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
<url><loc>https://www.aaronjy.me/writing/static-site-on-google-cloud/</loc><lastmod>2024-03-13T16:28:02.821Z</lastmod><changefreq>daily</changefreq><priority>0.7</priority></url>
</urlset>

View file

@ -9,8 +9,9 @@ function Header () {
<nav>
<Link href='/'>Home</Link>
<Link href='/writing'>Writing</Link>
<Link href='/cv'>CV</Link>
<Link href='/recipes'>Recipes</Link>
<Link href='/fun'>Fun</Link>
<Link href='/cv'>CV</Link>
</nav>
</header>
)

View file

@ -4,7 +4,7 @@ import style from './DefaultLayout.module.css'
import Header from '@/components/Header/Header'
import Footer from '@/components/Footer/Footer'
import { Fira_Sans as FiraSans} from 'next/font/google'
import { Fira_Sans as FiraSans } from 'next/font/google'
const fontMain = FiraSans({ subsets: ['latin'], weight: ['400', '600'] })

View file

@ -21,3 +21,35 @@ export function getMarkdownEntry (path) {
slug
}
}
export function getStaticEntryPaths(contentPath) {
const entries = fs.readdirSync(contentPath, { withFileTypes: true })
const paths = entries.map((dirent) => ({
params: {
slug: toSlug(dirent.name),
contentPath: ';test'
}
}))
return {
fallback: false,
paths
}
}
export function getStaticEntryProps(contentPath, { params }) {
const path = `${contentPath}/${params.slug}.md`
const entry = getMarkdownEntry(path)
return { props: { ...entry } }
}
export function getStaticEntryListProps(contentPath, urlPrefix) {
const fun = fs.readdirSync(contentPath, { withFileTypes: true })
const entries = fun.map((dirent) =>
getMarkdownEntry(`${dirent.path}/${dirent.name}`)
)
return { props: { entries, urlPrefix } }
}

View file

@ -1,38 +1,17 @@
import { toSlug } from '@/lib/helpers'
import React from 'react'
import fs from 'fs'
import DefaultLayout from '@/layouts/DefaultLayout/DefaultLayout'
import { getMarkdownEntry } from '@/lib/content'
import Article from '@/components/Article/Article'
import { getStaticEntryPaths, getStaticEntryProps } from '@/lib/content'
function FunSingle ({ attributes, html }) {
const CONTENT_PATH = "./content/fun"
export const getStaticPaths = () => getStaticEntryPaths(CONTENT_PATH)
export const getStaticProps = (ctx) => getStaticEntryProps(CONTENT_PATH, ctx)
export default function FunSingle ({ attributes, html }) {
return (
<DefaultLayout>
<Article attributes={attributes} html={html} />
</DefaultLayout>
)
}
export function getStaticPaths () {
const fun = fs.readdirSync('./content/fun', { withFileTypes: true })
const paths = fun.map((dirent) => ({
params: {
slug: toSlug(dirent.name)
}
}))
return {
fallback: false,
paths
}
}
export function getStaticProps ({ params }) {
const path = `./content/fun/${params.slug}.md`
const entry = getMarkdownEntry(path)
return { props: { ...entry } }
}
export default FunSingle

View file

@ -1,11 +1,11 @@
import DefaultLayout from '@/layouts/DefaultLayout/DefaultLayout'
import React from 'react'
import fs from 'fs'
import Grid from '@/components/Grid/Grid'
import Link from 'next/link'
import { getMarkdownEntry } from '@/lib/content'
import { getStaticEntryListProps } from '@/lib/content'
function Fun ({ entries }) {
export const getStaticProps = () => getStaticEntryListProps("./content/fun", "/fun/")
export default function Fun ({ entries, urlPrefix }) {
return (
<DefaultLayout>
<section>
@ -14,28 +14,16 @@ function Fun ({ entries }) {
</section>
<section>
<Grid>
{entries.map((e) => (
<div key={e.attributes.title}>
<h2><Link href={'/fun/' + e.slug}>{e.attributes.title}</Link></h2>
<p>{e.attributes.desc}</p>
<Link href={'/fun/' + e.slug}>Read more</Link>
</div>
))}
</Grid>
{entries.map((e) => (
<div key={e.attributes.title}>
<h2>
<Link href={`${urlPrefix}${e.slug}`}>{e.attributes.title}</Link>
</h2>
<p>{e.attributes.desc}</p>
<Link href={`${urlPrefix}${e.slug}`}>Read more</Link>
</div>
))}
</section>
</DefaultLayout>
)
}
export function getStaticProps () {
const fun = fs.readdirSync('./content/fun', { withFileTypes: true })
const entries = fun.map((dirent) =>
getMarkdownEntry(`${dirent.path}/${dirent.name}`)
)
return { props: { entries } }
}
export default Fun

View file

@ -0,0 +1,17 @@
import React from 'react'
import DefaultLayout from '@/layouts/DefaultLayout/DefaultLayout'
import Article from '@/components/Article/Article'
import { getStaticEntryPaths, getStaticEntryProps } from '@/lib/content'
const CONTENT_PATH = "./content/recipes"
export const getStaticPaths = () => getStaticEntryPaths(CONTENT_PATH)
export const getStaticProps = (ctx) => getStaticEntryProps(CONTENT_PATH, ctx)
export default function RecipesSingle ({ attributes, html }) {
return (
<DefaultLayout>
<Article attributes={attributes} html={html} />
</DefaultLayout>
)
}

View file

@ -0,0 +1,29 @@
import DefaultLayout from '@/layouts/DefaultLayout/DefaultLayout'
import React from 'react'
import Link from 'next/link'
import { getStaticEntryListProps } from '@/lib/content'
export const getStaticProps = () => getStaticEntryListProps("./content/recipes", "/recipes/")
export default function Recipes ({ entries, urlPrefix }) {
return (
<DefaultLayout>
<section>
<h1>Recipes</h1>
<p>Some of my favourite recipes. Most of them are variations of recipes I have found online, but some I&apos;ve cooked up myself!</p>
</section>
<section>
{entries.map((e) => (
<div key={e.attributes.title}>
<h2>
<Link href={`${urlPrefix}${e.slug}`}>{e.attributes.title}</Link>
</h2>
<p>{e.attributes.desc}</p>
<Link href={`${urlPrefix}${e.slug}`}>Read more</Link>
</div>
))}
</section>
</DefaultLayout>
)
}

View file

@ -1,46 +0,0 @@
// import Grid from '@/components/Grid/Grid'
// import DefaultLayout from '@/layouts/DefaultLayout/DefaultLayout'
// import React from 'react'
// import path from 'path'
// import fs from 'fs'
// function Recipes ({ recipes }) {
// return (
// <DefaultLayout>
// <section>
// <h1>Recipes</h1>
// <Grid>
// {recipes.length &&
// recipes.map((recipe) => (
// <div key={recipe.name}>{recipe.name ?? 'unknown'}</div>
// ))}
// </Grid>
// </section>
// </DefaultLayout>
// )
// }
// export default Recipes
// export async function getStaticProps () {
// const recipeDirents = await fs.promises
// .readdir('./content/recipes', {
// recursive: false,
// withFileTypes: true
// })
// const recipes = [{
// name: 'lol'
// }]
// for (const recipe of recipeDirents) {
// // const recipePath = path.join('./', recipe.path, recipe.name)
// // const recipeContent = fs.readFileSync(recipePath, { encoding: 'utf-8' })
// console.log(recipeFm)
// }
// return {
// props: { recipes }
// }
// }

View file

@ -1,38 +1,15 @@
import { toSlug } from '@/lib/helpers'
import React from 'react'
import fs from 'fs'
import DefaultLayout from '@/layouts/DefaultLayout/DefaultLayout'
import { getMarkdownEntry } from '@/lib/content'
import { getStaticEntryPaths, getStaticEntryProps } from '@/lib/content'
import Article from '@/components/Article/Article'
function FunSingle ({ attributes, html }) {
export const getStaticPaths = () => getStaticEntryPaths("./content/writing")
export const getStaticProps = (ctx) => getStaticEntryProps("./content/writing", ctx)
export default function WritingSingle ({ attributes, html }) {
return (
<DefaultLayout>
<Article attributes={attributes} html={html} />
</DefaultLayout>
)
}
export function getStaticPaths () {
const fun = fs.readdirSync('./content/writing', { withFileTypes: true })
const paths = fun.map((dirent) => ({
params: {
slug: toSlug(dirent.name)
}
}))
return {
fallback: false,
paths
}
}
export function getStaticProps ({ params }) {
const path = `./content/writing/${params.slug}.md`
const entry = getMarkdownEntry(path)
return { props: { ...entry } }
}
export default FunSingle

View file

@ -1,10 +1,11 @@
import DefaultLayout from '@/layouts/DefaultLayout/DefaultLayout'
import React from 'react'
import fs from 'fs'
import Link from 'next/link'
import { getMarkdownEntry } from '@/lib/content'
import { getStaticEntryListProps } from '@/lib/content'
function Fun ({ entries }) {
export const getStaticProps = () => getStaticEntryListProps("./content/writing", "/writing/")
export default function Writing ({ entries, urlPrefix }) {
return (
<DefaultLayout>
<section>
@ -19,25 +20,13 @@ function Fun ({ entries }) {
{entries.map((e) => (
<div key={e.attributes.title}>
<h2>
<Link href={'/writing/' + e.slug}>{e.attributes.title}</Link>
<Link href={`${urlPrefix}${e.slug}`}>{e.attributes.title}</Link>
</h2>
<p>{e.attributes.desc}</p>
<Link href={'/writing/' + e.slug}>Read more</Link>
<Link href={`${urlPrefix}${e.slug}`}>Read more</Link>
</div>
))}
</section>
</DefaultLayout>
)
}
export function getStaticProps () {
const fun = fs.readdirSync('./content/writing', { withFileTypes: true })
const entries = fun.map((dirent) =>
getMarkdownEntry(`${dirent.path}/${dirent.name}`)
)
return { props: { entries } }
}
export default Fun