Skip to content

Commit

Permalink
Show list of notes on type index page
Browse files Browse the repository at this point in the history
  • Loading branch information
puf committed Jul 12, 2024
1 parent a8399f3 commit 7fc2f9f
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 17 deletions.
14 changes: 7 additions & 7 deletions notes/.obsidian/workspace.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
"state": {
"type": "markdown",
"state": {
"file": "posts/How to perform geoqueries on Firestore (somewhat) efficiently.md",
"file": "readme.md",
"mode": "source",
"source": false
}
Expand Down Expand Up @@ -98,7 +98,7 @@
"state": {
"type": "backlink",
"state": {
"file": "posts/How to perform geoqueries on Firestore (somewhat) efficiently.md",
"file": "readme.md",
"collapseAll": false,
"extraContext": false,
"sortOrder": "alphabetical",
Expand All @@ -115,7 +115,7 @@
"state": {
"type": "outgoing-link",
"state": {
"file": "posts/How to perform geoqueries on Firestore (somewhat) efficiently.md",
"file": "readme.md",
"linksCollapsed": false,
"unlinkedCollapsed": true
}
Expand All @@ -138,7 +138,7 @@
"state": {
"type": "outline",
"state": {
"file": "posts/How to perform geoqueries on Firestore (somewhat) efficiently.md"
"file": "readme.md"
}
}
}
Expand All @@ -161,12 +161,12 @@
},
"active": "1365a4023b87afb4",
"lastOpenFiles": [
"posts/DevRel Funnel.md",
"books/_readme.md",
"posts/_readme.md",
"posts/How to perform geoqueries on Firestore (somewhat) efficiently.md",
"posts/DevRel Funnel.md",
"readme.md",
"Welcome.md",
"books/_readme.md",
"posts/_readme.md",
"posts/Untitled.md",
"books/Chip War - Chris Miller.md",
"books/The Rule of Threes - Jeffery Deaver.md",
Expand Down
2 changes: 1 addition & 1 deletion notes/books/_readme.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
I'm a voracious reader of books and articles. I track all my reading on [GoodReads](https://www.goodreads.com/user/show/24654655) and have been writing short reviews for a few years now, which I'll share here.
I'm a voracious reader of books and articles, and write blurbs about that. I track all my reading on [GoodReads](https://www.goodreads.com/user/show/24654655) and have been writing short reviews for a few years now, which I'll share here.
4 changes: 3 additions & 1 deletion notes/posts/_readme.md
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
I write a lot, and sometimes post it here.
I write a lot, and sometimes post it here.

From February until August 2014 I wrote about many topics on [The Puf Principle](http://frank.vanpuffelen.net/). Most of my public writing can be found in Stack Overflow [questions](https://stackoverflow.com/users/209103/frank-van-puffelen?tab=questions) and [answers](https://stackoverflow.com/users/209103/frank-van-puffelen?tab=answers); really... **do** check them out as there's bound to be **something** useful in there.
7 changes: 6 additions & 1 deletion src/components/Notes.astro
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export function getPubDateForNote(note) {
return ""; // What should the default be here?
}
export async function getNotes(options?: { includeSkip?: boolean }) {
export async function getNotes(options?: { keepIf?: (note: any) => boolean }) {
// Get all notes recursively from the notes directory
const notes = await Astro.glob("../../notes/**/*.md");
Expand Down Expand Up @@ -58,6 +58,11 @@ export async function getNotes(options?: { includeSkip?: boolean }) {
return !isDraft;
});
// Remove by custom filter
if (options?.keepIf) {
results = results.filter(options.keepIf);
}
// console.log("getNotes", results)
return results;
}
Expand Down
16 changes: 14 additions & 2 deletions src/layouts/IndexPage.astro
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import Header from '../components/Header.astro';
import Footer from '../components/Footer.astro';
import FormattedDate from '../components/FormattedDate.astro';
import path from "path";
import { notesPath, getSlugForNote, getTypeForNote } from '../components/Notes.astro';
import { notesPath, getSlugForNote, getTypeForNote, getNotes } from '../components/Notes.astro';
console.log("IndexPage.astro: Astro.props=", Astro.props)
Expand All @@ -16,6 +16,8 @@ const type = slug.substring(0, slug.indexOf("/"))
// const name = slug.substring(type.length+1)
title = type
const notes = await getNotes({ keepIf: (note) => note.params.type === type && !/readme.md$/.test(note.props.file) });
console.log(slug, type, title)
---

Expand Down Expand Up @@ -73,9 +75,19 @@ console.log(slug, type, title)
<div class="prose">
<div class="title">
<h1>{title}</h1>
<hr />
</div>
<hr />
<slot />
<hr />
<div class="list">
<div>There are {notes.length} {type}:</div>
<ol>
{notes.map((note) => (
<li><a href={note.params.slug}>{note.props.frontmatter.title}</a> ({note.params.pubDate})</li>
))}
</ol>
<hr/>
</div>
<div class="date">
{
<div class="last-updated-on">
Expand Down
12 changes: 7 additions & 5 deletions src/pages/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
import { type CollectionEntry, getCollection } from 'astro:content';
import BlogPost from '../layouts/BlogPost.astro';
import IndexPage from '../layouts/IndexPage.astro';
import { getNotes, getPubDateForNote } from '../components/Notes.astro';
import { getNotes, getPubDateForNote, getTypeForNote } from '../components/Notes.astro';
import type { MarkdownInstance } from "astro";
export async function getStaticPaths() {
Expand All @@ -15,18 +15,20 @@ const { Content } = post;
const pubDate = getPubDateForNote(post)
const isReadme = (/readme.md$/.test(post.file))
const type = getTypeForNote(post)
console.log("Rendering ", post.file, " with pubDate ", pubDate, " and isReadme ", isReadme, " to ", JSON.stringify(post))
// TODO:
// * [ ] Show all notes of type on index page for that type
// * [ ] Link index page for type back to home page
// * [ ] Show current index page (and detail page?) as a "breakcrumb" in the header
// * [ ] Link note page for type back to type index page
// * [ ] Show current index page as "breakcrumb" in the header for note-detail page
// * [ ] Assign layout based on note type
// * [ ] Determine pubDate based on note type, instead of hard-coding them (in Notes.astro)
// * [ ] Show one-line readme on main index.html
// * [ ] Show first sentence of readme on home page
// * [ ] Limit number of notes on homepage
// * [ ] group notes on category page on date (month) or whatever else makes sense
// * [x] Link index page for type back to home page (that was always the case)
// * [x] Show all notes of type on index page for that type (done: in Notes.astro and IndexPage.astro)
// * [x] Generate additional nodes/paths for category pages
// * [x] Show readme on pages
// * [x] Skip notes whose pubDate is in the future
Expand Down

0 comments on commit 7fc2f9f

Please sign in to comment.