From f5b7a825c880a9ed008c28bafa7bb9b813948069 Mon Sep 17 00:00:00 2001 From: Yufan Sheng Date: Fri, 29 Nov 2024 13:55:36 +0800 Subject: [PATCH] feat: add the switch for open graph. --- .env.example | 3 +++ README.md | 5 ++++- astro.config.ts | 2 ++ src/pages/images/og/[slug].png.ts | 4 ++-- 4 files changed, 11 insertions(+), 3 deletions(-) diff --git a/.env.example b/.env.example index 3a9346d..13f7ae1 100644 --- a/.env.example +++ b/.env.example @@ -17,3 +17,6 @@ POSTGRES_DATABASE= ARTALK_SCHEME= ARTALK_HOST= ARTALK_PORT= + +# Open Graph Switch +BUILD_OPEN_GRAPH=true diff --git a/README.md b/README.md index f16b1ec..92f5dc7 100644 --- a/README.md +++ b/README.md @@ -46,6 +46,9 @@ npm update # Start local development with a live preview. The weblog is hosted on http://localhost:4321 npm run dev + +# Build the project +BUILD_OPEN_GRAPH=true npm run build ``` ### Postgres Database @@ -193,7 +196,7 @@ to get it worked everywhere. This weblog is deployed on the [zeabur](https://zeabur.com) platform. You can check their documents and get your own weblog to be published without any budget at first. -Or you can host on your own machine. Use [Dockerfile](./Dockerfile) to build an image and run it locally. +Or you can host on your own machine. Use [Dockerfile](./docs/Dockerfile) to build an image and run it locally. The comment system is leverage the [Artalk](https://artalk.js.org), a self-hosted comment system. You should host it on your own machine. diff --git a/astro.config.ts b/astro.config.ts index a125452..434d125 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -35,6 +35,8 @@ export default defineConfig({ ARTALK_SCHEME: envField.string({ context: 'server', access: 'secret' }), ARTALK_HOST: envField.string({ context: 'server', access: 'secret' }), ARTALK_PORT: envField.number({ context: 'server', access: 'secret' }), + // Build the Open Graph + BUILD_OPEN_GRAPH: envField.boolean({ context: 'server', access: 'public', default: true }), }, validateSecrets: true, }, diff --git a/src/pages/images/og/[slug].png.ts b/src/pages/images/og/[slug].png.ts index 67ae3dc..8dfc2bb 100644 --- a/src/pages/images/og/[slug].png.ts +++ b/src/pages/images/og/[slug].png.ts @@ -2,13 +2,13 @@ import { defaultOpenGraph, drawOpenGraph } from '@/helpers/og'; import { getPage, getPost, pages, posts } from '@/helpers/schema'; import options from '@/options'; import type { APIRoute } from 'astro'; - const fallback = async () => new Response(await defaultOpenGraph(), { headers: { 'Content-Type': 'image/png' }, }); -export const prerender = true; +// This endpoint can be controlled by using environment variable. +export const prerender = import.meta.env.BUILD_OPEN_GRAPH; export const GET: APIRoute = async ({ params }) => { const slug = params.slug;