diff --git a/.gitignore b/.gitignore index b63d586..5f0c2de 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,5 @@ node_modules .eslintcache .env *.log + +public/pagefind/ diff --git a/astro.config.ts b/astro.config.ts index 43026ee..3c03073 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -12,9 +12,11 @@ import rehypeAutolinkHeadings from 'rehype-autolink-headings' import rehypeExternalLinks from 'rehype-external-links' import rehypePrettyCode from 'rehype-pretty-code' import UnoCSS from 'unocss/astro' +import pagefind from 'vite-plugin-pagefind' +import siteConfig from './src/site-config' export default defineConfig({ - site: 'https://vinh.dev', + site: siteConfig.site, trailingSlash: 'never', build: { assets: '_assets', @@ -23,6 +25,17 @@ export default defineConfig({ experimental: { svg: true, }, + vite: { + ssr: { + noExternal: [`${siteConfig.site}/pagefind/pagefind.js`], + }, + plugins: [pagefind()], + build: { + rollupOptions: { + external: [`${siteConfig.site}/pagefind/pagefind.js`], + }, + }, + }, integrations: [ mdx(), sitemap(), diff --git a/bun.lockb b/bun.lockb index 0179be9..7cde6b6 100755 Binary files a/bun.lockb and b/bun.lockb differ diff --git a/package.json b/package.json index cc067cf..4df547b 100644 --- a/package.json +++ b/package.json @@ -7,8 +7,7 @@ "prepare": "simple-git-hooks", "compress": "esno scripts/img-compress-staged.ts", "dev": "astro dev --host", - "build": "astro build", - "postbuild": "pagefind --site dist", + "build": "astro build && pagefind", "preview": "astro preview", "lint": "eslint .", "lint:fix": "eslint --fix", @@ -18,6 +17,7 @@ "@astrojs/mdx": "^4.0.1", "@astrojs/rss": "4.0.9", "@astrojs/sitemap": "3.2.1", + "@astrojs/svelte": "^7.0.1", "@astrojs/vue": "^5.0.1", "@unocss/reset": "^0.65.1", "astro": "^5.0.2", @@ -57,7 +57,8 @@ "reading-time": "^1.5.0", "rehype-pretty-code": "^0.14.0", "simple-git": "^3.27.0", - "simple-git-hooks": "^2.11.1" + "simple-git-hooks": "^2.11.1", + "vite-plugin-pagefind": "^0.2.10" }, "simple-git-hooks": { "pre-commit": "bunx esno scripts/reading-time-hook.ts && bunx lint-staged" diff --git a/pagefind.json b/pagefind.json new file mode 100644 index 0000000..200da05 --- /dev/null +++ b/pagefind.json @@ -0,0 +1,4 @@ +{ + "site": "dist", + "vite_plugin_pagefind": {} +} diff --git a/src/components/Header.astro b/src/components/Header.astro index 080ec58..c0594e4 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -3,6 +3,7 @@ import { getLinkTarget } from '@/utils/link' import siteConfig from '@/site-config' import GlitchingLogo from './GlitchingLogo.vue' import Search from './Search.vue' +import CommandPalette from './SearchCommandPalette.vue' import ThemeToggle from './ThemeToggle.vue' const navLinks = siteConfig.header.navLinks || [] @@ -48,11 +49,12 @@ const socialLinks = structuredClone(siteConfig.socialLinks).filter((link: Record /> ))} - + + diff --git a/src/components/SearchCommandPalette.vue b/src/components/SearchCommandPalette.vue new file mode 100644 index 0000000..779bd3a --- /dev/null +++ b/src/components/SearchCommandPalette.vue @@ -0,0 +1,214 @@ + + + + + diff --git a/src/pages/posts/[...slug].astro b/src/pages/posts/[...slug].astro index 8d717c3..62b4d03 100644 --- a/src/pages/posts/[...slug].astro +++ b/src/pages/posts/[...slug].astro @@ -34,7 +34,7 @@ const blueskyUrl = `https://bsky.app/intent/compose?text=${encodeURIComponent(`R --- -
+

{title}

{date && } diff --git a/src/site-config.ts b/src/site-config.ts index 4d1fcda..82333dd 100644 --- a/src/site-config.ts +++ b/src/site-config.ts @@ -3,6 +3,7 @@ import type { SiteConfig } from '@/types' export const siteConfig: SiteConfig = { author: 'Vinh Pham', title: 'vinh.dev', + site: 'https://vinh.dev', subtitle: 'Thoughts and ideas', description: 'Thoughts and ideas', image: { diff --git a/src/stores/search.ts b/src/stores/search.ts new file mode 100644 index 0000000..8e1375f --- /dev/null +++ b/src/stores/search.ts @@ -0,0 +1,3 @@ +import { ref } from 'vue' + +export const showSearch = ref(false) diff --git a/src/types.ts b/src/types.ts index 15bb585..6be521a 100644 --- a/src/types.ts +++ b/src/types.ts @@ -57,6 +57,7 @@ export interface Footer { export interface SiteConfig { author: string title: string + site: string subtitle: string description: string image: Image diff --git a/svelte.config.js b/svelte.config.js new file mode 100644 index 0000000..d0ce7b1 --- /dev/null +++ b/svelte.config.js @@ -0,0 +1,5 @@ +import { vitePreprocess } from '@astrojs/svelte' + +export default { + preprocess: vitePreprocess(), +} diff --git a/tsconfig.json b/tsconfig.json index 46ac63f..13578bb 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -9,5 +9,5 @@ "strictNullChecks": true }, "include": [".astro/types.d.ts", "**/*"], - "exclude": ["dist"] + "exclude": ["public/pagefind", "dist"] }