diff --git a/docs/.vuepress/config/sidebar-developer.js b/docs/.vuepress/config/sidebar-developer.js index cfba5f9d1f..574c86fe6a 100644 --- a/docs/.vuepress/config/sidebar-developer.js +++ b/docs/.vuepress/config/sidebar-developer.js @@ -488,19 +488,4 @@ const developer = [ }, ], }, - { - title: '📚 Guides', - collapsable: true, - children: [ - // ['/developer-docs/latest/guides/is-owner', 'Create is owner policy'], - // ['/developer-docs/latest/guides/custom-admin', 'Custom admin'], - // ['/developer-docs/latest/guides/custom-data-response', 'Custom data response'], - // ['/developer-docs/latest/guides/error-catching', 'Error catching'], - // ['/developer-docs/latest/guides/external-data', 'Fetching external data'], - ['/developer-docs/latest/guides/scheduled-publication', 'Scheduled publication'], - // ['/developer-docs/latest/guides/secure-your-app', 'Secure your application'], - // ['/developer-docs/latest/guides/send-email', 'Send email programmatically'], - // ['/developer-docs/latest/guides/client', 'Setup a third party client'], - ], - }, ]; diff --git a/docs/.vuepress/redirects b/docs/.vuepress/redirects index cebb113039..44022ea205 100644 --- a/docs/.vuepress/redirects +++ b/docs/.vuepress/redirects @@ -10,5 +10,5 @@ /developer-docs/latest/guides/unit-testing.html /developer-docs/latest/developer-resources/unit-testing.html /developer-docs/latest/guides/auth-request.html /developer-docs/latest/plugins/users-permissions.html /developer-docs/latest/guides/registering-a-field-in-admin.html /developer-docs/latest/development/custom-fields.html -/developer-docs/latest/guides/slug.html /developer-docs/latest/development/backend-customization/models.html +/developer-docs/latest/guides/scheduled-publication.html /user-docs/latest/content-manager/saving-and-publishing-content.html /developer-docs/latest/guides/jwt-validation.html /developer-docs/latest/plugins/users-permissions.html \ No newline at end of file diff --git a/docs/developer-docs/latest/guides/scheduled-publication.md b/docs/developer-docs/latest/guides/scheduled-publication.md deleted file mode 100644 index 5676d3f2f2..0000000000 --- a/docs/developer-docs/latest/guides/scheduled-publication.md +++ /dev/null @@ -1,82 +0,0 @@ ---- -title: Scheduled Publication - Strapi Developer Docs -description: Learn in this guide how to create an article schedule system. -canonicalUrl: https://docs.strapi.io/developer-docs/latest/guides/scheduled-publication.html ---- - -# Scheduled publication - -!!!include(developer-docs/latest/guides/snippets/guide-not-updated.md)!!! - -This guide will explain how to create an article schedule system. - -## Introduction - -What we want here is to be able to set a publication date for an article, and at this date, switch the `draft` state to `published`. - -## Example - -For this example, we will have to add a `publish_at` attribute to the **Article** Content Type. - -- Click on the Content-type Builder link in the left menu -- Select the **Article** Content Type -- Add another field - - `date` attribute named `publish_at` with `datetime` type - -And add some data with different dates and state to be able to see the publication happen. -Make sure to create some entries with a draft state and a `publish_at` that is before the current date. - -The goal will be to check every minute if there are draft articles that have a `publish_at` lower that the current date. - -## Create a CRON task - -To execute a function every minutes, we will use a CRON task. - -Here is the [full documentation](/developer-docs/latest/setup-deployment-guides/configurations/optional/cronjobs.md) of this feature. If your CRON task requires to run based on a specific timezone then do look into the full documentation. - -**Path —** `./config/functions/cron.js` - -```js -module.exports = { - '*/1 * * * *': () => { - console.log('1 minute later'); - }, -}; -``` - -Make sure the enabled cron config is set to true in `./config/server.js` file. - -::: tip -Please note that Strapi's built in CRON feature will not work if you plan to use `pm2` or node based clustering. You will need to execute these CRON tasks outside of Strapi. -::: - -## Business logic - -Now we can start writing the publishing logic. The code that will fetch all `draft` **Articles** with a `publish_at` that is before the current date. - -Then we will update the `published_at` of all these articles. - -**Path —** `./config/functions/cron.js` - -```js -module.exports = { - '*/1 * * * *': async () => { - // fetch articles to publish - const draftArticleToPublish = await strapi.api.article.services.article.find({ - _publicationState: 'preview', // preview returns both draft and published entries - published_at_null: true, // so we add another condition here to filter entries that have not been published - publish_at_lt: new Date(), - }); - - // update published_at of articles - await Promise.all(draftArticleToPublish.map(article => { - return strapi.api.article.services.article.update( - { id: article.id }, - { published_at: new Date() } - ); - })); - }, -}; -``` - -And tada! diff --git a/docs/user-docs/latest/content-manager/saving-and-publishing-content.md b/docs/user-docs/latest/content-manager/saving-and-publishing-content.md index 50041a724d..a072286219 100644 --- a/docs/user-docs/latest/content-manager/saving-and-publishing-content.md +++ b/docs/user-docs/latest/content-manager/saving-and-publishing-content.md @@ -32,6 +32,10 @@ When a content is not a draft anymore, but has been published, it is indicated o ![Editing published version](../assets/content-manager/editing_published_version.png) +::: tip +To schedule publication, i.e. convert a draft to a published entry at a given date and time, you can follow [this technical guide](https://forum.strapi.io/t/schedule-publications/23184) which requires adding custom code to the Strapi application. +::: + ### Unpublishing content Published contents can be unpublished, switching back to being drafts again. @@ -51,4 +55,4 @@ You can delete entries from the list view of a collection type, by clicking on t ::: caution If the [Internationalization plugin](/user-docs/latest/plugins/strapi-plugins.md#internationalization-plugin) is installed, entries can only be deleted one locale at the time. -::: \ No newline at end of file +:::