add VISIBLE_DRAFT for showing drafts in the list
All checks were successful
Build & Depoly / Depoly blog (push) Successful in 1m41s

This commit is contained in:
thislight 2025-04-26 14:21:07 +08:00
parent 9ec980839a
commit 85ded53035
3 changed files with 42 additions and 22 deletions

View file

@ -1,23 +1,36 @@
import { defineConfig } from "astro/config"; import { defineConfig, envField } from "astro/config";
import solidJs from "@astrojs/solid-js"; import solidJs from "@astrojs/solid-js";
import mdx from "@astrojs/mdx"; import mdx from "@astrojs/mdx";
import icon from "astro-icon"; import icon from "astro-icon";
import paths from "node:path" import paths from "node:path";
import rehypeBuckTable from "~/support/rehype-buck-tables"; import rehypeBuckTable from "~/support/rehype-buck-tables";
// https://astro.build/config // https://astro.build/config
export default defineConfig({ export default defineConfig({
integrations: [solidJs(), mdx(), icon(), { env: {
schema: {
VISIBLE_DRAFT: envField.boolean({
context: "server",
access: "public",
default: false,
}),
},
},
integrations: [
solidJs(),
mdx(),
icon(),
{
name: "inject-cloudflare-headers", name: "inject-cloudflare-headers",
"hooks": { hooks: {
"astro:config:setup": ({injectRoute}) => { "astro:config:setup": ({ injectRoute }) => {
injectRoute({ injectRoute({
pattern: "/_headers", pattern: "/_headers",
entrypoint: "./src/pages/_headers.ts", entrypoint: "./src/pages/_headers.ts",
}) });
} },
} },
} },
], ],
markdown: { markdown: {
rehypePlugins: [rehypeBuckTable], rehypePlugins: [rehypeBuckTable],
@ -25,14 +38,14 @@ export default defineConfig({
themes: { themes: {
light: "github-light", light: "github-light",
dark: "github-dark", dark: "github-dark",
} },
} },
}, },
vite: { vite: {
resolve: { resolve: {
alias: { alias: {
"~": paths.resolve(import.meta.dir, "src") "~": paths.resolve(import.meta.dir, "src"),
} },
} },
} },
}); });

View file

@ -3,7 +3,7 @@
"type": "module", "type": "module",
"private": true, "private": true,
"scripts": { "scripts": {
"dev": "bunx --bun astro dev", "dev": "VISIBLE_DRAFT=true bunx --bun astro dev",
"dist": "bunx --bun astro build", "dist": "bunx --bun astro build",
"preview": "bunx --bun astro preview", "preview": "bunx --bun astro preview",
"posts": "bun run scripts/postman.ts" "posts": "bun run scripts/postman.ts"

View file

@ -1,4 +1,5 @@
import type { CollectionEntry } from "astro:content"; import type { CollectionEntry } from "astro:content";
import { VISIBLE_DRAFT } from "astro:env/server";
function toPadLeft(n: number) { function toPadLeft(n: number) {
if (n < 10) { if (n < 10) {
@ -24,7 +25,9 @@ export function postParamlink(post: CollectionEntry<"posts">) {
} }
export function getAllTags(posts: CollectionEntry<"posts">[]) { export function getAllTags(posts: CollectionEntry<"posts">[]) {
const tags = new Set(posts.filter(shouldBeVisible).flatMap((post) => post.data.tags || [])); const tags = new Set(
posts.filter(shouldBeVisible).flatMap((post) => post.data.tags || []),
);
return tags.values().toArray().sort(); return tags.values().toArray().sort();
} }
@ -75,5 +78,9 @@ export function getHotTags(posts: CollectionEntry<"posts">[], tags: string[]) {
} }
export function shouldBeVisible(post: CollectionEntry<"posts">) { export function shouldBeVisible(post: CollectionEntry<"posts">) {
return !post.data.visibility || post.data.visibility === "visible" return (
!post.data.visibility ||
post.data.visibility === "visible" ||
(VISIBLE_DRAFT && post.data.visibility === "draft")
);
} }