0
Fork 0
mirror of https://github.com/TryGhost/Ghost.git synced 2025-01-06 22:40:14 -05:00

Added ?force_rerender=true param to posts edit endpoint

no issue

- there are various situations where we adapt/fix/improve our mobiledoc->html output over time but we didn't have a way of updating old content without manually editing the mobiledoc and saving, or running an expensive migration to re-render all old content
- this adds a `?force_rerender=true` query param to the `PUT .../admin/posts/:id/` endpoint that allows the `html` field to be re-generated without modifying the `mobiledoc` field contents
This commit is contained in:
Kevin Ansfield 2020-06-12 18:05:57 +01:00
parent 5d0d0b397e
commit 008f86fc29
2 changed files with 8 additions and 2 deletions

View file

@ -126,6 +126,7 @@ module.exports = {
'id', 'id',
'source', 'source',
'send_email_when_published', 'send_email_when_published',
'force_rerender',
// NOTE: only for internal context // NOTE: only for internal context
'forUpdate', 'forUpdate',
'transacting' 'transacting'

View file

@ -405,8 +405,13 @@ Post = ghostBookshelf.Model.extend({
}); });
// CASE: mobiledoc has changed, generate html // CASE: mobiledoc has changed, generate html
// CASE: ?force_rerender=true passed via Admin API
// CASE: html is null, but mobiledoc exists (only important for migrations & importing) // CASE: html is null, but mobiledoc exists (only important for migrations & importing)
if (this.hasChanged('mobiledoc') || (!this.get('html') && (options.migrating || options.importing))) { if (
this.hasChanged('mobiledoc')
|| options.force_rerender
|| (!this.get('html') && (options.migrating || options.importing))
) {
try { try {
this.set('html', mobiledocLib.mobiledocHtmlRenderer.render(JSON.parse(this.get('mobiledoc')))); this.set('html', mobiledocLib.mobiledocHtmlRenderer.render(JSON.parse(this.get('mobiledoc'))));
} catch (err) { } catch (err) {
@ -781,7 +786,7 @@ Post = ghostBookshelf.Model.extend({
findPage: ['status'], findPage: ['status'],
findAll: ['columns', 'filter'], findAll: ['columns', 'filter'],
destroy: ['destroyAll', 'destroyBy'], destroy: ['destroyAll', 'destroyBy'],
edit: ['filter', 'send_email_when_published'] edit: ['filter', 'send_email_when_published', 'force_rerender']
}; };
// The post model additionally supports having a formats option // The post model additionally supports having a formats option