-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Each function in its own file as a default export
- Loading branch information
1 parent
2d4a4cb
commit 0d2ebd6
Showing
27 changed files
with
156 additions
and
128 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { type CollectionEntry } from "astro:content"; | ||
|
||
export default function checkCategory(entry: CollectionEntry<'posts'>, knownCategorySlug: string) { | ||
return entry.id.split('/').at(0) === knownCategorySlug; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
// Adapted from Nunjuck's wordcount filter implementation | ||
|
||
export default function countWords(str: string): number { | ||
const words = (str) ? str.match(/\w+/g) : null; | ||
return (words) ? words.length : 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { type CollectionEntry } from "astro:content"; | ||
import isDraft from "./isDraft"; | ||
|
||
export default function filterOutDraftsIfProduction(entries: CollectionEntry<'posts'>[]): CollectionEntry<'posts'>[] { | ||
const isProduction = (import.meta.env.MODE === 'production'); | ||
if (!isProduction) return entries; | ||
return entries.filter( | ||
(e: CollectionEntry<'posts'>) => !isDraft(e) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export default function firstFive(collection: any[]) { | ||
return collection.slice(0, 5); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export default function formatDateIso(date: Date) { | ||
return date.toISOString(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import { DateTime } from "luxon"; | ||
|
||
export default function formatPostDate(date: Date) { | ||
return DateTime.fromJSDate(date).toLocaleString(DateTime.DATE_MED); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { getCollection, type CollectionEntry } from "astro:content"; | ||
|
||
export default async function getCategory(entry: CollectionEntry<'posts'>): Promise<CollectionEntry<'categories'> | undefined> { | ||
const categories = await getCollection('categories'); | ||
const category = entry.id.split('/').at(0); | ||
if (!category) return undefined; | ||
return categories.find(c => c.id === category); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { type CollectionEntry } from "astro:content"; | ||
|
||
const now = new Date(); | ||
|
||
export default function getPostDate(entry: CollectionEntry<'posts'>) { | ||
if (entry.data.date) { | ||
return entry.data.date; | ||
} | ||
else return now; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { type CollectionEntry } from "astro:content"; | ||
|
||
const now = new Date(); | ||
|
||
export default function isDraft(entry: CollectionEntry<'posts'>): boolean { | ||
return !(entry.data.date && entry.data.date < now); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
import { type CollectionEntry } from "astro:content"; | ||
import isDraft from "./isDraft"; | ||
|
||
|
||
export default function labelDrafts(entries: CollectionEntry<'posts'>[]): CollectionEntry<'posts'>[] { | ||
const label = `[Draft]`; | ||
return entries.map((e: CollectionEntry<'posts'>) => { | ||
e.data.title = (isDraft(e) && !e.data.title.startsWith(label)) ? `${label} ${e.data.title}` : e.data.title; | ||
return e; | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import sanitizeHtml from 'sanitize-html'; | ||
import MarkdownIt from 'markdown-it'; | ||
import anchor from 'markdown-it-anchor'; | ||
import footnote from 'markdown-it-footnote'; | ||
|
||
const parser = new MarkdownIt({ | ||
html: true, | ||
typographer: true | ||
}).use(anchor, { | ||
permalink: anchor.permalink.headerLink({ | ||
safariReaderFix: true | ||
}) | ||
}).use(footnote); | ||
|
||
export default function renderMarkdown(markdown: string) { | ||
return sanitizeHtml(parser.render(markdown)); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { type CollectionEntry } from "astro:content"; | ||
import getPostDate from "./getPostDate"; | ||
|
||
|
||
export default function sortByDate(entries: CollectionEntry<'posts'>[]): CollectionEntry<'posts'>[] { | ||
return entries.sort( | ||
(a, b) => getPostDate(b).getTime() - getPostDate(a).getTime()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
|
||
export type WithNextAndPrev<T> = { | ||
item: T, | ||
next?: T, | ||
prev?: T | ||
} | ||
|
||
export default function toWithNextAndPrev<T>(items: T[], reverse: boolean = false): WithNextAndPrev<T>[] { | ||
return items.map((t, i, a) => ({ | ||
item: t, | ||
next: reverse ? a[i - 1] : a[i + 1], | ||
prev: reverse ? a[i + 1] : a[i - 1] | ||
})); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
|
||
export default function trimTrailingSlash(str: string): string { | ||
return str.replace(/\/$/, ""); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
export default function unMarkdown(raw: string): string { | ||
return raw?.replace(/[\*_`]/g, '') | ||
} |
This file was deleted.
Oops, something went wrong.