Git Product home page Git Product logo

astro-jsonc's Introduction

@angius/astro-jsonc

This is a very simple Astro Integration to allow you to use JSON with comments files as data collections.

Quick Installation

# global
astro add @angius/astro-jsonc
# or npm
npx astro add @angius/astro-jsonc
# or yarn
yarn dlx astro add @angius/astro-jsonc
# or pnpm
pnpm dlx astro add @angius/astro-jsonc
# or bun
bunx astro add @angius/astro-jsonc

Manual Installation

First, install the @angius/astro-jsonc package using your package manager.

# or npm
npm install @angius/astro-jsonc
# or yarn
yarn add @angius/astro-jsonc
# or pnpm
pnpm add @angius/astro-jsonc
# or bun
bun i @angius/astro-jsonc

Next, add the integration to your astro.config.* file. There is currently no set of configuration options.

import { defineConfig } from "astro/config";
import jsonc from "@angius/astro-jsonc";

export default defineConfig({
  // ...
  integrations: [jsonc()],
});

Usage

JSON with comment files can only be used within content collections of the data type. Add entries to any content collection using the .jsonc extension:

src/content/my-stuff/
  data-1.jsonc
  data-2.jsonc

Define a collection and its schema in your content/config.ts file.

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

const jsoncCollection = defineCollection({
  // MUST BE 'data'. 'content' will not work.
  type: "data",
  // Schema must match what is in your TOML files.
  schema: z.object({
    title: z.string(),
    tags: z.array(z.string()),
    image: z.string().optional(),
  }),
});

export const collections = {
  // ...
  'my-stuff': jsoncCollection,
};
---
import { getEntryBySlug } from 'astro:content';

const entry = await getEntryBySlug('my-stuff', 'data-1');
---

<!--Access frontmatter properties with `data`-->
<h1>{entry.data.title}</h1>

astro-jsonc's People

Contributors

atulin avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.