54 - garden-astro - tags & search

Add tags

Start by adding type schema in Astro’s config.ts

const secondBrain = defineCollection({
  schema: z.object({
    ...
    tags: z.array(z.string()).optional(),
  }),
})

Then the tags will be available in Astro layout file

// Post.astro
const { title, date, draft, updated, filepath, tags } = Astro.props

All tags page

Tag entries page

Use Pagefind that indexes the whole site after build. There is one problem about the library is it have to be async imported and it’s not available on development, luckily there is a workaround to add a dev endpoint to mock the library on development.

The search result is not ideal since it does not strip some html tags, will deal with it later.


#issue Degit blows up

09:11:04 PM [build] Waiting for the github-fetch integration...
 error   zlib: unexpected end of file
  File:
    /Users/narze/Code/github.com/narze/garden-astro/node_modules/.pnpm/[email protected]/node_modules/degit/dist/index-688c5d50.js:1322:22
  Code:
    1321 |       Buffer.concat = OriginalBufferConcat;
    > 1322 |       this[_onError](new ZlibError(err));
           |                      ^

Solution : Clear degit cache rm -rf ~/.degit ref. (Cannot use tiged since it does not support typescript)

Maybe we should move to Octokit in the near future…