Skip to content

Commit

Permalink
Refactored pagination, added tags and filters and initial fetching of…
Browse files Browse the repository at this point in the history
… file list from github
  • Loading branch information
Ex-iT committed Jan 6, 2025
1 parent b206a90 commit 528c51d
Show file tree
Hide file tree
Showing 32 changed files with 509 additions and 404 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,8 @@ Run code linters:
```bash
pnpm lint
```

## Attribution

- Icons: [Material Symbols by Google](https://icon-sets.iconify.design/material-symbols/)
- Astro template / theme [Astro Blur](https://github.com/Jazee6/astro-blur)
3 changes: 0 additions & 3 deletions astro.config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,8 @@ import mdx from '@astrojs/mdx'
import sitemap from '@astrojs/sitemap'
import tailwind from '@astrojs/tailwind'
import icon from 'astro-icon'
import { remarkModifiedTime } from './src/utils/remark-modified-time'
import { siteConfig } from './src/config'

// https://astro.build/config
export default defineConfig({
site: siteConfig.site,
server: { port: 3000 },
Expand All @@ -27,7 +25,6 @@ export default defineConfig({
dark: 'dracula',
},
},
remarkPlugins: [remarkModifiedTime],
},
devToolbar: {
enabled: false,
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "ex-it.nl",
"type": "module",
"version": "0.4.0",
"version": "0.1.0",
"license": "UNLICENSED",
"scripts": {
"dev": "ASTRO_TELEMETRY_DISABLED=1 astro dev",
Expand All @@ -10,7 +10,7 @@
"postbuild": "pagefind --site dist",
"preview": "astro preview",
"astro": "astro",
"lint": "pnpm run lint:prettier && pnpm run lint:typescript",
"lint": "astro check && pnpm run lint:prettier && pnpm run lint:typescript",
"lint:prettier": "prettier --check .",
"lint:typescript": "tsc --noEmit"
},
Expand All @@ -22,7 +22,7 @@
"@astrojs/tailwind": "^5.1.4",
"@iconify-json/material-symbols": "^1.2.12",
"astro": "^5.1.1",
"astro-icon": "^1.1.4",
"astro-icon": "^1.1.5",
"tailwindcss": "^3.4.17",
"typescript": "^5.7.2"
},
Expand Down
12 changes: 6 additions & 6 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

19 changes: 7 additions & 12 deletions src/components/BaseHead.astro
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
---
import "../global.css";
import { siteConfig } from "../config";
import '../main.css'
import { siteConfig } from '../config'
interface Props {
title: string;
description: string;
image: string;
title: string
description: string
image: string
}
const canonicalURL = new URL(Astro.url.pathname, Astro.site);
const canonicalURL = new URL(Astro.url.pathname, Astro.site)
const { title, description, image } = Astro.props;
const { title, description, image } = Astro.props
---

<!-- Global Metadata -->
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width,initial-scale=1" />
<link rel="icon" type="image/png" href={siteConfig.favicon} />
Expand All @@ -25,24 +24,20 @@ const { title, description, image } = Astro.props;
href={`${Astro.site}rss.xml`}
/>

<!-- Canonical URL -->
<link rel="canonical" href={canonicalURL} />

<!-- Primary Meta Tags -->
<title>{title}</title>
<meta name="title" content={title} />
<meta name="keywords" content={siteConfig.keywords} />
<meta name="description" content={description} />
<meta name="author" content={siteConfig.author} />

<!-- Open Graph / Facebook -->
<meta property="og:type" content="website" />
<meta property="og:url" content={Astro.url} />
<meta property="og:title" content={title} />
<meta property="og:description" content={description} />
<meta property="og:image" content={new URL(image, Astro.url)} />

<!-- Twitter -->
<meta property="twitter:card" content="summary_large_image" />
<meta property="twitter:url" content={Astro.url} />
<meta property="twitter:title" content={title} />
Expand Down
44 changes: 44 additions & 0 deletions src/components/Card/LinkedCard.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
---
import { Icon } from 'astro-icon/components'
interface Props {
url?: string
target?: string
img?: string
imgAlt?: string
title?: string
}
const { url = '#', target = null, img, imgAlt = '', title = null } = Astro.props
---

<a href={url} target={target} class="flex min-h-32 gap-4 card p-4">
{
img ? (
<img src={img} alt={imgAlt} class="h-20 rounded-full flex-1" />
) : (
<Icon
class="h-20 w-auto text-neutral-600"
name="material-symbols:exit-to-app-sharp"
/>
)
}
<div class="flex flex-col w-full">
<slot name="title">
<h2 class="flex gap-2 font-bold text-xl mb-1">
<span class="highlight-first-letter line-clamp-1 break-all">
{title}
</span>
{
target?.includes('_blank') ? (
<Icon
class="flex-shrink-0 w-5 h-5 self-center ml-auto mr-0"
name="material-symbols:open-in-new"
/>
) : null
}
</h2>
</slot>
<slot />
</div>
</a>
5 changes: 4 additions & 1 deletion src/components/Header.astro
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,15 @@ import { Icon } from 'astro-icon/components'
</nav>
</div>
<button id="search" class="ml-4 icon-button">
<span class="sr-only">Search</span>
<Icon
class="block w-6 h-6 m-auto"
name="material-symbols:search-rounded"
/>
</button>
<button id="theme" class="ml-2 max-sm:ml-4 icon-button"></button>
<button id="theme" class="ml-2 max-sm:ml-4 icon-button">
<span class="sr-only">Toggle theme</span>
</button>
</div>
</header>

Expand Down
84 changes: 84 additions & 0 deletions src/components/Notes/Note.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
---
import getTitle from '../../utils/getTitle'
import fetchFileList from '../../utils/fetchFileList'
import formatDate from '../../utils/formatDate'
import Badge from '../../components/Badge.astro'
import { render } from 'astro:content'
import type { CollectionEntry } from 'astro:content'
import PageLayout from '../../layouts/PageLayout.astro'
// @TODO: handle errors
const fileList = await fetchFileList('posts', '')
const files = await fileList.json()
interface Props {
note: CollectionEntry<'notes'>
}
const { note } = Astro.props
const { data } = note
const { Content } = await render(note)
---

<PageLayout title={getTitle(data.title)} description={data.description}>
<div class="flex items-start">
<aside
class="basis-[16rem] shrink-0 max-md:hidden sticky top-20 mr-4 bg-base transition-all rounded-xl p-2"
>
<ul>
{
// @TODO: Extract to its own component
files.map((file) => (
<li>
<a class="px-2 menu-item" href={file.html_url}>
{file.name}
</a>
</li>
))
}
</ul>
</aside>

<article class="article base-card grow" data-pagefind-body>
<h1 id={data.title}>{data.title}</h1>

<!-- @TODO: Move tags to its own component and add styling -->
<a href={`/notes/${data.tag}`}>{data.tag}</a>:::{data.tags?.join(', ')}

<div class="flex space-x-4 not-prose">
<Badge icon="material-symbols:edit-calendar-rounded">
<time datetime={data.pubDate.toISOString()}>
{formatDate(data.pubDate)}
</time>
</Badge>
</div>

<Content />
</article>
</div>
</PageLayout>

<script>
// @TODO: Remove this when the TOC is removed too (in favor of the files listing)
// @TODO: Make sure to check if the debounce util is being used
// import debounce from '../../utils/debounce'

// const links = document.querySelectorAll('.menu-item')
// const handler = debounce(() => {
// for (const link of links) {
// const href = link.getAttribute('href') as string
// const target = document.querySelector(`[id="${href.slice(1)}"]`)
// if (target) {
// const offsetTop =
// target.getBoundingClientRect().top - document.body.clientHeight / 3
// if (offsetTop <= 0) {
// links.forEach((link) => link.classList.remove('bg-hover'))
// link.classList.add('bg-hover')
// history.replaceState(null, '', href)
// }
// }
// }
// })
// document.addEventListener('scroll', handler)
// document.addEventListener('DOMContentLoaded', handler)
</script>
57 changes: 57 additions & 0 deletions src/components/Notes/Overview.astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
---
import PageLayout from '../../layouts/PageLayout.astro'
import getTitle from '../../utils/getTitle'
import Pagination from '../Pagination.astro'
import type { CollectionEntry } from 'astro:content'
import type { Page } from 'astro'
import LinkedCard from '../Card/LinkedCard.astro'
import formatDate from '../../utils/formatDate'
interface Props {
notes: CollectionEntry<'notes'>[]
page: Page<CollectionEntry<'notes'>>
tags: CollectionEntry<'notes'>['data']['tag'][]
tag: CollectionEntry<'notes'>['data']['tag']
}
const { notes, page, tag } = Astro.props
---

<PageLayout title={getTitle('All Notes')} description="All Notes">
<div class="grow">
<ul class="space-y-4">
{
notes.map((note) => (
<li>
<LinkedCard
url={`/notes/${note.id}`}
img={note.data.image}
imgAlt={note.data.title}
title={note.data.title}
>
<p class="line-clamp-2 mb-2"> {note.data.description} </p>
<div class="mt-auto flex">
<time
class="ml-auto"
datetime={note.data.pubDate.toISOString()}
>
{formatDate(note.data.pubDate)}
</time>
</div>
</LinkedCard>
</li>
))
}
</ul>
<Pagination page={page} {tag} />
</div>
</PageLayout>

<style>
.foo {
width: 80px;
height: 80px;
background-color: grey;
display: inline-block;
}
</style>
Loading

0 comments on commit 528c51d

Please # to comment.