Skip to content

Commit

Permalink
Limit home page to only recent notes
Browse files Browse the repository at this point in the history
Maximum 3 notes per type, and no notes older than 90 days.
  • Loading branch information
puf committed Jul 12, 2024
1 parent f86c3db commit de0f0ac
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 8 deletions.
2 changes: 1 addition & 1 deletion notes/books/The Lost Cause - Cory Doctorrow.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ edition: Audiobook
link: https://www.goodreads.com/book/show/214135308-the-lost-cause
pageCount: 368
---
Near future novel about climate change. I love Cory's the tech topics that Cory writes about, but his novelist style is not always my favorite. In addition, I feel he's the worst person to narrate his own work. Still... I learnt a ton about what climate change could look like, which I liked.
Near future novel about climate change. I love the tech topics that Cory writes about, but his novelist style is not always my favorite. In addition, I feel he's the worst person to narrate his own work. Still... I learnt a ton about what climate change could look like, which I liked.
2 changes: 1 addition & 1 deletion notes/posts/DevRel Funnel.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
---
title: DevRel Adoption Funnel
description: ""
pubDate: July 22, 2022
pubDate: July 22, 2024
heroImage: https://miro.medium.com/v2/resize:fit:1400/format:webp/1*teIrX51jyNYyyCajHGYthA.png
---

Expand Down
2 changes: 1 addition & 1 deletion src/pages/[...slug].astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ const type = getTypeForNote(post)
console.log("Rendering ", post.file, " with pubDate ", pubDate, " and isReadme ", isReadme, " to ", JSON.stringify(post))
// TODO:
// * [ ] Limit number of notes per type on homepage (in progress in index.astro)
// * [ ] Link note detail page back to type index page (with breakcrumb)
// * [ ] Assign layout based on note type
// * [ ] Determine pubDate based on note type, instead of hard-coding them (in Notes.astro)
// * [ ] Show first sentence of readme on home page
// * [ ] group notes on category page on date (month) or whatever else makes sense
// * [x] Limit number of notes per type on homepage (in progress in index.astro)
// * [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
Expand Down
14 changes: 9 additions & 5 deletions src/pages/index.astro
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ console.log(`CWD: ${process.cwd()}, Notes path: ${notesPath}`)
const notes = await getNotes(); // Loads all notes from disk
const readmes = { "posts": "Intro", "books": "Intro" }
const recents = { "posts": [], "books": [] }
const counts = { "posts": 0, "books": 0 }
const CATEGORIES = ["posts", "books"]
// TODO: load recent notes (per category: maxcount=3, maxage=6m)
Expand All @@ -30,11 +31,14 @@ notes.forEach((note) => {
if (readmes[type]) readmes[type] = note;
return; // don't further process readmes
}
console.log(note);
const cutoffDate = new Date(Date.now() - 30*24*60*60*1000)
if (typeof recents[type] !== 'undefined' && recents[type].length < 3 && getPubDateForNote(note)) {
const cutoffDate = new Date(Date.now() - 90*24*60*60*1000)
if (typeof recents[type] !== 'undefined') {
notesCount++
recents[type].push(note);
counts[type]++
if (recents[type].length < 3 && new Date(getPubDateForNote(note)) > cutoffDate) {
recents[type].push(note);
}
}
})
//console.log("READMES", readmes)
Expand Down Expand Up @@ -63,7 +67,7 @@ notes.forEach((note) => {
<li><a href={note.params.slug}>{note.props.frontmatter.title}</a> ({note.params.pubDate})</li>
))}
</ol>
<a href={category}>All {category} ({recents[category].length})</a>
<a href={category}>All {category} ({counts[category]})</a>
<hr/>
))}
<hr/>
Expand Down

0 comments on commit de0f0ac

Please sign in to comment.