mirror of
https://github.com/TryGhost/Ghost.git
synced 2024-12-19 08:31:43 +03:00
9ea4fbd7a7
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
60 lines
2.1 KiB
JavaScript
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;
|
|
}
|
|
}
|