Add date-based post scheduling and daily deploy cron

Gate blog listings/RSS on pubDate<=now (in addition to !draft) via a shared
getPublishedPosts() helper, so a post set to draft:false with a future pubDate
publishes itself once a build runs on that day. Dev shows everything for preview.

Add .gitea/workflows/scheduled-deploy.yml: a daily cron that pings the Coolify
deploy hook so the static site rebuilds and the date gate advances. No file
mutation, no repo write access — needs a runner + COOLIFY_DEPLOY_HOOK secret.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-07-01 16:35:06 +02:00
parent d1acda5a93
commit cecbda26b0
7 changed files with 84 additions and 15 deletions

View File

@@ -1,10 +1,11 @@
---
import { getCollection, render } from 'astro:content';
import { render } from 'astro:content';
import BlogPost from '../../layouts/BlogPost.astro';
import type { GetStaticPaths } from 'astro';
import { getPublishedPosts } from '../../utils/posts';
export const getStaticPaths = (async () => {
const posts = await getCollection('blog', ({ data }) => !data.draft);
const posts = await getPublishedPosts();
return posts.map((post) => ({
params: { slug: post.id },
props: { post },

View File

@@ -1,11 +1,9 @@
---
import BaseLayout from '../../layouts/BaseLayout.astro';
import FormattedDate from '../../components/FormattedDate.astro';
import { getCollection } from 'astro:content';
import { getPublishedPosts } from '../../utils/posts';
const posts = (await getCollection('blog', ({ data }) => !data.draft)).sort(
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
);
const posts = await getPublishedPosts();
---
<BaseLayout title="Blog" description="Writing and notes by Jean-Luc Makiola." width="narrow">

View File

@@ -3,10 +3,9 @@ import BaseLayout from '../layouts/BaseLayout.astro';
import { Icon } from 'astro-icon/components';
import { getCollection } from 'astro:content';
import { SITE } from '../consts';
import { getPublishedPosts } from '../utils/posts';
const posts = (await getCollection('blog', ({ data }) => !data.draft))
.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf())
.slice(0, 4);
const posts = (await getPublishedPosts()).slice(0, 4);
const fmt = (d: Date) =>
d.toLocaleDateString(SITE.lang, { year: 'numeric', month: 'short' });

View File

@@ -1,11 +1,9 @@
import rss from '@astrojs/rss';
import { getCollection } from 'astro:content';
import { SITE } from '../consts';
import { getPublishedPosts } from '../utils/posts';
export async function GET(context) {
const posts = (await getCollection('blog', ({ data }) => !data.draft)).sort(
(a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf()
);
const posts = await getPublishedPosts();
return rss({
title: SITE.title,

View File

@@ -1,11 +1,11 @@
---
import BaseLayout from '../../layouts/BaseLayout.astro';
import FormattedDate from '../../components/FormattedDate.astro';
import { getCollection } from 'astro:content';
import type { GetStaticPaths } from 'astro';
import { getPublishedPosts } from '../../utils/posts';
export const getStaticPaths = (async () => {
const posts = await getCollection('blog', ({ data }) => !data.draft);
const posts = await getPublishedPosts();
const tags = [...new Set(posts.flatMap((p) => p.data.tags))];
return tags.map((tag) => ({
params: { tag },

24
src/utils/posts.ts Normal file
View File

@@ -0,0 +1,24 @@
import { getCollection, type CollectionEntry } from 'astro:content';
/**
* Published blog posts, newest first.
*
* A post is published when it is not a draft AND its `pubDate` has arrived.
* That makes `pubDate` the single source of truth for scheduling: set a post
* to `draft: false` with a future date and it goes live on its own once a
* build runs on or after that day (see the daily deploy cron).
*
* In dev the gate is lifted entirely so drafts and future-scheduled posts can
* be previewed locally; production applies both the draft and date gates.
*/
export async function getPublishedPosts(): Promise<CollectionEntry<'blog'>[]> {
const now = Date.now();
const posts = await getCollection('blog', ({ data }) => {
// Dev server: show everything, including drafts and not-yet-due posts.
if (import.meta.env.DEV) return true;
if (data.draft) return false;
if (data.pubDate.valueOf() > now) return false;
return true;
});
return posts.sort((a, b) => b.data.pubDate.valueOf() - a.data.pubDate.valueOf());
}