0.1.5 • Published 5 months ago
polite-stack v0.1.5
Polite Stack
A headless WordPress integration for Astro.
Features
- WordPress REST API integration
- Reusable Astro components
- TypeScript support
- Easy to use with minimal configuration
Installation
npm install polite-stack
Usage
---
// src/pages/index.astro
import Layout from "../layouts/Layout.astro";
import { wordpress } from "polite-stack";
// Access components through the wordpress namespace
const { Posts } = wordpress.components;
// WordPress API URL
const WP_API = "http://your-wordpress-site.com/wp-json";
// Fetch posts
const posts = await wordpress.getPosts(WP_API, { per_page: 6 });
---
<Layout title="WordPress Blog">
<main>
<h1>Latest Posts</h1>
<Posts posts={posts} columns={3} />
</main>
</Layout>
API
WordPress API
getPosts(endpoint, options)
- Fetch posts with optionsgetPost(endpoint, slug)
- Fetch a single post by sluggetPages(endpoint, options)
- Fetch pages with optionsgetPage(endpoint, slug)
- Fetch a single page by sluggetFeaturedImage(post)
- Get the featured image URL from a postgetCategories(post)
- Get categories from a postgetTags(post)
- Get tags from a postformatDate(dateString)
- Format a date string
Components
Post
- Renders a single postPosts
- Renders a grid of postsPage
- Renders a single page
Development
# Install dependencies
npm install
# Run development server
npm run dev
# Build for production
npm run build
# Lint code
npm run lint
# Format code
npm run format
License
MIT