mirror of
https://github.com/Xevion/undefined.behavio.rs.git
synced 2025-12-06 01:16:46 -06:00
Factor filter predicate into helpers.ts, add @lib alias dir
This commit is contained in:
5
src/lib/helpers.ts
Normal file
5
src/lib/helpers.ts
Normal file
@@ -0,0 +1,5 @@
|
||||
import { type CollectionEntry } from "astro:content";
|
||||
|
||||
export function shouldShowPost(post: CollectionEntry<"blog">) {
|
||||
return import.meta.env.DEV || !post.data.draft;
|
||||
}
|
||||
@@ -1,8 +1,9 @@
|
||||
---
|
||||
import { getCollection } from "astro:content";
|
||||
import { shouldShowPost } from "@lib/helpers";
|
||||
import General from "@layouts/General.astro";
|
||||
import Summary from "@components/Summary.astro";
|
||||
const posts = (await getCollection("blog")).filter(entry => import.meta.env.DEV || !entry.data.draft);
|
||||
const posts = (await getCollection("blog")).filter(shouldShowPost);
|
||||
posts.sort((a, b) => new Date(b.data.pubDate).getTime() - new Date(a.data.pubDate).getTime());
|
||||
---
|
||||
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
---
|
||||
import Post from "@layouts/Post.astro";
|
||||
import { shouldShowPost } from "@lib/helpers";
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const posts = await getCollection("blog");
|
||||
return posts
|
||||
.filter((entry) => import.meta.env.DEV || !entry.data.draft)
|
||||
.filter(shouldShowPost)
|
||||
.map((entry) => {
|
||||
return {
|
||||
params: { slug: entry.slug },
|
||||
|
||||
@@ -1,12 +1,13 @@
|
||||
---
|
||||
import General from "@layouts/General.astro";
|
||||
import { shouldShowPost } from "@lib/helpers";
|
||||
import { getCollection } from "astro:content";
|
||||
|
||||
export async function getStaticPaths() {
|
||||
const blogEntries = await getCollection("blog");
|
||||
const tags = new Set(
|
||||
blogEntries
|
||||
.filter((entry) => import.meta.env.DEV || !entry.data.draft)
|
||||
.filter(shouldShowPost)
|
||||
.map((entry) => entry.data.tags)
|
||||
.flat(),
|
||||
);
|
||||
|
||||
@@ -3,6 +3,9 @@
|
||||
"compilerOptions": {
|
||||
"baseUrl": ".",
|
||||
"paths": {
|
||||
"@lib/*": [
|
||||
"src/lib/*"
|
||||
],
|
||||
"@styles/*": [
|
||||
"src/styles/*"
|
||||
],
|
||||
|
||||
Reference in New Issue
Block a user