add VISIBLE_DRAFT for showing drafts in the list
All checks were successful
Build & Depoly / Depoly blog (push) Successful in 1m41s
All checks were successful
Build & Depoly / Depoly blog (push) Successful in 1m41s
This commit is contained in:
parent
9ec980839a
commit
85ded53035
3 changed files with 42 additions and 22 deletions
|
@ -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: {
|
||||||
name: "inject-cloudflare-headers",
|
schema: {
|
||||||
"hooks": {
|
VISIBLE_DRAFT: envField.boolean({
|
||||||
"astro:config:setup": ({injectRoute}) => {
|
context: "server",
|
||||||
injectRoute({
|
access: "public",
|
||||||
pattern: "/_headers",
|
default: false,
|
||||||
entrypoint: "./src/pages/_headers.ts",
|
}),
|
||||||
})
|
},
|
||||||
}
|
},
|
||||||
}
|
integrations: [
|
||||||
}
|
solidJs(),
|
||||||
|
mdx(),
|
||||||
|
icon(),
|
||||||
|
{
|
||||||
|
name: "inject-cloudflare-headers",
|
||||||
|
hooks: {
|
||||||
|
"astro:config:setup": ({ injectRoute }) => {
|
||||||
|
injectRoute({
|
||||||
|
pattern: "/_headers",
|
||||||
|
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"),
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
}
|
},
|
||||||
});
|
});
|
||||||
|
|
|
@ -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"
|
||||||
|
|
|
@ -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")
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue