mirror of
https://github.com/Xevion/undefined.behavio.rs.git
synced 2025-12-06 11:16:51 -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 { getCollection } from "astro:content";
|
||||||
|
import { shouldShowPost } from "@lib/helpers";
|
||||||
import General from "@layouts/General.astro";
|
import General from "@layouts/General.astro";
|
||||||
import Summary from "@components/Summary.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());
|
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 Post from "@layouts/Post.astro";
|
||||||
|
import { shouldShowPost } from "@lib/helpers";
|
||||||
import { getCollection } from "astro:content";
|
import { getCollection } from "astro:content";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const posts = await getCollection("blog");
|
const posts = await getCollection("blog");
|
||||||
return posts
|
return posts
|
||||||
.filter((entry) => import.meta.env.DEV || !entry.data.draft)
|
.filter(shouldShowPost)
|
||||||
.map((entry) => {
|
.map((entry) => {
|
||||||
return {
|
return {
|
||||||
params: { slug: entry.slug },
|
params: { slug: entry.slug },
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
---
|
---
|
||||||
import General from "@layouts/General.astro";
|
import General from "@layouts/General.astro";
|
||||||
|
import { shouldShowPost } from "@lib/helpers";
|
||||||
import { getCollection } from "astro:content";
|
import { getCollection } from "astro:content";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const blogEntries = await getCollection("blog");
|
const blogEntries = await getCollection("blog");
|
||||||
const tags = new Set(
|
const tags = new Set(
|
||||||
blogEntries
|
blogEntries
|
||||||
.filter((entry) => import.meta.env.DEV || !entry.data.draft)
|
.filter(shouldShowPost)
|
||||||
.map((entry) => entry.data.tags)
|
.map((entry) => entry.data.tags)
|
||||||
.flat(),
|
.flat(),
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -3,6 +3,9 @@
|
|||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"baseUrl": ".",
|
"baseUrl": ".",
|
||||||
"paths": {
|
"paths": {
|
||||||
|
"@lib/*": [
|
||||||
|
"src/lib/*"
|
||||||
|
],
|
||||||
"@styles/*": [
|
"@styles/*": [
|
||||||
"src/styles/*"
|
"src/styles/*"
|
||||||
],
|
],
|
||||||
|
|||||||
Reference in New Issue
Block a user