#Lock a content item from updating

3 messages · Page 1 of 1 (latest)

rigid igloo
#

@storm halo Is it possible to "lock" a content collection item from ever being updated again?

storm haloBOT
#

Hi @rigid igloo. I'm kapa.ai, your friendly support bot. I will try to answer your question by searching through the knowledge base. :wave:

#

Based on the provided knowledge sources, there isn't specific information about "locking" a content collection item from being updated in Astro. However, I can provide some relevant information about content collections and filtering that might be helpful.

Astro's content collections API allows you to filter collection queries based on various criteria. While there's no direct "locking" mechanism mentioned, you could potentially use a custom property in your content schema to achieve a similar effect.

For example, you could add a locked property to your content schema:

import { defineCollection, z } from 'astro:content';

const myCollection = defineCollection({
  schema: z.object({
    title: z.string(),
    locked: z.boolean().optional(),
    // other properties...
  })
});

Then, when querying your collection, you could filter out items marked as locked:

import { getCollection } from 'astro:content';

const nonLockedEntries = await getCollection('myCollection', ({ data }) => {
  return data.locked !== true;
});

This approach doesn't prevent the content from being updated in the source files, but it allows you to exclude "locked" items from being used in your site builds.

For more information on filtering collection queries, you can refer to the Astro documentation on Filtering collection queries.

Remember that this is a workaround and not a built-in feature of Astro. If you need more robust content locking mechanisms, you might need to explore additional tools or content management systems that integrate with Astro.

Note: you can ask me a follow up question by @ mentioning me again :speech_balloon: