Skip to content

Commit b59edaf

Browse files
committed
update readme
1 parent 6994b21 commit b59edaf

File tree

1 file changed

+32
-66
lines changed

1 file changed

+32
-66
lines changed

README.md

Lines changed: 32 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,31 @@
1-
# payload-plugin-algolia
1+
# payload-plugin-scheduler
22

3-
PayloadCMS plugin that syncs collections with Algolia search
3+
Payload plugin that enables scheduled publishing for draft-enabled collections, inspired by wordpress post scheduler.
44

5-
![ci status](https://github.com/wkentdag/payload-plugin-algolia/actions/workflows/test.yml/badge.svg)
5+
![ci status](https://github.com/wkentdag/payload-plugin-scheduler/actions/workflows/test.yml/badge.svg)
66

77
## Installation
88

99
```sh
10-
npm i payload-plugin-algolia
10+
npm i payload-plugin-scheduler
1111
```
1212

1313
## Usage
1414

15-
At a minimum, the plugin requires Algolia credentials and a list of enabled collections.
16-
1715
```ts
1816
// payload.config.ts
1917

2018
import { buildConfig } from 'payload/config'
21-
import { AlgoliaSearchPlugin } from 'payload-plugin-algolia'
19+
import { ScheduledPostPlugin } from 'payload-plugin-scheduler'
2220
import Pages from './collections/Pages'
2321
import Posts from './collections/Posts'
2422

2523
export default buildConfig({
2624
collections: [Pages, Posts],
2725
plugins: [
28-
AlgoliaSearchPlugin({
29-
algolia: {
30-
appId: process.env.ALGOLIA_APP_ID,
31-
apiKey: process.env.ALGOLIA_ADMIN_API_KEY,
32-
index: process.env.ALGOLIA_INDEX
33-
},
34-
collections: ['pages', 'posts']
26+
ScheduledPostPlugin({
27+
collections: ['pages', 'posts'],
28+
interval: 10,
3529
})
3630
]
3731
// ...more config
@@ -41,69 +35,41 @@ export default buildConfig({
4135

4236
## Options
4337

44-
### `generateSearchAttributes`
38+
### `collections: string[]`
4539

46-
By default, the plugin will pass the entire document through to Algolia, with two appended keys:
40+
An array of collection slugs. All collections must have drafts enabled.
4741

48-
* `objectID`: format `${collection}:${id}` eg `pages:1`
49-
* `collection`: the collection slug
42+
### `interval?: number`
5043

51-
You can modify search attributes by providing a custom `generateSearchAttributes` function:
44+
Specify how frequently to check for scheduled posts (in minutes).
45+
This value will also be passed to the `DatePicker` component. Defaults to 5 mins.
5246

53-
```ts
54-
import { type GenerateSearchAttributes } from 'plugin-payload-algolia'
55-
56-
interface PageRecord {
57-
title: string
58-
text: string
59-
}
60-
61-
interface PostRecord extends PageRecord {
62-
image: string
63-
}
64-
65-
const generateSearchAttributes: GenerateSearchAtributes<
66-
PageRecord | PostRecord
67-
> = async ({ doc, collection, req: { payload } }) => {
68-
switch (collection.slug) {
69-
case 'posts': {
70-
if (doc.featured_image) {
71-
const { url } = await payload.findById({
72-
collection: 'media',
73-
id: doc.featured_image as number
74-
})
75-
76-
return {
77-
...doc,
78-
image: url,
79-
}
80-
}
81-
82-
return doc
83-
}
84-
default:
85-
return doc
86-
}
87-
}
88-
```
8947

90-
### `waitForHook`
48+
### `scheduledPosts?: Partial<CollectionConfig>`
9149

92-
> `Boolean`, default = `false`
50+
Custom configuration for the scheduled posts collection that gets merged with the defaults.
9351

94-
Set to `true` to wait for algolia set / delete operations during the collection hooks.
9552

96-
## Notes
53+
## Approach
54+
55+
In a nutshell, the plugin creates a `publish_date` field that it uses to determine whether a pending draft update needs to be scheduled.
9756

98-
> The current scope of the plugin is quite limited. PRs welcome!
57+
### `publish_date`
9958

100-
### Drafts
101-
Drafts are not indexed. If a document is unpublished, it gets removed from search results. Otherwise, draft updates to a published document have no effect.
59+
Custom Datetime field added to documents in enabled collections.
60+
Includes custom `Field` and `Cell` components that include schedule status in the client-side UI.
10261

103-
### Globals
62+
### `scheduled_posts`
10463

105-
Globals are not supported for indexing.
64+
Collection added by the plugin to store pending schedule updates. Can be customized via `scheduledPosts` option.
65+
66+
### Cron
67+
68+
A configurable timer checks for any posts to be scheduled in the upcoming interval window. For each hit, it creates a separate job that's fired at that document's `publish_date` (via [node-schedule](https://github.com/node-schedule/node-schedule)). The idea here is that you can configure your interval window to avoid super long running tasks that are more prone to flaking.
69+
70+
71+
## Notes
10672

107-
### Algolia search config
73+
Since the plugin uses cron under the hood, it depends on a long-running server and is incompatible with short-lived/serverless environments like ECS, or Vercel if you're using Payload 3.0 beta.
10874

109-
The internal Algolia client accepts [all options](https://github.com/algolia/algoliasearch-client-javascript/blob/master/packages/algoliasearch/src/types/AlgoliaSearchOptions.ts). Beyond that, the rest of the setup for a typical Algolia configuration is outside the scope of the plugin (setting search attributes and facets, etc).
75+
I developed this plugin for a project that hasn't gone live yet. It has good test coverage but not in the wild yet -- there's your disclaimer.

0 commit comments

Comments
 (0)