Ghost/ghost/admin/app/adapters/post.js
Chris Raible 9ea4fbd7a7
Added feature to convert and open mobiledoc posts in the lexical editor (#17453)
refs TryGhost/Product#3638

- Added `convert_to_lexical` flag to the posts/pages edit endpoint
- Added 'convertToLexical' feature flag so we can enable/disable this
feature independently from the main lexical beta flag
- Modified admin posts/pages list to point to the lexical editor for
_all_ posts, regardless of mobiledoc vs lexical (if the flag is on)
- Added call to edit endpoint with `convert_to_lexical` in the lexical
editor admin route if the page/post is currently in mobiledoc and the
flag is enabled
2023-08-08 15:44:54 -07:00

60 lines
2.1 KiB
JavaScript

import ApplicationAdapter from 'ghost-admin/adapters/application';
export default class Post extends ApplicationAdapter {
buildIncludeURL(store, modelName, id, snapshot, requestType, query) {
const url = this.buildURL(modelName, id, snapshot, requestType, query);
const parsedUrl = new URL(url);
if (snapshot?.adapterOptions?.newsletter) {
const newsletter = snapshot.adapterOptions.newsletter;
parsedUrl.searchParams.append('newsletter', newsletter);
let emailSegment = snapshot?.adapterOptions?.emailSegment;
if (emailSegment) {
if (emailSegment === 'status:free,status:-free') {
emailSegment = 'all';
}
parsedUrl.searchParams.append('email_segment', emailSegment);
}
}
if (snapshot?.adapterOptions?.saveRevision) {
const saveRevision = snapshot.adapterOptions.saveRevision;
parsedUrl.searchParams.append('save_revision', saveRevision);
}
if (snapshot?.adapterOptions?.convertToLexical) {
const convertToLexical = snapshot.adapterOptions.convertToLexical;
parsedUrl.searchParams.append('convert_to_lexical', convertToLexical);
}
return parsedUrl.toString();
}
buildURL() {
const url = super.buildURL(...arguments);
try {
const parsedUrl = new URL(url);
if (!parsedUrl.searchParams.get('formats')) {
parsedUrl.searchParams.set('formats', 'mobiledoc,lexical');
return parsedUrl.href;
}
} catch (e) {
// noop, just use the original url
console.error('Couldn\'t parse URL', e); // eslint-disable-line
}
return url;
}
// posts and pages now include all relations by default so we don't want
// EmbeddedRelationAdapter.buildQuery adding an `?include=` param that
// overrides the defaults with a more restrictive list
buildQuery(store, modelName, options) {
return options;
}
}