1.0.7 • Published 5 months ago

@sensinum/astro-strapi-loader v1.0.7

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

Table of Contents

📋 Table of Contents

📋 Requirements

  • Astro ^5.0.0
  • Strapi ^5.0.0

📦 Installation

npm install @sensinum/astro-strapi-loader
# or
yarn add @sensinum/astro-strapi-loader

🚀 Features

  • Easy integration with Astro and Strapi
  • Automatic data loading from Strapi API
  • Query, filtering and population capabilities - Strapi 5 Documentation
  • Authorization token support
  • Astro collections system integration
  • TypeScript typing

🖥️ Usage

  1. Add the integration to your src/content.config.ts:
import { generateCollections } from '@sensinum/astro-strapi-loader';

let strapiCollections: any = {};

try {
  strapiCollections = await generateCollections({
    url: import.meta.env.STRAPI_URL,
    token: import.meta.env.STRAPI_TOKEN,
  }, [{ // leave empty [] to fetch all the collections based on default Strapi settings
    name: "my-collection",
    query: {
      populate: {
        // ...
      },
    },
  }, 'yet-another-collection']);
} catch (error) {
  console.error(error);
}

export const collections = {
    ...strapiCollections,
};
  1. Use in your Astro component:
---
import { getCollection } from 'astro:content';
import { fetchContent } from '@sensinum/astro-strapi-loader';

// Basic usage with Astro Collections
const myCollection = await getCollection('my-collection');

// Basic usage with direct Strapi Content API fetch
const myCollection = await fetchContent({
  url: import.meta.env.STRAPI_URL,
  token: import.meta.env.STRAPI_TOKEN,
  contentType: 'my-collection',
  queryParams: {
    populate: { 
      // ...
    },
    filters: {
      // ...
    },
    sort: ['publishedAt:desc'],
  },
});
---

<div>
  { myCollection.map(item => (
    <article>
      <h2>{item.title}</h2>
      <p>{item.description}</p>
    </article>
  )) }
</div>

⚙️ Configuration

Integration Options

OptionTypeRequiredDescription
urlstringYesStrapi API URL
tokenstringNoStrapi API access token

⚠️ Note: The token must have read access to both the Content API and the Content-Type Builder API (ONLY to the "Get Content Types" endpoint).

Query Options

OptionTypeDescriptionDocumentation
filtersobjectStrapi Query Builder filtersopen
populateobject / string[]Populating & selecting relationsopen
fieldsstring[]Selecting fieldsopen
sortstring[]Result sortingopen
paginationobjectResult paginationopen

🔧 Development

  1. Clone the repository
  2. Install dependencies:
yarn
  1. Run development mode:
yarn dev
  1. Check types:
yarn check

🤝 Contributing

We welcome contributions to this project! Here's how you can help:

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

Please make sure to:

  • Follow the existing code style
  • Write tests for new features
  • Update documentation as needed
  • Keep your PR focused and concise

📄 License

Copyright © Sensinum & VirtusLab

This project is licensed under the MIT License - see the LICENSE.md file for details.

1.0.7

5 months ago

1.0.6

5 months ago

1.0.5

5 months ago

1.0.4

5 months ago

1.0.3

5 months ago

1.0.2

5 months ago

1.0.1

5 months ago

1.0.0

5 months ago