Skip to content

Commit

Permalink
Update rss
Browse files Browse the repository at this point in the history
  • Loading branch information
derekmbrown committed Nov 30, 2024
1 parent 32302d7 commit 3d6eb2c
Show file tree
Hide file tree
Showing 17 changed files with 57 additions and 26 deletions.
12 changes: 12 additions & 0 deletions src/content/config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { z, defineCollection } from 'astro:content'

const noteCollection = defineCollection({
type: 'content',
schema: z.object({
title: z.string(),
pubDate: z.string(),
tags: z.array(z.string()),
})
})

export const collections = { 'notes': noteCollection }
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'Add Full Path To Default Oh My Zsh Theme'
pubDate: 04-17-2024
tags: ['note', 'terminal', 'ohmyzsh']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'Custom Shortcuts In VS Code'
pubDate: 11-20-2024
tags: ['note', 'vscode']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'Delete All Git History'
pubDate: 03-29-2024
tags: ['note', 'git', 'cli']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'Docker Multi-Stage Build'
pubDate: 02-24-2024
tags: ['note', 'docker', 'snippet']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'Huginn Docker Compose File'
pubDate: 05-15-2024
tags: ['note', 'docker', 'huginn']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'List Number Of Objects Stored In S3 Bucket'
pubDate: 05-28-2024
tags: ['note', 'aws', 's3', 'cli']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'My First Note'
pubDate: 02-01-2024
tags: ['note']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'Reset Sidebar Views In VS Code'
pubDate: 08-14-2024
tags: ['note', 'vscode']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'Send Raw String As Body Using HTTPie'
pubDate: 10-29-2024
tags: ['note', 'terminal', httpie]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'Shiki Themes For Markdown Syntax Highlighting'
pubDate: 11-10-2024
tags: ['note', 'astro', 'markdown']
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
layout: '../../layouts/Note.astro'
title: 'SSH To Remote Host Through Bastion In One Command'
pubDate: 04-27-2024
tags: ['note', 'ssh']
Expand Down
9 changes: 5 additions & 4 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
import Main from '../layouts/Main.astro'
import { getCollection } from 'astro:content'
const allNotes = await Astro.glob('./notes/*.md')
allNotes.sort((a, b) => Date.parse(b.frontmatter.pubDate) - Date.parse(a.frontmatter.pubDate))
const allNotes = await getCollection('notes')
allNotes.sort((a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate))
---

<Main
Expand All @@ -23,10 +24,10 @@ allNotes.sort((a, b) => Date.parse(b.frontmatter.pubDate) - Date.parse(a.frontma
{allNotes.slice(0, 5).map((note) =>
<div class="flex flex-col justify-between md:flex-row md:mb-3 mb-3 bg-[#1E262F] p-6 text-lg rounded-lg">
<div class="mr-2">
<a href={note.url}>{note.frontmatter.title}</a>
<a href={`/notes/${note.slug}`}>{note.data.title}</a>
</div>
<div class="text-[#7E8C9A] shrink-0">
{new Date(note.frontmatter.pubDate).toDateString().slice(4, 15)}
{new Date(note.data.pubDate).toDateString().slice(4, 15)}
</div>
</div>
)}
Expand Down
19 changes: 19 additions & 0 deletions src/pages/notes/[...slug].astro
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
---
import Note from '../../layouts/Note.astro'
import { getCollection } from 'astro:content'
export async function getStaticPaths() {
const allNotes = await getCollection('notes')
allNotes.sort((a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate))
return allNotes.map(note => ({
params: { slug: note.slug }, props: { note }
}))
}
const { note } = Astro.props
const { Content } = await note.render()
---

<Note frontmatter={note.data}>
<Content />
</Main>
12 changes: 10 additions & 2 deletions src/pages/rss.xml.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,18 @@
import rss, { pagesGlobToRssItems } from '@astrojs/rss';
import rss from '@astrojs/rss'
import { getCollection } from 'astro:content'

export async function GET(context) {
const notes = await getCollection('notes')
notes.sort((a, b) => new Date(b.data.pubDate) - new Date(a.data.pubDate))

return rss({
title: 'Derek Brown\'s Notes',
description: 'Notes from Derek Brown.',
site: context.site,
items: await pagesGlobToRssItems(import.meta.glob('./notes/*.{md,mdx}'))
items: notes.map((note) => ({
title: note.data.title,
pubDate: note.data.pubDate,
link: `/note/${note.slug}/`
}))
})
}
15 changes: 8 additions & 7 deletions src/pages/tags/[tag].astro
Original file line number Diff line number Diff line change
@@ -1,20 +1,21 @@
---
import Main from '../../layouts/Main.astro'
import { getCollection } from 'astro:content'
export async function getStaticPaths() {
const allNotes = await Astro.glob('../notes/*.md')
allNotes.sort((a, b) => Date.parse(b.frontmatter.pubDate) - Date.parse(a.frontmatter.pubDate))
const allTags = [...new Set(allNotes.map((note) => note.frontmatter.tags).flat())]
const allNotes = await getCollection('notes')
allNotes.sort((a, b) => Date.parse(b.data.pubDate) - Date.parse(a.data.pubDate))
const allTags = [...new Set(allNotes.map((note) => note.data.tags).flat())]
return allTags.map((tag) => {
const filteredNotes = allNotes.filter((note) => note.frontmatter.tags.includes(tag))
const filteredNotes = allNotes.filter((note) => note.data.tags.includes(tag))
return { params: { tag }, props: { notes: filteredNotes }}
})
}
const { tag } = Astro.params
const { notes } = Astro.props
const filteredNotes = notes.filter((note) => note.frontmatter.tags?.includes(tag))
const filteredNotes = notes.filter((note) => note.data.tags?.includes(tag))
const title = `Tag: ${tag}`
---

Expand All @@ -29,9 +30,9 @@ const title = `Tag: ${tag}`
<div class="mb-6 text-xl">{filteredNotes.length} notes tagged with <span class="font-black">{tag}</span>:</div>
{filteredNotes.map((note) =>
<div class="flex flex-col justify-between md:flex-row md:mb-3 mb-3 bg-[#1E262F] p-6 text-lg rounded-lg">
<div><a href={note.url}>{note.frontmatter.title}</a></div>
<div><a href={`/notes/${note.slug}`}>{note.data.title}</a></div>
<div class="text-[#7E8C9A] shrink-0">
{new Date(note.frontmatter.pubDate).toDateString().slice(4, 15)}
{new Date(note.data.pubDate).toDateString().slice(4, 15)}
</div>
</div>
)}
Expand Down
5 changes: 3 additions & 2 deletions src/pages/tags/index.astro
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
---
import Main from '../../layouts/Main.astro'
import { getCollection } from 'astro:content'
const allNotes = await Astro.glob('./../notes/*.md')
const tags = [...new Set(allNotes.map((note) => note.frontmatter.tags).flat())]
const allNotes = await getCollection('notes')
const tags = [...new Set(allNotes.map((note) => note.data.tags).flat())]
tags.sort()
---

Expand Down

0 comments on commit 3d6eb2c

Please sign in to comment.