pawcoding / astro-loader-pocketbase

A content loader for Astro that uses the PocketBase API
https://www.npmjs.com/package/astro-loader-pocketbase
MIT License
16 stars 2 forks source link

chore(loader): add support for custom unique identifier #12

Closed kmishmael closed 1 week ago

kmishmael commented 2 weeks ago

This PR implements a feature request outlined in issue #13, introducing support for a custom unique identifier (slug) to replace the default Pocketbase ID. This allows for enhanced flexibility by enabling the use of other fields as unique identifiers tailored to specific use cases, including usage with the getEntry function.

The proposal introduces a new optional configuration parameter, id, which serves as the unique identifier key for collection entries. If id is not specified, it defaults to entry.id.

Documentation has also been updated to reflect these changes.

Example Usage

import { defineCollection } from 'astro:content'
import { pocketbaseLoader } from "astro-loader-pocketbase";

const remotePostsCollection = defineCollection({
  loader: pocketbaseLoader({
    url: <POCKETBASE_URL>,
    adminEmail: <POCKETBASE_ADMIN_EMAIL>,
    adminPassword: <POCKETBASE_ADMIN_PASSWORD>,
    collectionName: "posts",
    content: "content",
    id: "slug",
  }),
})

closes #13

pawcoding commented 1 week ago

Thank you for your PR, that's a really nice addition to the loader 🚀!

I went over your code and updated it slightly (mostly documentation and some warnings). In addition I

You can find the updated code in

I also published the changes in v0.5.0-custom-id-rc.1, so you can easily try it out for yourself. Just let me know if it works correctly or if it still needs some refinement.

pawcoding commented 1 week ago

Closing this since it's included in #14