Compare commits
4 commits
302ded3613
...
65fb7cf638
Author | SHA1 | Date | |
---|---|---|---|
65fb7cf638 | |||
9e0afdad03 | |||
ca28bd2d36 | |||
bfd3bef223 |
14 changed files with 66 additions and 21 deletions
|
@ -1,9 +1,17 @@
|
||||||
---
|
---
|
||||||
const { tip = '' } = Astro.props
|
const { tip = '' } = Astro.props
|
||||||
|
let divNeeded = false
|
||||||
|
const content = await Astro.slots.render('default')
|
||||||
|
if (content.includes('<p>')) {
|
||||||
|
divNeeded = true
|
||||||
|
}
|
||||||
|
|
||||||
---
|
---
|
||||||
<span class="spoiler" title={tip}>
|
{divNeeded ?
|
||||||
<slot/>
|
<div class="spoiler" title={tip} set:html={content}></div>
|
||||||
</span>
|
:
|
||||||
|
<span class="spoiler" title={tip} set:html={content}></span>
|
||||||
|
}
|
||||||
<style>
|
<style>
|
||||||
:global(.spoiler p) {
|
:global(.spoiler p) {
|
||||||
background-color: #252525;
|
background-color: #252525;
|
||||||
|
|
|
@ -4,6 +4,7 @@ import { z, reference } from 'astro:content';
|
||||||
export const posts = ({ image }) => z.object({
|
export const posts = ({ image }) => z.object({
|
||||||
title: z.string(),
|
title: z.string(),
|
||||||
description: z.string().optional(),
|
description: z.string().optional(),
|
||||||
|
draft: z.boolean().optional().default(false),
|
||||||
summary: z.string().optional(),
|
summary: z.string().optional(),
|
||||||
date: z.coerce.date(),
|
date: z.coerce.date(),
|
||||||
categories: z.union([z.array(z.string()), z.string()]).transform(val => Array.isArray(val) ? val : [val]).default(['uncategorized']),
|
categories: z.union([z.array(z.string()), z.string()]).transform(val => Array.isArray(val) ? val : [val]).default(['uncategorized']),
|
||||||
|
|
|
@ -9,7 +9,9 @@ import { getLangFromUrl, useTranslations, useTranslatedPath } from '../i18n/util
|
||||||
const lang = getLangFromUrl(Astro.url);
|
const lang = getLangFromUrl(Astro.url);
|
||||||
const t = useTranslations(lang);
|
const t = useTranslations(lang);
|
||||||
const translatePath = useTranslatedPath(lang);
|
const translatePath = useTranslatedPath(lang);
|
||||||
const posts = await getCollection('posts');
|
const posts = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime());
|
posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime());
|
||||||
---
|
---
|
||||||
|
|
||||||
|
|
|
@ -17,7 +17,9 @@ const t = useTranslations(lang);
|
||||||
const translatePath = useTranslatedPath(lang);
|
const translatePath = useTranslatedPath(lang);
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const blogEntries = await getCollection('posts');
|
const blogEntries = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
return blogEntries.map(entry => ({
|
return blogEntries.map(entry => ({
|
||||||
params: { slug: entry.slug }, props: { entry },
|
params: { slug: entry.slug }, props: { entry },
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -2,7 +2,9 @@ import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
export const prerender = true;
|
export const prerender = true;
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const blogEntries = await getCollection('posts');
|
const blogEntries = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
return blogEntries.map(entry => ({
|
return blogEntries.map(entry => ({
|
||||||
params: { slug: entry.slug }, props: { entry },
|
params: { slug: entry.slug }, props: { entry },
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -62,7 +62,9 @@ const fileCache = {
|
||||||
};
|
};
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const blogEntries = await getCollection('posts');
|
const blogEntries = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
return blogEntries.map(post => ({
|
return blogEntries.map(post => ({
|
||||||
params: { slug: post.slug }, props: { post },
|
params: { slug: post.slug }, props: { post },
|
||||||
}));
|
}));
|
||||||
|
|
|
@ -1,17 +1,26 @@
|
||||||
---
|
---
|
||||||
import {getCollection} from "astro:content";
|
import {getCollection} from "astro:content";
|
||||||
import Layout from "../layouts/Layout.astro";
|
import Layout from "../layouts/Layout.astro";
|
||||||
const allPosts = await getCollection('posts');
|
const allPosts = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
const uniqueCategories = [...new Set(allPosts.map((post: any) => post.data.categories ? post.data.categories : []).flat())];
|
const uniqueCategories = [...new Set(allPosts.map((post: any) => post.data.categories ? post.data.categories : []).flat())];
|
||||||
---
|
---
|
||||||
<Layout title="Categoies" description="List all categories used in the blog posts.">
|
<Layout title="Categoies" description="List all categories used in the blog posts.">
|
||||||
<h1 class="title">~/blog/categories</h1>
|
<h1 class="title">~/blog/categories</h1>
|
||||||
<div style="margin-top: 2rem;">
|
<div style="margin-top: 2rem;">
|
||||||
<span class="command">ls -l categories/</span>
|
<span class="command">ls categories/</span>
|
||||||
<div style="margin-top: 1rem; margin-left: 1rem;">
|
<div style="margin-top: 1rem; margin-left: 1rem;" class="category-list">
|
||||||
{uniqueCategories.map((tag) => (
|
{uniqueCategories.map((category) => (
|
||||||
<p><a href={`/categories/${tag}`}>{tag}</a></p>
|
<p><a href={`/categories/${category}`}>{category}</a></p>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
<style>
|
||||||
|
div.category-list {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
</style>
|
|
@ -4,7 +4,9 @@ import {getCollection} from "astro:content";
|
||||||
import ArticleList from "../../components/ArticleList.astro";
|
import ArticleList from "../../components/ArticleList.astro";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const allPosts = await getCollection('posts');
|
const allPosts = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
// Get all categories, ensuring the default 'uncategorized' is used when categories is undefined
|
// Get all categories, ensuring the default 'uncategorized' is used when categories is undefined
|
||||||
const uniqueCategories = [...new Set(allPosts.map((post: any) =>
|
const uniqueCategories = [...new Set(allPosts.map((post: any) =>
|
||||||
post.data.categories || ['uncategorized']).flat())];
|
post.data.categories || ['uncategorized']).flat())];
|
||||||
|
|
|
@ -12,7 +12,7 @@ try {
|
||||||
}
|
}
|
||||||
---
|
---
|
||||||
|
|
||||||
<Layout>
|
<Layout ogImage={siteConfig.homepageOgImage || ""}>
|
||||||
<h1 class="title">~/</h1>
|
<h1 class="title">~/</h1>
|
||||||
<div class="content">
|
<div class="content">
|
||||||
{HomePageContent ? <HomePageContent/> :
|
{HomePageContent ? <HomePageContent/> :
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
export async function GET() {
|
export async function GET() {
|
||||||
const posts = await getCollection('posts');
|
const posts = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
const searchIndex = posts.map(post => ({
|
const searchIndex = posts.map(post => ({
|
||||||
title: post.data.title,
|
title: post.data.title,
|
||||||
description: post.data.description || '',
|
description: post.data.description || '',
|
||||||
|
|
|
@ -1,17 +1,26 @@
|
||||||
---
|
---
|
||||||
import {getCollection} from "astro:content";
|
import {getCollection} from "astro:content";
|
||||||
import Layout from "../layouts/Layout.astro";
|
import Layout from "../layouts/Layout.astro";
|
||||||
const allPosts = await getCollection('posts');
|
const allPosts = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
const uniqueTags = [...new Set(allPosts.map((post: any) => post.data.tags ? post.data.tags : []).flat())];
|
const uniqueTags = [...new Set(allPosts.map((post: any) => post.data.tags ? post.data.tags : []).flat())];
|
||||||
---
|
---
|
||||||
<Layout title="Tags" description="List all tags used in the blog posts.">
|
<Layout title="Tags" description="List all tags used in the blog posts.">
|
||||||
<h1 class="title">~/blog/tags</h1>
|
<h1 class="title">~/blog/tags</h1>
|
||||||
<div style="margin-top: 2rem;">
|
<div style="margin-top: 2rem;">
|
||||||
<span class="command">ls -l tags/</span>
|
<span class="command">ls tags/</span>
|
||||||
<div style="margin-top: 1rem; margin-left: 1rem;">
|
<div style="margin-top: 1rem; margin-left: 1rem;" class="tags-list">
|
||||||
{uniqueTags.map((tag) => (
|
{uniqueTags.map((tag) => (
|
||||||
<p><a href={`/tags/${tag}`}>{tag}</a></p>
|
<p><a href={`/tags/${tag}`}>{tag}</a></p>
|
||||||
))}
|
))}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</Layout>
|
</Layout>
|
||||||
|
<style>
|
||||||
|
div.tags-list {
|
||||||
|
display: flex;
|
||||||
|
gap: 1rem;
|
||||||
|
flex-wrap: wrap;
|
||||||
|
}
|
||||||
|
</style>
|
||||||
|
|
|
@ -4,7 +4,9 @@ import {getCollection} from "astro:content";
|
||||||
import ArticleList from "../../components/ArticleList.astro";
|
import ArticleList from "../../components/ArticleList.astro";
|
||||||
|
|
||||||
export async function getStaticPaths() {
|
export async function getStaticPaths() {
|
||||||
const allPosts = await getCollection('posts');
|
const allPosts = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
const uniqueTags = [...new Set(allPosts.map((post: any) => post.data.tags ? post.data.tags : []).flat())];
|
const uniqueTags = [...new Set(allPosts.map((post: any) => post.data.tags ? post.data.tags : []).flat())];
|
||||||
return uniqueTags.map((tag) => {
|
return uniqueTags.map((tag) => {
|
||||||
const filteredPosts = allPosts.filter((post: any) => post.data.tags?.includes(tag));
|
const filteredPosts = allPosts.filter((post: any) => post.data.tags?.includes(tag));
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import { getCollection } from 'astro:content';
|
import { getCollection } from 'astro:content';
|
||||||
|
|
||||||
export async function GET(context) {
|
export async function GET(context) {
|
||||||
const posts = await getCollection('posts');
|
const posts = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
// Sort posts by date (newest first)
|
// Sort posts by date (newest first)
|
||||||
posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime());
|
posts.sort((a, b) => new Date(b.data.date).getTime() - new Date(a.data.date).getTime());
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
import { getCollection, render } from 'astro:content';
|
import { getCollection, render } from 'astro:content';
|
||||||
|
|
||||||
async function fetchPostsData() {
|
async function fetchPostsData() {
|
||||||
const posts = await getCollection('posts');
|
const posts = await getCollection('posts', ({ data }) => {
|
||||||
|
return import.meta.env.PROD ? data.draft !== true : true;
|
||||||
|
});
|
||||||
const entriesData = {};
|
const entriesData = {};
|
||||||
|
|
||||||
for (const post of posts) {
|
for (const post of posts) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue