0.4.1 • Published 8 months ago

astro-loader v0.4.1

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

astro-loader

npm version npm downloads bundle JSDocs License

A package for loading content into Astro's Content Collection API

Install

pnpm add astro-loader

loaders

Posts

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

import { HashnodeLoader } from 'astro-loader/hashnode'

const posts = defineCollection({
  loader: HashnodeLoader({
    operation: 'posts',
    publicationHost: 'adrianub.dev/hashnode',
    fields: ['slug', 'title', 'publishedAt', 'subtitle', { coverImage: ['url'], content: ['html', 'markdown'] }],
  }),
  schema: z.object({
    slug: z.string(),
    title: z.string(),
    subtitle: z.string().optional(),
    publishedAt: z.string().transform(date => new Date(date)),
    coverImage: z.object({
      url: z.string().url(),
    }),
    content: z.object({
      html: z.string(),
      markdown: z.string(),
    }),
  }),
})

export const collections = { posts }

Series

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

import { HashnodeLoader } from 'astro-loader/hashnode'

const series = defineCollection({
  loader: HashnodeLoader({
    publicationHost: 'adrianub.dev/hashnode',
    operation: 'seriesList',
    fields: [
      'slug',
      'name',
      'createdAt',
      'coverImage',
      {
        description: ['html', 'markdown'],
      },
    ],
    withPosts: {
      fields: ['slug', 'title', 'publishedAt', { coverImage: ['url'] }],
    },
  }),
  schema: z.object({
    slug: z.string(),
    name: z.string(),
    createdAt: z.string().transform(date => new Date(date)),
    coverImage: z.string().url(),
    description: z.object({
      html: z.string(),
      markdown: z.string(),
    }),
    posts: z.array(z.object({
      slug: z.string(),
      title: z.string(),
      publishedAt: z.string().transform(date => new Date(date)),
      coverImage: z.object({
        url: z.string().url(),
      }),
    })),
  }),
})

export const collections = { series }

Pages

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

import { HashnodeLoader } from 'astro-loader/hashnode'

const pages = defineCollection({
  loader: HashnodeLoader({
    operation: 'staticPages',
    publicationHost: 'adrianub.dev/hashnode',
    fields: [
      'slug',
      'title',
      {
        content: ['html', 'markdown'],
        ogMetaData: ['image'],
      },
    ],
  }),
  schema: z.object({
    slug: z.string(),
    title: z.string(),
    content: z.object({
      html: z.string(),
      markdown: z.string(),
    }),
    ogMetaData: z.object({
      image: z.string().url(),
    }),
  }),
})

export const collections = { pages }

Sponsors

License

MIT License © 2024-PRESENT Adrián UB

0.4.1

8 months ago

0.4.0

9 months ago

0.3.0

9 months ago

0.2.0

9 months ago

0.1.0

9 months ago

0.0.0

9 months ago