feat(ghost): Implement Tag, Author and Page models; add advanced filtering, search, bulk operations, image upload, related-posts, update tests and bump dependencies
This commit is contained in:
196
readme.md
196
readme.md
@@ -172,6 +172,202 @@ filteredPosts.forEach(post => {
|
||||
});
|
||||
```
|
||||
|
||||
#### Fetching Tags
|
||||
|
||||
You can fetch all tags from your Ghost site using the `getTags` method.
|
||||
|
||||
```typescript
|
||||
const tags = await ghostInstance.getTags();
|
||||
|
||||
tags.forEach(tag => {
|
||||
console.log(`${tag.name} (${tag.slug})`);
|
||||
});
|
||||
```
|
||||
|
||||
#### Fetching Tags with Minimatch Filtering
|
||||
|
||||
The `getTags` method supports filtering tags using minimatch patterns on tag slugs.
|
||||
|
||||
```typescript
|
||||
// Fetch all tags starting with 'tech-'
|
||||
const techTags = await ghostInstance.getTags({ filter: 'tech-*' });
|
||||
|
||||
// Fetch all tags containing 'blog'
|
||||
const blogTags = await ghostInstance.getTags({ filter: '*blog*' });
|
||||
|
||||
// Fetch with limit
|
||||
const limitedTags = await ghostInstance.getTags({ limit: 10, filter: 'a*' });
|
||||
|
||||
limitedTags.forEach(tag => {
|
||||
console.log(tag.name);
|
||||
});
|
||||
```
|
||||
|
||||
#### Working with Tag Class
|
||||
|
||||
Fetch individual tags and manage them with the `Tag` class.
|
||||
|
||||
```typescript
|
||||
// Get tag by slug
|
||||
const tag = await ghostInstance.getTagBySlug('tech');
|
||||
console.log(tag.getName());
|
||||
console.log(tag.getDescription());
|
||||
|
||||
// Create a new tag
|
||||
const newTag = await ghostInstance.createTag({
|
||||
name: 'JavaScript',
|
||||
slug: 'javascript',
|
||||
description: 'Posts about JavaScript'
|
||||
});
|
||||
|
||||
// Update a tag
|
||||
await newTag.update({
|
||||
description: 'All things JavaScript'
|
||||
});
|
||||
|
||||
// Delete a tag
|
||||
await newTag.delete();
|
||||
```
|
||||
|
||||
#### Fetching Authors
|
||||
|
||||
Manage and filter authors with minimatch patterns.
|
||||
|
||||
```typescript
|
||||
// Get all authors
|
||||
const authors = await ghostInstance.getAuthors();
|
||||
authors.forEach(author => {
|
||||
console.log(`${author.getName()} (${author.getSlug()})`);
|
||||
});
|
||||
|
||||
// Filter authors with minimatch
|
||||
const filteredAuthors = await ghostInstance.getAuthors({ filter: 'j*' });
|
||||
|
||||
// Get author by slug
|
||||
const author = await ghostInstance.getAuthorBySlug('john-doe');
|
||||
console.log(author.getBio());
|
||||
|
||||
// Update author
|
||||
await author.update({
|
||||
bio: 'Updated bio information'
|
||||
});
|
||||
```
|
||||
|
||||
#### Working with Pages
|
||||
|
||||
Ghost pages are similar to posts but for static content.
|
||||
|
||||
```typescript
|
||||
// Get all pages
|
||||
const pages = await ghostInstance.getPages();
|
||||
pages.forEach(page => {
|
||||
console.log(page.getTitle());
|
||||
});
|
||||
|
||||
// Filter pages with minimatch
|
||||
const filteredPages = await ghostInstance.getPages({ filter: 'about*' });
|
||||
|
||||
// Get page by slug
|
||||
const page = await ghostInstance.getPageBySlug('about');
|
||||
console.log(page.getHtml());
|
||||
|
||||
// Create a new page
|
||||
const newPage = await ghostInstance.createPage({
|
||||
title: 'Contact Us',
|
||||
html: '<p>Contact information...</p>'
|
||||
});
|
||||
|
||||
// Update a page
|
||||
await newPage.update({
|
||||
html: '<p>Updated contact information...</p>'
|
||||
});
|
||||
|
||||
// Delete a page
|
||||
await newPage.delete();
|
||||
```
|
||||
|
||||
#### Enhanced Post Filtering
|
||||
|
||||
The `getPosts` method now supports multiple filtering options.
|
||||
|
||||
```typescript
|
||||
// Filter by tag
|
||||
const techPosts = await ghostInstance.getPosts({ tag: 'tech', limit: 10 });
|
||||
|
||||
// Filter by author
|
||||
const authorPosts = await ghostInstance.getPosts({ author: 'john-doe' });
|
||||
|
||||
// Get only featured posts
|
||||
const featuredPosts = await ghostInstance.getPosts({ featured: true });
|
||||
|
||||
// Combine multiple filters
|
||||
const filteredPosts = await ghostInstance.getPosts({
|
||||
tag: 'javascript',
|
||||
featured: true,
|
||||
limit: 5
|
||||
});
|
||||
```
|
||||
|
||||
#### Searching Posts
|
||||
|
||||
Full-text search across post titles and excerpts.
|
||||
|
||||
```typescript
|
||||
// Search for posts containing a keyword
|
||||
const searchResults = await ghostInstance.searchPosts('ghost api', { limit: 10 });
|
||||
|
||||
searchResults.forEach(post => {
|
||||
console.log(post.getTitle());
|
||||
console.log(post.getExcerpt());
|
||||
});
|
||||
```
|
||||
|
||||
#### Finding Related Posts
|
||||
|
||||
Get posts with similar tags.
|
||||
|
||||
```typescript
|
||||
const post = await ghostInstance.getPostById('some-post-id');
|
||||
|
||||
// Get related posts based on tags
|
||||
const relatedPosts = await ghostInstance.getRelatedPosts(post.getId(), 5);
|
||||
|
||||
relatedPosts.forEach(relatedPost => {
|
||||
console.log(`Related: ${relatedPost.getTitle()}`);
|
||||
});
|
||||
```
|
||||
|
||||
#### Image Upload
|
||||
|
||||
Upload images to your Ghost site.
|
||||
|
||||
```typescript
|
||||
// Upload an image file
|
||||
const imageUrl = await ghostInstance.uploadImage('/path/to/image.jpg');
|
||||
|
||||
// Use the uploaded image URL in a post
|
||||
await ghostInstance.createPost({
|
||||
title: 'Post with Image',
|
||||
html: '<p>Content here</p>',
|
||||
feature_image: imageUrl
|
||||
});
|
||||
```
|
||||
|
||||
#### Bulk Operations
|
||||
|
||||
Perform operations on multiple posts at once.
|
||||
|
||||
```typescript
|
||||
// Bulk update posts
|
||||
const postIds = ['id1', 'id2', 'id3'];
|
||||
await ghostInstance.bulkUpdatePosts(postIds, {
|
||||
featured: true
|
||||
});
|
||||
|
||||
// Bulk delete posts
|
||||
await ghostInstance.bulkDeletePosts(['id4', 'id5']);
|
||||
```
|
||||
|
||||
### Example Projects
|
||||
|
||||
To give you a comprehensive understanding, let's look at a couple of example projects.
|
||||
|
Reference in New Issue
Block a user