Fork of Chiri for Astro for my blog
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

feat(linkCard): add config option to bypass adapter setup

the3ash d7210203 5a18f023

+82 -16
+2 -2
README.md
··· 39 39 40 40 4. Use `pnpm new <title>` to create new posts, or add your posts to `src/content/posts`. 41 41 42 - 5. Deploy to Netlify, Vercel, or other platforms, refer to [Astro Deployment Guides](https://docs.astro.build/en/guides/deploy/) for more details. 42 + 5. You need to set adapter as follows before deploying to Netlify, Vercel, or other platforms, but you can set `linkCard` to `false` in `src/config.ts` to skip this step: 43 43 - **Netlify**: `pnpm add @astrojs/netlify` and add `adapter: netlify()` in `astro.config.ts`. 44 44 - **Vercel**: `pnpm add @astrojs/vercel` and add `adapter: vercel()` in `astro.config.ts`. 45 45 - **Static (e.g. GitHub Pages)**: `pnpm add @astrojs/static` and add `adapter: static()` in `astro.config.ts`. 46 - 46 + - Refer to [Astro Deployment Guides](https://docs.astro.build/en/guides/deploy/) for more details. 47 47 48 48 &emsp;[![Deploy to Netlify](https://www.netlify.com/img/deploy/button.svg)](https://app.netlify.com/start) [![Deploy to Vercel](https://vercel.com/button)](https://vercel.com/new) 49 49
+2 -1
package.json
··· 5 5 "license": "MIT", 6 6 "scripts": { 7 7 "dev": "astro dev", 8 - "build": "astro build", 8 + "prebuild": "pnpm exec tsx scripts/toggle-proxy.ts", 9 + "build": "pnpm run prebuild && astro build", 9 10 "preview": "astro preview", 10 11 "astro": "astro", 11 12 "lint": "eslint .",
+66
scripts/toggle-proxy.ts
··· 1 + // toggle-proxy.ts 2 + import fs from 'fs' 3 + import path from 'path' 4 + import { fileURLToPath } from 'url' 5 + 6 + // Compatible with ES module __dirname 7 + const __filename = fileURLToPath(import.meta.url) 8 + const __dirname = path.dirname(__filename) 9 + 10 + const configPath = path.resolve(__dirname, '../src/config.ts') 11 + const proxyPath = path.resolve(__dirname, '../src/pages/api/proxy.ts') 12 + const backupPath = path.resolve(__dirname, '../src/pages/api/proxy.ts.bak') 13 + const astroConfigPath = path.resolve(__dirname, '../astro.config.ts') 14 + 15 + // Read config.ts content 16 + const configContent = fs.readFileSync(configPath, 'utf-8') 17 + 18 + // Use regex to extract linkCard config (assuming the format does not change) 19 + const match = configContent.match(/linkCard:\s*(true|false)/) 20 + if (!match) { 21 + console.error('linkCard config not found') 22 + process.exit(1) 23 + } 24 + const linkCardEnabled: boolean = match[1] === 'true' 25 + 26 + // Helper to comment/uncomment adapter lines in astro.config.ts 27 + function toggleAstroAdapter(comment: boolean) { 28 + const astroConfig = fs.readFileSync(astroConfigPath, 'utf-8').split('\n') 29 + // 16: import netlify..., 19: adapter: netlify() (0-based) 30 + const importIdx = 16 31 + const adapterIdx = 19 32 + if (comment) { 33 + if (!astroConfig[importIdx].trim().startsWith('//')) { 34 + astroConfig[importIdx] = '// ' + astroConfig[importIdx] 35 + } 36 + if (!astroConfig[adapterIdx].trim().startsWith('//')) { 37 + astroConfig[adapterIdx] = '// ' + astroConfig[adapterIdx] 38 + } 39 + } else { 40 + if (astroConfig[importIdx].trim().startsWith('//')) { 41 + astroConfig[importIdx] = astroConfig[importIdx].replace(/^\/\/\s?/, '') 42 + } 43 + if (astroConfig[adapterIdx].trim().startsWith('//')) { 44 + astroConfig[adapterIdx] = astroConfig[adapterIdx].replace(/^\/\/\s?/, '') 45 + } 46 + } 47 + fs.writeFileSync(astroConfigPath, astroConfig.join('\n'), 'utf-8') 48 + } 49 + 50 + if (!linkCardEnabled) { 51 + // If linkCard is disabled, rename proxy.ts and comment adapter 52 + if (fs.existsSync(proxyPath)) { 53 + fs.renameSync(proxyPath, backupPath) 54 + console.log('🟡 proxy.ts disabled') 55 + } 56 + toggleAstroAdapter(true) 57 + console.log('🟡 adapter config commented') 58 + } else { 59 + // If linkCard is enabled, restore proxy.ts and uncomment adapter 60 + if (fs.existsSync(backupPath)) { 61 + fs.renameSync(backupPath, proxyPath) 62 + console.log('🔵 proxy.ts enabled') 63 + } 64 + toggleAstroAdapter(false) 65 + console.log('🔵 adapter config uncommented') 66 + }
+3 -2
src/config.ts
··· 30 30 // POST SETTINGS /////////////////////////////////////////////////////////////////////////////////////// 31 31 post: { 32 32 readingTime: false, // Show reading time in posts 33 - toc: true, // Show the table of contents (when there is enough page width) 33 + toc: true, // Show table of contents (when there is enough page width) 34 34 imageViewer: true, // Enable image viewer 35 - copyCode: true // Enable copy button in code blocks 35 + copyCode: true, // Enable copy button in code blocks 36 + linkCard: true // Enable link card 36 37 } 37 38 }
+3 -8
src/content/posts/embedded-content.md
··· 33 33 ``` 34 34 🟡 35 35 36 - If you don’t need Link Card, you can skip adapter setup: 37 - 38 - - Run「pnpm remove @astrojs/netlify」 39 - - Delete the following content: 40 - - src/component/ui/LinkCard.astro 41 - - src/plugins/remark-embedded-media.mjs (Lines 8 - 32) 42 - - src/pages/api/proxy.ts 43 - - astro.config.ts (Lines 17 & 20) 36 + If you don’t need Link Card, 37 + you can set `linkCard` to `false` in `src/config.ts`, 38 + then you don't need to set adapter before building. 44 39 ``` 45 40 46 41 ## Spotify
+4 -2
src/content/posts/theme-guide.md
··· 73 73 post: { 74 74 // Show reading time in posts 75 75 readingTime: false, 76 - // Show the table of contents (when there is enough page width) 76 + // Show table of contents (when there is enough page width) 77 77 toc: true, 78 78 // Enable image viewer 79 79 imageViewer: true, 80 80 // Enable copy button in code blocks 81 - copyCode: true 81 + copyCode: true, 82 + // Enable link card 83 + linkCard: true 82 84 } 83 85 ``` 84 86
+1 -1
src/layouts/PostLayout.astro
··· 61 61 <FootnoteScroll /> 62 62 <CopyCode /> 63 63 <GitHubCard /> 64 - <LinkCard /> 65 64 <XPOST /> 66 65 <ImageOptimizer /> 67 66 {themeConfig.post.imageViewer && <ImageViewer />} 67 + {themeConfig.post.linkCard && <LinkCard />} 68 68 {themeConfig.general.footer && <Footer />} 69 69 </div> 70 70 </BaseLayout>
+1
src/types/config.types.ts
··· 38 38 toc: boolean 39 39 imageViewer: boolean 40 40 copyCode: boolean 41 + linkCard: boolean 41 42 } 42 43 43 44 // Theme configuration type